Skip to content

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:

  • CreateRectangle

    Create a rectangle

  • GetSegments

    Get polygon segments

  • IsValid

    Check if the polygon is valid ( has at least 3 points )

  • Normalize

    Normalize Polygon2D.

  • NormalizeNoThrow

    Normalize Polygon2D.

  • Reverse

    Reverse the point order in polygon, separatelly for every subpolygon

  • __eq__

    Equal operator

  • __iadd__

    Addition assignment operator

  • __init__

    dummy, is only needed for the creation of the documentation by MkDocs

  • __ne__

    Not equal operator

  • __repr__

    Convert to string

CreateRectangle staticmethod

CreateRectangle(leftBottom: Point2D, rightTop: Point2D) -> Polygon2D

Create a rectangle

Parameters:

  • leftBottom (Point2D) –

    Left bottom point

  • rightTop (Point2D) –

    Right top point

Returns:

GetSegments

GetSegments() -> tuple[eGeometryErrorCode, list[Line2D]]

Get polygon segments

Returns:

IsValid

IsValid() -> bool

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:

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:

Returns:

Reverse

Reverse()

Reverse the point order in polygon, separatelly for every subpolygon

__eq__

__eq__(polygon2: Polygon2D) -> bool

Equal operator

Parameters:

Returns:

  • bool

    Polyline3D are equal

__iadd__

__iadd__(point: Point2D) -> Polygon2D

Addition assignment operator

Parameters:

  • point (Point2D) –

    Point which will be added

Returns:

__init__ overloaded

__init__()

Initialize

__init__(pntList: list)

Constructor with an initializer list

Parameters:

  • pntList (list) –

    Point list

__init__(polygon: Polygon2D)

Copy constructor.

Parameters:

  • polygon (Polygon2D) –

    Polygon which will be copied

__ne__

__ne__(polygon2: Polygon2D) -> bool

Not equal operator

Parameters:

Returns:

  • bool

    Polyline3D are equal

__repr__

__repr__() -> str

Convert to string