Polygon2D
Class full path: NemAll_Python_Geometry.Polygon2D
Bases: PolyPoints2D
Representation class for 2D Polygon
For constructing a polygon from a bunch of points, the following rules must be fulfilled: 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 points must be monotonous. It can be either clockwise or counter-clockwise. The polygon must not self-intersect itself. You can create instances of polygons that self-intersects or have alternating orientation, but in those cases some methods will report errors, throw or return wrong calculation results.
Each polygon is compound from one or more components. Component is a loop. Component represent solid element or hole element, it depend on orientation of loop (counter-clockwise is solid element, clockwise is hole). When polygon is created from more compounds, then each compound must be closed (first and last point are equal) and first and last point of hole polygon are equal too.
For better polygon creation you can use Builder::Polygon2DBuilder class.
Functions
CreateRectangle(leftBottom, rightTop)
staticmethod
Create a rectangle
Parameters:
Name | Type | Description | Default |
---|---|---|---|
leftBottom
|
Point2D
|
Left bottom point |
required |
rightTop
|
Point2D
|
Right top point |
required |
Returns:
Type | Description |
---|---|
Polygon2D
|
Polygon of the rectangle |
GetSegments()
Get polygon segments
Returns:
Type | Description |
---|---|
eGeometryErrorCode
|
tuple(error code, |
list[Line2D]
|
vector of polygon segments) |
IsValid()
Check if the polygon is valid ( has at least 3 points )
For additional point validation use Service::Validate.
Returns:
Type | Description |
---|---|
bool
|
true if is valid |
Normalize(normalizeType=DEFAULT_NORM_TYPE, extra_smooth=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:
Name | Type | Description | Default |
---|---|---|---|
normalizeType
|
ePolygonNormalizeType
|
type of Polygon2D normalization |
DEFAULT_NORM_TYPE
|
extra_smooth
|
bool
|
Including extra smooth: true/false |
False
|
NormalizeNoThrow(normalizeType=DEFAULT_NORM_TYPE, extra_smooth=False)
Normalize Polygon2D.
Same as Normalize, but method doesn't throw exception, just return error code
Parameters:
Name | Type | Description | Default |
---|---|---|---|
normalizeType
|
ePolygonNormalizeType
|
type of Polygon2D normalization |
DEFAULT_NORM_TYPE
|
extra_smooth
|
bool
|
Including extra smooth: true/false |
False
|
Returns:
Type | Description |
---|---|
object
|
Error code (eOK, eAllocError, eStructuralError) |
Reverse()
Reverse the point order in polygon, separatelly for every subpolygon
__eq__(polygon2)
Equal operator
Parameters:
Name | Type | Description | Default |
---|---|---|---|
polygon2
|
Polygon2D
|
Second polygon |
required |
Returns:
Type | Description |
---|---|
bool
|
Polyline3D are equal |
__iadd__(point)
Addition assignment operator
Parameters:
Name | Type | Description | Default |
---|---|---|---|
point
|
Point2D
|
Point which will be added |
required |
Returns:
Type | Description |
---|---|
Polygon2D
|
Reference to polygon |
__init__
overload
__init__()
Initialize
__init__(pntList)
Constructor with an initializer list
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pntList
|
list
|
Point list |
required |
__init__(polygon)
Copy constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
polygon
|
Polygon2D
|
Polygon which will be copied |
required |
__ne__(polygon2)
Not equal operator
Parameters:
Name | Type | Description | Default |
---|---|---|---|
polygon2
|
Polygon2D
|
Second polygon |
required |
Returns:
Type | Description |
---|---|
bool
|
Polyline3D are equal |
__repr__()
Convert to string