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).
CreateRectangle
staticmethod
GetSegments
GetSegments() -> tuple[eGeometryErrorCode, list[Line2D]]
Get polygon segments
Returns:
-
tuple[eGeometryErrorCode, list[Line2D]]
–tuple(error code, vector of polygon segments)
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 = 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 = 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)
__eq__
__eq__(polygon2: Polygon2D) -> bool
Equal operator
Parameters:
-
polygon2
(Polygon2D
) –Second polygon
Returns:
-
bool
–Polyline3D are equal
__iadd__
__init__
overloaded
Initialize
Constructor with an initializer list
Parameters:
-
pntList
(list
) –Point list
__init__(polygon: Polygon2D)