Polyline2D Type
A class holding a list of 2D points representing a mutable 2D Polyline. If the last point is the same as the first point, the Polyline2D is considered closed. The Default constructor uses the provided ResizeArray of points directly, so changes to the list will be reflected in the Polyline2D.
Constructors
| Constructor |
Description
|
|
Create a new empty Polyline2D with predefined capacity for the internal list of points.
|
|
Create a new empty Polyline2D
|
|
|
Instance members
| Instance member |
Description
|
Full Usage:
this.Area
Returns: float
|
The area of the Polyline2D. Fails if Polyline is not exactly closed. For self intersecting Polylines the result is invalid.
|
Full Usage:
this.AsFSharpCode
Returns: string
|
Format a 2D polyline into an F# code string that can be used to recreate the point.
|
Full Usage:
this.AsString
Returns: string
|
Format Polyline2D into string including its length.
|
|
Gets bounding rectangle of the Polyline2D
|
|
Returns the average center of all points of the Polyline2D.
|
|
Creates a copy of the Polyline2D. Same as polyline.Duplicate()
|
Full Usage:
this.CloseInPlace
Parameters:
float
|
Close the Polyline2D if it is not already closed. If the ends are closer than the tolerance. The last point is set to equal the first point. Else the start point is added to the end of the Polyline2D.
|
|
Returns the parameter on the Polyline2D that is the closest point to the given point. The integer part of the parameter is the index of the segment that the point is on. The fractional part of the parameter is the parameter form 0.0 to 1.0 on the segment. The domain Polyline2D starts at 0.0 and ends at points.Count - 1.0 .
|
|
|
|
Returns the index into the Polylines point list of the vertex that is closest to the given point.
|
Full Usage:
this.Contains
Parameters:
Pt
-
The point to test.
Returns: bool
TRUE if the point is inside, FALSE otherwise.
|
Tests if a point is inside the closed Polyline2D using the ray casting algorithm. The first and last point of the Polyline2D need to be identical for correct results. Self-intersecting polygons give "alternating" inside/outside regions Uses ray casting: runs an infinite horizontal ray (increasing x, fixed y) from the test point and counts edge crossings. Each crossing toggles inside/outside state (Jordan curve theorem). Always returns FALSE if the Polyline2D has less than 3 points. Boundary cases: Points exactly on edges or vertices have implementation-specific behavior. Horizontal edges are handled by the strict inequality convention (pi.Y > y) != (pj.Y > y). Points on left/bottom edges tend to be considered inside, right/top edges outside. The result may differ from checking the pl.WindingNumber 0 for boundary points.
|
|
Returns the distance of the test point to the closest point on the Polyline2D.
|
|
Creates a copy of the Polyline2D Same as polyline.Clone()
|
Full Usage:
this.End
|
Gets or sets last or end point of the Polyline2D This is the point at index Points.Count - 1. Same as Polyline2D.LastPoint |
|
Returns the point at a given parameter on the Polyline2D. The integer part of the parameter is the index of the segment that the point is on. The fractional part of the parameter is the parameter form 0.0 to 1.0 on the segment. The domain Polyline2D starts at 0.0 and ends at points.Count - 1.0 . If the parameter is within 1e-6 of an integer value, the integer value is used as parameter.
|
|
Finds a point inside a closed Polyline2D that is the farthest away from the edges of the Polyline2D. Uses the Polylabel algorithm from Mapbox. It is a highly optimized algorithm specifically designed to find the pole of inaccessibility for polygons. The point within the polygon that is farthest from the edges, often used for optimal label placement. Adaptive Precision: Can trade accuracy for speed based on your needs. Returns the best point and its distance to the polygon edge. Supplying an open polyline is allowed, but the computed "inside" still assumes the points describe a closed boundary (first and last vertices should match).
|
Full Usage:
this.FirstPoint
|
Gets or sets the first point of the Polyline2D. This is the point at index 0. Same as Polyline2D.Start |
|
Gets the first segment of the Polyline2D.
|
|
|
Full Usage:
this.IsAlmostClosed
Parameters:
float
Returns: bool
|
Tests if Polyline2D is closed within given tolerance. Returns False if the Polyline2D has less than 3 points.
|
Full Usage:
this.IsClockwise
Returns: bool
|
Test if Polyline2D is Clockwise. The Polyline2D does not need to be actually closed. The signed area of the Polyline2D is calculated. If it is negative the Polyline2D is Clockwise.
|
Full Usage:
this.IsClosed
Returns: bool
|
Tests if Polyline2D start and end points are exactly the same. Returns False if the Polyline2D has less than 3 points.
|
Full Usage:
this.IsCounterClockwise
Returns: bool
|
Test if Polyline2D is CounterClockwise. The Polyline2D does not need to be actually closed. The signed area of the Polyline2D is calculated. If it is positive the Polyline2D is Counter Clockwise.
|
Full Usage:
this.LastPoint
|
Gets or sets the last point of the Polyline2D. This is the point at index Points.Count - 1. Same as Polyline2D.End |
Full Usage:
this.LastPointIndex
Returns: int
|
Gets the index of the last point in the Polyline2D. points.Count - 1
|
|
Gets the segment at index i of the Polyline2D.
|
Full Usage:
this.LastSegmentIndex
Returns: int
|
Gets the index of the last segment in the Polyline2D. This is poly.Points.Count - 2
|
Full Usage:
this.Length
Returns: float
|
Gets the length of the Polyline2D Returns 0.0 if there are less than 2 points.
|
Full Usage:
this.PointCount
Returns: int
|
Gets the count of points in the Polyline2D
|
|
Gets the internal list of all Points of the Polyline2D. This is not a copy, so changes to the list will be reflected in the Polyline2D.
|
|
Returns new Polyline2D in reversed Order.
|
Full Usage:
this.ReverseInPlace
|
Reverse order of the Polyline2D in place. |
|
Scales the 2D polyline by a given factor. Scale center is World Origin 0,0
|
|
Scales the 2D polyline by a given factor on a given center point.
|
Full Usage:
this.SecondLastPoint
|
Gets or sets the second last point of the Polyline2D. |
Full Usage:
this.SecondPoint
|
Gets or sets the second point of the Polyline2D. This is the point at index 1. |
Full Usage:
this.SegmentCount
Returns: int
|
Gets the count of segments in the Polyline2D This is poly.Points.Count - 1
|
|
Returns the line vectors of all segments of the Polyline2D as a list of Vc.
|
|
Returns all segments of the Polyline2D as a list of Line2D.
|
|
Sets the vertex at given index to the given point. On a closed Polyline2D, setting the first or last point will set both to the same point.
|
Full Usage:
this.SignedArea
Returns: float
|
The signed area of the Polyline2D . If it is positive the Polyline2D is Counter Clockwise. Polyline does not need to be exactly closed. But then result might be wrong. Or without meaning. For self intersecting Polylines the result is also invalid.
|
|
Calculates the shortest distance from the test point to the polyline with `DistanceTo`, then signs that value by testing containment via the ray-casting based `Contains` helper. Returns a positive distance for points that lie inside the polyline boundary and negative otherwise. For reliable results the polyline should be closed and have identical first and last vertices.
|
Full Usage:
this.Start
|
Gets or sets first point of the Polyline2D This is the point at index 0. Same as Polyline2D.FirstPoint |
Full Usage:
this.WindingNumber
Parameters:
Pt
-
The point to test.
Returns: int
The winding number. Zero means outside, non-zero means inside.
|
Count how many times the polygon winds around the point. If the result is 0 then the point is outside of the Polyline2D. A non-zero value indicates the point is inside. The first and last point of the Polyline2D need to be identical for correct results. Boundary cases: Points exactly on edges or vertices may return inconsistent results due to floating-point precision. For points on horizontal edges, behavior depends on the edge direction. This method Handles self-intersecting polygons more intuitively than the pl.Contains method.
|
Static members
| Static member |
Description
|
|
Returns a new closed Polyline2D. If the first and last point are within 1e-6 of each other, the last point is set equal to the first point. Otherwise one point is added.
|
|
Closes the Polyline2D in place by adding a point. If the first and last point are within 1e-6 of each other, the last point is set equal to the first point instead.
|
Full Usage:
Polyline2D.closestParameter pl pt
Parameters:
Polyline2D
pt : Pt
Returns: float
Modifiers: inline |
Returns the parameter on the Polyline2D that is the closest point to the given point. The integer part of the parameter is the index of the segment that the point is on. The fractional part of the parameter is the parameter form 0.0 to 1.0 on the segment. The domain Polyline2D starts at 0.0 and ends at point count.
|
Full Usage:
Polyline2D.closestPoint pl pt
Parameters:
Polyline2D
pt : Pt
Returns: Pt
Modifiers: inline |
Returns the point on the Polyline2D that is the closest point to the given point.
|
Full Usage:
Polyline2D.closestVertex pl pt
Parameters:
Polyline2D
pt : Pt
Returns: int
Modifiers: inline |
Returns the index into the Polylines point list of the vertex that is closest to the given point.
|
Full Usage:
Polyline2D.contains pt pl
Parameters:
Pt
-
The point to test.
pl : Polyline2D
-
The closed Polyline2D.
Returns: bool
TRUE if the point is inside, FALSE otherwise.
Modifiers: inline |
Tests if a point is inside the closed Polyline2D using the ray casting algorithm. The first and last point of the Polyline2D need to be identical for correct results. Self-intersecting polygons give "alternating" inside/outside regions Uses ray casting: runs an infinite horizontal ray (increasing x, fixed y) from the test point and counts edge crossings. Each crossing toggles inside/outside state (Jordan curve theorem). Always returns FALSE if the Polyline2D has less than 3 points. Boundary cases: Points exactly on edges or vertices have implementation-specific behavior. Horizontal edges are handled by the strict inequality convention (pi.Y > y) != (pj.Y > y). Points on left/bottom edges tend to be considered inside, right/top edges outside. The result may differ from checking the pl.WindingNumber 0 for boundary points.
|
Full Usage:
Polyline2D.create points
Parameters:
Pt seq
Returns: Polyline2D
Modifiers: inline |
Create a new Polyline2D by copying over all points. This will allocate a new ResizeArray and copy all points.
|
Full Usage:
Polyline2D.createDirectlyUnsafe points
Parameters:
ResizeArray<Pt>
Returns: Polyline2D
|
Create a new Polyline2D by using the provided ResizeArray directly. Unsafe because all later changes to the ResizeArray will be reflected in the Polyline2D.
|
Full Usage:
Polyline2D.createEmpty capacity
Parameters:
int
Returns: Polyline2D
Modifiers: inline |
Create a new empty Polyline2D without any points. But predefined capacity.
|
Full Usage:
Polyline2D.distanceTo pl pt
Parameters:
Polyline2D
pt : Pt
Returns: float
Modifiers: inline |
Returns the distance of the test point to the closest point on the Polyline2D.
|
|
|
Full Usage:
Polyline2D.equals tol a b
Parameters:
float
a : Polyline2D
b : Polyline2D
Returns: bool
|
Tests if two Polyline2D have the same number of points and points are equal within a given tolerance.
|
|
Returns the point at a given parameter on the Polyline2D. The integer part of the parameter is the index of the segment that the point is on. The fractional part of the parameter is the parameter form 0.0 to 1.0 on the segment. The domain Polyline2D starts at 0.0 and ends at point count.
|
Full Usage:
Polyline2D.findLablePoint precision pl
Parameters:
float
pl : Polyline2D
Returns: Pt * float
|
Finds a point inside a closed Polyline2D that is the farthest away from the edges of the Polyline2D. Uses the Polylabel algorithm from Mapbox. It is a highly optimized algorithm specifically designed to find the pole of inaccessibility for polygons. The point within the polygon that is farthest from the edges, often used for optimal label placement. Adaptive Precision: Can trade accuracy for speed based on your needs. Returns the best point and its distance to the polygon edge. Supplying an open polyline is allowed, but the computed "inside" still assumes the points describe a closed boundary (first and last vertices should match).
|
|
Gets the length of the Polyline2D. The sum of the lengths of all segments.
|
Full Usage:
Polyline2D.map mapping pl
Parameters:
Pt -> Pt
pl : Polyline2D
Returns: Polyline2D
|
Apply a mapping function to each point in the 2D Polyline2D. Returns new Polyline2D.
|
|
Move a Polyline2D by a vector. (same as Polyline2D.translate)
|
Full Usage:
Polyline2D.moveX distance pl
Parameters:
float
pl : Polyline2D
Returns: Polyline2D
|
Returns a Polyline2D moved by a given distance in X direction.
|
Full Usage:
Polyline2D.moveY distance pl
Parameters:
float
pl : Polyline2D
Returns: Polyline2D
|
Returns a Polyline2D moved by a given distance in Y direction.
|
Full Usage:
Polyline2D.offset (polyLine, constantOffsetDistance, ?loop, ?checkOrientation, ?uTurnBehavior, ?useUTurnBehaviorAbove)
Parameters:
Polyline2D
-
A 2D Polyline, open or closed.
constantOffsetDistance : float
-
The offset distance for all segments of the polyline.
A positive distance offset to the inside of the polyline. A negative distance offset to the outside of the polyline.
?loop : bool
-
bool, Optional (false).
Set to true to explicitly consider last point and first point to be from a closed loop, even if they are not at the same location.
?checkOrientation : bool
-
bool, Optional(true). By default the algorithm always checks if the polyline is clockwise or counter clockwise.
So that positive offset distances are always towards the inside of the polyline.
Set this parameter to false if you are sure that the input polyline is counter clockwise or if you want to skip this check.
?uTurnBehavior : UTurn
-
Optional. Default value: `Offset2D.UTurnBehavior.Fail`.
What to do at a 180 degree U-turn? Fail, Chamfer with two points, Use179 or Skip the point.
?useUTurnBehaviorAbove : MeasureProduct<cosine, MeasureOne>
-
Optional. Default value: `Cosine.``175.0`` `.
The angle between normals after which, instead of a normal miter, the joint is chamfered by adding an extra point.
Returns: Polyline2D
A new 2D polyline.
|
Offsets a Polyline in 2D space by finding the local offset in each corner. Auto detects if given points are from a closed Polyline (first point = last point) and loops them. By default this function raises an Exception on duplicate points, 180 degree U-Turns. But this can be configured with optional parameters.
|
Full Usage:
Polyline2D.offsetVar (polyLine, multipleOffsetDistances, ?loop, ?checkOrientation, ?varDistParallelBehavior, ?uTurnBehavior, ?useVarDistParallelBehaviorBelow, ?useUTurnBehaviorAbove)
Parameters:
Polyline2D
-
A 2D Polyline, open or closed.
multipleOffsetDistances : float[]
-
The parallel offset distances for each segment of the polyline.
A positive distance offsets inwards in corners, a negative offset outwards.
For open and closed polylines this list of distances must have one item less than number of points in the polyline.
Except if the polyline is open and the loop parameter is set to true. Then points and distances list shall have the same count.
?loop : bool
-
bool, Optional (false).
Set to true to explicitly consider last point and first point to be from a closed loop, even if they are not at the same location.
?checkOrientation : bool
-
bool, Optional(true). By default the algorithm always checks if the polyline is clockwise or counter clockwise.
So that positive offset distances are always towards the inside of the polyline.
Set this parameter to false if you are sure that the input polyline is counter clockwise or if you want to skip this check.
?varDistParallelBehavior : VarDistParallel
-
Optional. Default value: `Offset2D.VarDistParallelBehavior.Fail`.
What to do with colinear segments below 'useVarDistParallelBehaviorBelow' degrees when offset distances are different too.
?uTurnBehavior : UTurn
-
Optional. Default value: `Offset2D.UTurnBehavior.Fail`.
What to do at a 180 degree U-turn? Fail, Chamfer with two points, Use179 or Skip the point.
?useVarDistParallelBehaviorBelow : MeasureProduct<cosine, MeasureOne>
-
Optional. Default value: `Cosine.``5.0`` `.
The angle between normals below which points are considered colinear and VarDistParallelBehavior is applied if distances are not the same.
?useUTurnBehaviorAbove : MeasureProduct<cosine, MeasureOne>
-
Optional. Default value: `Cosine.``175.0`` `.
The angle between normals after which, instead of a normal miter, the joint is chamfered by adding an extra point.
Returns: Polyline2D
A new 2D polyline.
|
Offsets a Polyline in 2D space by finding the local offset in each corner. Auto detects if given points are from a closed Polyline (first point = last point) and loops them. By default this function raises an Exception on duplicate points, 180 degree U-Turns, and variable distances at colinear segments. But this can be configured with optional parameters.
|
Full Usage:
Polyline2D.offsetVar (polyLine, multipleOffsetDistances, ?loop, ?checkOrientation, ?varDistParallelBehavior, ?uTurnBehavior, ?useVarDistParallelBehaviorBelow, ?useUTurnBehaviorAbove)
Parameters:
Polyline2D
-
A 2D Polyline, open or closed.
multipleOffsetDistances : IList<float>
-
The parallel offset distances for each segment of the polyline.
A positive distance offsets inwards in corners, a negative offset outwards.
For open and closed polylines this list of distances must have one item less than number of points in the polyline.
Except if the polyline is open and the loop parameter is set to true. Then points and distances list shall have the same count.
?loop : bool
-
bool, Optional (false).
Set to true to explicitly consider last point and first point to be from a closed loop, even if they are not at the same location.
?checkOrientation : bool
-
bool, Optional(true). By default the algorithm always checks if the polyline is clockwise or counter clockwise.
So that positive offset distances are always towards the inside of the polyline.
Set this parameter to false if you are sure that the input polyline is counter clockwise or if you want to skip this check.
?varDistParallelBehavior : VarDistParallel
-
Optional. Default value: `Offset2D.VarDistParallelBehavior.Fail`.
What to do with colinear segments below 'useVarDistParallelBehaviorBelow' degrees when offset distances are different too.
?uTurnBehavior : UTurn
-
Optional. Default value: `Offset2D.UTurnBehavior.Fail`.
What to do at a 180 degree U-turn? Fail, Chamfer with two points, Use179 or Skip the point.
?useVarDistParallelBehaviorBelow : MeasureProduct<cosine, MeasureOne>
-
Optional. Default value: `Cosine.``5.0`` `.
The angle between normals below which points are considered colinear and VarDistParallelBehavior is applied if distances are not the same.
?useUTurnBehaviorAbove : MeasureProduct<cosine, MeasureOne>
-
Optional. Default value: `Cosine.``175.0`` `.
The angle between normals after which, instead of a normal miter, the joint is chamfered by adding an extra point.
Returns: Polyline2D
A new 2D polyline.
|
Offsets a Polyline in 2D space by finding the local offset in each corner. Auto detects if given points are from a closed Polyline (first point = last point) and loops them. By default this function raises an Exception on duplicate points, 180 degree U-Turns, and variable distances at colinear segments. But this can be configured with optional parameters.
|
|
|
|
Gets the internal list of all Points of the Polyline2D. This is not a copy, so changes to the list will be reflected in the Polyline2D.
|
Full Usage:
Polyline2D.removeColinearAndDuplicatePoints angleTolerance distanceTolerance pl
Parameters:
float<MeasureProduct<cosine, MeasureOne>>
distanceTolerance : float
pl : Polyline2D
Returns: Polyline2D
|
Removes consecutive duplicate points and colinear points from the Polyline2D within given tolerances. This algorithm allows the last and first point to be identical if the Polyline2D is closed. Colinear points are removed when the angle between segments is smaller than the cosine threshold (e.g. cosine of 0.5 degrees ). If the Polyline2D is closed and starts and ends with colinear segments, the first point is replaced with the last non-colinear point. So the joint of the loop is now moved to the last non-colinear point. So that there are no colinear segments even between start and end.
|
Full Usage:
Polyline2D.removeDuplicatePoints distanceTolerance pl
Parameters:
float
pl : Polyline2D
Returns: Polyline2D
|
Removes consecutive duplicate points from the Polyline2D within a given tolerance. This algorithm allows the last and first point to be identical if the Polyline2D is closed.
|
|
|
|
Reverse order of the Polyline2D in place.
|
|
|
Full Usage:
Polyline2D.rotateWithCenter cen r pl
Parameters:
Pt
r : Rotation2D
pl : Polyline2D
Returns: Polyline2D
|
Rotation a Polyline2D round given Center point an a local Z-axis.
|
Full Usage:
Polyline2D.scale factor pl
Parameters:
float
pl : Polyline2D
Returns: Polyline2D
|
Scales the Polyline2D by a given factor. Scale center is World Origin 0,0 Returns a new Polyline2D.
|
|
|
|
|
Full Usage:
Polyline2D.subPolyline a b pl
Parameters:
float
b : float
pl : Polyline2D
Returns: Polyline2D
|
Returns new Polyline2D from point at Parameter a to point at Parameter b. if 'a' is bigger 'b' then the new Polyline2D is in opposite direction. If a parameter is within 1e-4 of an integer value, the integer value is used as parameter.
|
|
|
Full Usage:
Polyline2D.tryFindSelfIntersection pl
Parameters:
Polyline2D
Returns: Option<Pt * int * int>
|
Tries to find a self intersection in the Polyline2D. Also returns Some if segments are just touching. If found returns the intersection point and the indices of the two segments that intersect. If no intersection is found returns None. This is an O(n^2) algorithm and should only be used for small Polylines.
|
Full Usage:
Polyline2D.windingNumber point pl
Parameters:
Pt
-
The point to test.
pl : Polyline2D
-
The closed Polyline2D.
Returns: int
The winding number. Zero means outside, non-zero means inside.
Modifiers: inline |
Count how many times the polygon winds around the point. If the result is 0 then the point is outside of the Polyline2D. A non-zero value indicates the point is inside. The first and last point of the Polyline2D need to be identical for correct results. Boundary cases: Points exactly on edges or vertices may return inconsistent results due to floating-point precision. For points on horizontal edges, behavior depends on the edge direction. This method Handles self-intersecting polygons more intuitively than the pl.Contains method.
|
Euclid