Class BorderGeometryUtils
Geometric utility functions for border processing Extracted from BorderCurveExtractor for reusability
Contains:
- Line segment intersection detection
- Path self-intersection checking
- Convex hull computation (Graham scan)
- Distance calculations
- Angle calculations
public static class BorderGeometryUtils
- Inheritance
-
objectBorderGeometryUtils
Methods
CalculateAngle(Vector2, Vector2, Vector2)
Calculate angle in degrees at point B formed by line A-B-C Returns 0° for straight line, 180° for complete reversal
public static float CalculateAngle(Vector2 pointA, Vector2 pointB, Vector2 pointC)
Parameters
Returns
- float
ComputeConvexHull(List<Vector2>)
Compute convex hull of points using Graham scan algorithm Returns hull vertices in counter-clockwise order
public static List<Vector2> ComputeConvexHull(List<Vector2> points)
Parameters
pointsList<Vector2>
Returns
- List<Vector2>
DistancePointToSegment(Vector2, Vector2, Vector2)
Compute distance from point to line segment
public static float DistancePointToSegment(Vector2 point, Vector2 segStart, Vector2 segEnd)
Parameters
Returns
- float
FilterToConvexHullPerimeter(List<Vector2>)
Filter border pixels to convex hull perimeter, removing interior pixels This prevents U-turns caused by peninsula indents creating interior loops
public static List<Vector2> FilterToConvexHullPerimeter(List<Vector2> pixels)
Parameters
pixelsList<Vector2>
Returns
- List<Vector2>
IsPointOnOrNearPolyline(Vector2, List<Vector2>, float)
Check if point is on or near a polyline (within tolerance distance)
public static bool IsPointOnOrNearPolyline(Vector2 point, List<Vector2> polyline, float tolerance)
Parameters
Returns
- bool
LineSegmentsIntersect(Vector2, Vector2, Vector2, Vector2)
Check if two line segments intersect (not just touch at endpoints) Uses cross product method for robust intersection detection
public static bool LineSegmentsIntersect(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4)
Parameters
Returns
- bool
PathSelfIntersects(List<Vector2>)
Check if path self-intersects (detects U-turns)
public static bool PathSelfIntersects(List<Vector2> path)
Parameters
pathList<Vector2>
Returns
- bool