Table of Contents

Class GeometryHelpers

Namespace
SharpConsoleUI.Helpers
Assembly
SharpConsoleUI.dll

Provides static helper methods for Rectangle geometry operations. Extracted from ConsoleWindowSystem as part of Phase 3.1 refactoring. Consolidates duplicate geometry logic from multiple classes.

public static class GeometryHelpers
Inheritance
GeometryHelpers
Inherited Members

Methods

CalculateExposedRegions(Rectangle, Rectangle)

Calculates regions that were covered by oldBounds but are not covered by newBounds.

public static List<Rectangle> CalculateExposedRegions(Rectangle oldBounds, Rectangle newBounds)

Parameters

oldBounds Rectangle

The old rectangle bounds.

newBounds Rectangle

The new rectangle bounds.

Returns

List<Rectangle>

A list of rectangles representing the exposed areas.

CalculateUncoveredRegions(Rectangle, List<Window>)

Calculates which parts of a region are not covered by a list of windows.

public static List<Rectangle> CalculateUncoveredRegions(Rectangle region, List<Window> coveringWindows)

Parameters

region Rectangle

The region to check.

coveringWindows List<Window>

The windows that may cover the region.

Returns

List<Rectangle>

A list of rectangles representing the uncovered areas.

DoesRectangleIntersect(Rectangle, Rectangle)

Checks if two rectangles intersect.

public static bool DoesRectangleIntersect(Rectangle rect1, Rectangle rect2)

Parameters

rect1 Rectangle

The first rectangle.

rect2 Rectangle

The second rectangle.

Returns

bool

True if the rectangles intersect; false otherwise.

DoesRectangleOverlapWindow(Rectangle, Window)

Checks if a rectangle overlaps with a window's bounds.

public static bool DoesRectangleOverlapWindow(Rectangle rect, Window window)

Parameters

rect Rectangle

The rectangle to check.

window Window

The window to check against.

Returns

bool

True if the rectangle overlaps the window; false otherwise.

GetRectangleIntersection(Rectangle, Rectangle)

Calculates the intersection of two rectangles.

public static Rectangle GetRectangleIntersection(Rectangle rect1, Rectangle rect2)

Parameters

rect1 Rectangle

The first rectangle.

rect2 Rectangle

The second rectangle.

Returns

Rectangle

The intersection rectangle, or Rectangle.Empty if no intersection.

OptimizeExposedRegions(List<Rectangle>)

Optimizes exposed regions by removing empty rectangles. Could be enhanced to merge adjacent rectangles.

public static List<Rectangle> OptimizeExposedRegions(List<Rectangle> regions)

Parameters

regions List<Rectangle>

The regions to optimize.

Returns

List<Rectangle>

The optimized list of regions.

SubtractRectangleFromRegions(List<Rectangle>, Rectangle)

Subtracts a rectangle from a list of regions. Returns the parts of the regions that are not covered by the subtracted rectangle.

public static List<Rectangle> SubtractRectangleFromRegions(List<Rectangle> regions, Rectangle subtract)

Parameters

regions List<Rectangle>

The list of regions to subtract from.

subtract Rectangle

The rectangle to subtract.

Returns

List<Rectangle>

A list of rectangles representing the uncovered areas.

TranslateToAbsolute(Window, Point, int)

Translates a window-relative point to absolute screen coordinates.

public static (int absoluteLeft, int absoluteTop) TranslateToAbsolute(Window window, Point point, int desktopTopOffset)

Parameters

window Window

The window containing the point.

point Point

The point in window-relative coordinates.

desktopTopOffset int

The Y offset of the desktop (from status bars).

Returns

(int absoluteLeft, int absoluteTop)

A tuple containing the absolute screen coordinates (absoluteLeft, absoluteTop).

TranslateToRelative(Window, Point?, int)

Translates an absolute screen point to window-relative coordinates.

public static Point TranslateToRelative(Window window, Point? point, int desktopTopOffset)

Parameters

window Window

The window to translate coordinates relative to.

point Point?

The point in absolute screen coordinates, or null.

desktopTopOffset int

The Y offset of the desktop (from status bars).

Returns

Point

The point in window-relative coordinates. Returns (0,0) if point is null.