# TPointArray TPointArray related methods - - - ## TPointArray.Mean ```pascal function TPointArray.Mean(): TPoint; constref; ``` Wraps Simba's TPAMiddle - - - ## TPointArray.MeanEx ```pascal function TPointArray.MeanEx(): Vector2; constref; ``` Middle as a Vector. - - - ## TPointArray.Sort ```pascal procedure TPointArray.Sort(From:TPoint=[0,0]); ``` Wraps Simba's `SortTPAFrom` - - - ## TPointArray.SortFrom ```pascal function TPointArray.Sorted(from: TPoint = [0,0]): TPointArray; function TPointArray.SortFrom(from: TPoint = [0,0]): TPointArray; constref; ``` Wraps Simba's `SortTPAFrom`, produces a sorted copy. - - - ## TPointArray.SortByX ```pascal procedure TPointArray.SortByX(LowToHi:Boolean=True); ``` Wraps Simba's `SortTPAByX` - - - ## TPointArray.SortByY ```pascal procedure TPointArray.SortByY(LowToHi:Boolean=True); ``` Wraps Simba's `SortTPAByY` - - - ## TPointArray.SortByRow ```pascal procedure TPointArray.SortByRow(reverse:Boolean=False); ``` Sorts a given TPointArray TPA row-by-row, starting from the smallest Y coordinate to the largest Y coordinate, and for every row from the smallest X coordinate to the largest X coordinate. - - - ## TPointArray.SortByColumn ```pascal procedure TPointArray.SortByColumn(reverse:Boolean=False); ``` Much like SortByRow, but the order of the column comes first - - - ## TPointArray.SortFromLine ```pascal procedure TPointArray.SortFromLine(p,q:TPoint; reverse:Boolean=False); ``` The name tells the story - - - ## TPointArray.Bounds ```pascal function TPointArray.Bounds(): TBox; constref; ``` Wraps Simba's GetTPABounds - - - ## TPointArray.Edges ```pascal function TPointArray.Edges(): TPointArray; constref; ``` Filters all points out of the given TPointArray which aren't edge-points. Edge-points are points that are on the edge of the TPA, not completely surrounded by other points. Same as Simba's `FindTPAEdges` - - - ## TPointArray.Cluster ```pascal function TPointArray.Cluster(dist: Int32): T2DPointArray; constref; function TPointArray.Cluster(distX,distY: Int32): T2DPointArray; constref; overload; ``` Smart wrapper of Simba's `ClusterTPA` and `ClusterTPAEx` (fall backs to `SplitTPA` when it's better suited) - - - ## TPointArray.Split ```pascal function TPointArray.Split(dist: Int32): T2DPointArray; constref; function TPointArray.Split(distX,distY: Int32): T2DPointArray; constref; overload; ``` Wraps Simba's `SplitTPA` and `SplitTPAEx` - - - ## TPointArray.ToATPA ```pascal function TPointArray.ToATPA(WH:Int32): T2DPointArray; constref; function TPointArray.ToATPA(W,H:Int32): T2DPointArray; constref; overload; ``` Wraps Simba's `TPAToATPA` and `TPAToATPAEx` - - - ## TPointArray.Offset ```pascal function TPointArray.Offset(X, Y: Int32): TPointArray; constref; function TPointArray.Offset(off: TPoint): TPointArray; constref; overload; ``` Wraps Simba's `OffsetTPA` - - - ## TPointArray.Invert ```pascal function TPointArray.Invert(Area:TBox=[0,0,-1,-1]): TPointArray; constref; ``` Inverts the shape based on the area covered, alternatively the given area. Same as `ReturnPointsNotInTPA` in Simba. - - - ## TPointArray.Filter ```pascal function TPointArray.FilterBox(b: TBox): TPointArray; constref; function TPointArray.FilterRectangle(rect: TRectangle): TPointArray; constref; function TPointArray.FilterCircle(circle: TCircle): TPointArray; constref; function TPointArray.FilterDist(MinDist,MaxDist: Double; Mx,My: Int32): TPointArray; constref; function TPointArray.FilterDuplicates(): TPointArray; constref; ``` Returns a filtered versions of the TPA. They should be self explanatory by their naming and parameters. - - - ## TPointArray.ClearDuplicates ```pascal procedure TPointArray.ClearDuplicates(); ``` Removes all the duplicate points from self. - - - ## TPointArray.Rotate ```pascal function TPointArray.Rotate(angleRad, x, y: Double): TPointArray; function TPointArray.Rotate(angleRad: Double; mid: TPoint): TPointArray; constref; overload; function TPointArray.Rotate(angleRad: Double; mid: Vector2): TPointArray; constref; overload; ``` Returns a copy where all points are rotated around `x` and `y`, a `TPoint` or a `Vector2`. Same as Simba's `RotatePoints`. - - - ## TPointArray.SplitRows ```pascal function TPointArray.SplitRows(dist:Int32): T2DPointArray; constref; ``` Splits a TPA `Arr` into TPAs of each row, it then proceeds to further split the rows in to separate TPAs when the given distance ``dist`` is less than the distance between the points Same output as `SplitTPAEx(TPA,dist,0)`, but generally faster. ```{note} By slacky ``` Example: ```pascal ATPA := TPA.SplitRows(5); ``` - - - ## TPointArray.Connect ```pascal function TPointArray.Connect(): TPointArray; constref; ``` Fills a line between all the points (by their order), can be used to get the edges around a polygon ```{note} By slacky ``` Example: ```pascal edges := TPA.ConvexHull().Connect(); ``` - - - ## TPointArray.ConvexHull ```pascal function TPointArray.ConvexHull(): TPointArray; constref; ``` Computes the convex hull around the given TPA. Imagine placing a rubber band around the points, the points which strech the band are the points returned by this function. See: http://en.wikipedia.org/wiki/Convex_hull for more information. ```{note} By slacky ``` Example: ```pascal Smart.Image.DrawTPA(TPA.ConvexHull()); ``` - - - ## TPointArray.MinAreaRect ```pascal function TPointArray.MinAreaRect(): TRectangle; ``` Computes the minimum bounding box (defined by area) around the given shape. Four points (which are in order) are always returned. See: http://en.wikipedia.org/wiki/Minimum_bounding_box for more information. ```{note} By slacky ``` Example: ```pascal WriteLn('The four box corners are: ', TPA.MinAreaRect()); ``` - - - ## TPointArray.MinAreaCircle ```pascal function TPointArray.MinAreaCircle(): TCircle; ``` Computes the minimum bounding circle around the given shape. See: https://en.wikipedia.org/wiki/Smallest-circle_problem for more information. Implementation is a mixture of a few implementations I've seen. - - - ## TPointArray.Density ```pascal function TPointArray.Density(): Double; constref; ``` Returns the TPA's density (Length(TPA)/(width*height)) - - - ## ExpandPolygon ```pascal function ExpandPolygon(Poly:TPointArray; inc:Int32): TPointArray; ``` A method for increasing the size of any convex polygon. ```{note} By slacky ``` - - - ## TPointArray.PointsInRangeOf ```pascal function TPointArray.PointsInRangeOf(constref Other: TPointArray; MinDist, MaxDist: Double): TPointArray; constref; function TPointArray.PointsInRangeOf(constref Other: TPointArray; MinDistX, MinDistY, MaxDistX, MaxDistY: Double): TPointArray; constref; overload; ``` Returns all the points from `self` that are within range of any point in `other`. The parameters `mindist` and `maxdist` determine what "within range" means. - - - ## TPointArray.InRange ```pascal function TPointArray.AnyInRange(p: TPoint; dist: Double): Boolean; function TPointArray.AnyInRange(other: TPointArray; dist: Double): Boolean; overload; function TPointArray.AllInRange(p: TPoint; dist: Double): Boolean; ``` Checks if the current points are within `dist` distance of `p`.