Polygon2D
Canonical path: NemAll_Python_Geometry.Polygon2D
Bases: PolyPoints2D
Representation of a two dimensional polygon
To construct a valid polygon from a bunch of points, the following rules must be fulfilled:
- First and last point must coincide. This class does not 'auto-close' polygons! A quadratic shape with '4' edges has to be defined by passing 5 points to a constructor. For such an object, the Count() method will return 5 accordingly.
- The orientation of the points must be monotonous. It can be either clockwise or counter-clockwise.
- The polygon must not self-intersect itself. You can create polygons that self-intersect or have alternating orientation, but in those cases some methods will raise errors or return wrong calculation results.
Each polygon consists of one or more components. A component is a closed loop, representing either a solid or a cut-out, depending on the orientation of the loop (if counter-clockwise is solid element, then clockwise is a cut-out). Each component must be closed (first and last point coincide).
Methods:
-
Clear
–Remove all points from vector.
-
Count
–Get count of points.
-
CreateRectangle
–Create a rectangle
-
Empty
–Return true if no points, otherwise false.
-
EqualRef
–Test if reference points are equal.
-
GetEndPoint
–Get the end point in world coordinate system.
-
GetEndRelPoint
–Get the end point
-
GetLastPoint
–Get the last point in world coordinate system.
-
GetPoint
–Get point in world coordinate system.
-
GetPointIndex
–Get index of the given point
-
GetPointIndexes
–Get indexes of the given point, in case that several points in the spline
-
GetRefPoint
–Get reference point.
-
GetRelPoint
–Get point in Local coordinate system.
-
GetSegments
–Get polygon segments
-
GetStartPoint
–Get the start point in world coordinate system.
-
GetStartRelPoint
–Get the start point
-
Insert
–Overloaded function. See individual overloads.
-
InsertRel
–Insert relative point at specific position. Used local coordinates.
-
IsValid
–Check if the polygon is valid ( has at least 3 points )
-
Normalize
–Normalize Polygon2D.
-
NormalizeNoThrow
–Normalize Polygon2D.
-
Remove
–Remove point from specific position.
-
RemoveLastPoint
–Remove the last point
-
Reserve
–Reserve container capacity
-
Resize
–Specifies a new size for the points vector.
-
Reverse
–Reverse the point order in polygon, separatelly for every subpolygon
-
SetEndPoint
–Set the end point in world coordinates
-
SetPoint
–Set point at given position in world coordinate system.
-
SetRefPoint
–Set reference point in world coordinate system.
-
SetRelPoint
–Set point at given position in relative coordinate system.
-
SetStartPoint
–Set the start point in world coordinates
-
ToLineChain
–Get polyline as a chain of lines composed from 2 points.
-
__eq__
–Equal operator
-
__getitem__
–Get point at position from index. Used world coordinates.
-
__iadd__
–Addition assignment operator
-
__init__
–Overloaded function. See individual overloads.
-
__mul__
–2D matrix transformation
-
__ne__
–Not equal operator
-
__repr__
–Convert to string
-
__setitem__
–Set a value at position from index.
Attributes:
-
EndPoint
(Point2D
) –Get the end point in world coordinate system.
-
EndRelPoint
(Point2D
) –Get the end point
-
LastPoint
(Point2D
) –Get the last point in world coordinate system.
-
Points
(list[Point2D]
) –Get the points
-
RefPoint
(Point2D
) –Get reference point.
-
StartPoint
(Point2D
) –Get the start point in world coordinate system.
-
StartRelPoint
(Point2D
) –Get the start point
CreateRectangle
staticmethod
EqualRef
EqualRef(polyPoints: PolyPoints2D) -> bool
Test if reference points are equal.
Parameters:
-
polyPoints
(PolyPoints2D
) –the PolyPoints.
Returns:
-
bool
–Reference points are equal: true/false
GetEndPoint
GetEndPoint() -> Point2D
Get the end point in world coordinate system.
Returns:
-
Point2D
–end point in world coordinate system
GetLastPoint
GetLastPoint() -> Point2D
Get the last point in world coordinate system.
Returns:
-
Point2D
–last point in world coordinate system
GetPoint
GetPoint(index: int) -> Point2D
Get point in world coordinate system.
This method is checked and throwing Geometry::Exception when index is out of range.
Parameters:
-
index
(int
) –point index.
Returns:
-
Point2D
–point point in world coordinate system.
GetPointIndex
GetPointIndexes
GetRefPoint
GetRefPoint() -> Point2D
GetRelPoint
GetRelPoint(index: int) -> Point2D
Get point in Local coordinate system.
This method is checked and throwing Geometry::Exception when index is out of range.
Parameters:
-
index
(int
) –point index.
Returns:
-
Point2D
–point the point at position index.
GetSegments
GetSegments() -> tuple[eGeometryErrorCode, list[Line2D]]
Get polygon segments
Returns:
-
tuple[eGeometryErrorCode, list[Line2D]]
–tuple(error code, vector of polygon segments)
Examples:
GetStartPoint
GetStartPoint() -> Point2D
Get the start point in world coordinate system.
Returns:
-
Point2D
–start point in world coordinate system
Insert
overloaded
Insert(polyPoints: PolyPoints2D, position: int = 18446744073709551615) -> bool
Insert vector of points at specific position.
If return false then points weren't inserted.
Parameters:
-
polyPoints
(PolyPoints2D
) –the PolyPoints.
-
position
(int
, default:18446744073709551615
) –position where points will be inserted.
Returns:
-
bool
–bool true if successful.
Insert(point: Point2D, position: int = 18446744073709551615) -> bool
Insert point at specific position. Used world coordinates.
If return false then points weren't Inserted.
Parameters:
-
point
(Point2D
) –the Point.
-
position
(int
, default:18446744073709551615
) –position where points will be inserted.
Returns:
-
bool
–bool true if successful.
InsertRel
InsertRel(point: Point2D, position: int = 18446744073709551615) -> bool
Insert relative point at specific position. Used local coordinates.
If return false then points weren't Inserted.
Parameters:
-
point
(Point2D
) –the Point.
-
position
(int
, default:18446744073709551615
) –position where points will be inserted.
Returns:
-
bool
–bool true if successful.
IsValid
Check if the polygon is valid ( has at least 3 points )
For additional point validation use Service::Validate.
Returns:
-
bool
–true if is valid
Normalize
Normalize(
normalizeType: ePolygonNormalizeType = DEFAULT_NORM_TYPE,
extra_smooth: bool = False,
)
Normalize Polygon2D.
Using huge old algorithm, adding points at line crossings, reorganizing the lines, correcting gaps, ... This method is checked and throwing Exception when error occurs.
Parameters:
-
normalizeType
(ePolygonNormalizeType
, default:DEFAULT_NORM_TYPE
) –type of Polygon2D normalization
-
extra_smooth
(bool
, default:False
) –Including extra smooth: true/false
NormalizeNoThrow
NormalizeNoThrow(
normalizeType: ePolygonNormalizeType = DEFAULT_NORM_TYPE,
extra_smooth: bool = False,
) -> eGeometryErrorCode
Normalize Polygon2D.
Same as Normalize, but method doesn't throw exception, just return error code
Parameters:
-
normalizeType
(ePolygonNormalizeType
, default:DEFAULT_NORM_TYPE
) –type of Polygon2D normalization
-
extra_smooth
(bool
, default:False
) –Including extra smooth: true/false
Returns:
-
eGeometryErrorCode
–Error code (eOK, eAllocError, eStructuralError)
Remove
Remove point from specific position.
If return false then points weren't removed.
Parameters:
-
position
(int
) –position of point which will be removed.
Returns:
-
bool
–Point removed: true/false
RemoveLastPoint
Remove the last point
Returns:
-
bool
–Point removed: true/false
Reserve
Reserve container capacity
Parameters:
-
newCount
(int
) –Expected size of container [count of points]
Resize
Specifies a new size for the points vector.
Parameters:
-
newSize
(int
) –The new size of the points vector.
SetEndPoint
SetEndPoint(endpoint: Point2D)
SetPoint
SetPoint(point: Point2D, index: int)
Set point at given position in world coordinate system.
Parameters:
-
point
(Point2D
) –point in the world coordinate system.
-
index
(int
) –index of point which will be set
SetRefPoint
SetRefPoint(refPoint: Point2D)
Set reference point in world coordinate system.
Parameters:
-
refPoint
(Point2D
) –reference point in the world coordinate system.
SetRelPoint
SetRelPoint(point: Point2D, index: int)
Set point at given position in relative coordinate system.
Parameters:
-
point
(Point2D
) –point in the relative coordinate system.
-
index
(int
) –index of point which will be set
SetStartPoint
SetStartPoint(startpoint: Point2D)
ToLineChain
ToLineChain() -> Point2DList
Get polyline as a chain of lines composed from 2 points.
Returns:
-
Point2DList
–vector of lines composed from 2 points (start and end point of a line)
__eq__
__eq__(polygon2: Polygon2D) -> bool
Equal operator
Parameters:
-
polygon2
(Polygon2D
) –Second polygon
Returns:
-
bool
–Polyline3D are equal
__getitem__
__getitem__(index: int) -> Point2D
Get point at position from index. Used world coordinates.
This method is checked and throwing Geometry::Exception when index is out of range.
Parameters:
-
index
(int
) –point index.
Returns:
-
Point2D
–copy of point.