Skip to content

Polygon2DBuilder

Canonical path: NemAll_Python_Geometry.Polygon2DBuilder

Polygon2D builder

This builder construct new, or modified existing Polygon2D object. Support creation of loops, called as Component, or deletion of component. Each loop must be started by calling BeginComponent() andized by calling EndComponent(). When loop is not started, or stopped without started, then these methods returns error.

Example of using: Polygon2D polygon; Point2D refPoint(100.,0.);

Builder::Polygon2DBuilder builder(polygon, refPoint, 5);

eGeometryErrorCode err = builder.BeginComponent(); // starting new loop if (err!=eOK) return; // error in starting loop

// calling 5times AddPoint err = builder.AddPoint(Point2D(0., 0.) ); if (err!=eOK) return; // point was not added

err = builder.EndComponent(); // stop the loop, closed point will be added automatically if (err!=eOK) return;

err = builder.Finalize(); // normalize polygon if (err!=eOK) return;

Methods:

Abort

Abort()

Abort all operations in builder

Calling of this method cancel all data in builder. Abort can be called if you want to break construction of polygon even if polygon is not correct because otherwise you get the error in Finalize phase.

Builder have no valid data after calling of this method.

AddComponent

AddComponent(component: Polygon2D) -> eGeometryErrorCode

Add component at the end of polygon eStructuralError in case of error, eAllocError in case of memory error.

Parameters:

Returns:

AddPoint

AddPoint(point: Point2D) -> eGeometryErrorCode

Add point at the end of polygon eStructuralError in case of error.

Parameters:

  • point (Point2D) –

    Point to inserted at the end of polygon

Returns:

BeginComponent

BeginComponent() -> eGeometryErrorCode

Starting of new polygon component eStructuralError in case of error.

This method must be called before creating new loop. When AddPoint is called before BeginComponent, then point will not be added. Each Component must be closed by EndComponent. When BeginComponent will be called twice without EndComponent, then second calling automatically stopped previous loop and when this operation will be successfully, then start new loop.

Returns:

CloseComponents

CloseComponents() -> eGeometryErrorCode

Close all components

This method only close all components if there are some opened and have no effect forization.

Returns:

Dirty

Dirty()

Set polygon as unfinalized

Call this method when polygon is modified directly without builder.

EndComponent

EndComponent() -> eGeometryErrorCode

End of component eStructuralError in case of error.

Stop the component started by BeginComponent. Each component must be stopped.

Returns:

Finalize

Finalize() -> eGeometryErrorCode

Finalize created or modified polygon

This method Finished running loops and Normalize polygon. Can be called explicitly by this method, or implicitly by destructor.

Returns:

GetComponent

GetComponent(position: int) -> tuple[eGeometryErrorCode, Polygon2D]

Get the component at the specified position eOutOfRange when position is out of range

Parameters:

  • position (int) –

    Position of component [zero based]

Returns:

GetCountOfComponents

GetCountOfComponents() -> int

Get count of components

Returns:

  • int

    Count of components, when zero then polygon is empty

IsComponent

IsComponent(polygon: Polygon2D) -> bool

Find out whether is given polygon an existing component

Parameters:

  • polygon (Polygon2D) –

    Potential component

Returns:

  • bool

    true if is

ReInitialize

ReInitialize(
    refPoint: Point2D, expectedPointsCount: int
) -> tuple[eGeometryErrorCode, Polygon2D]

Reinitialize builder with new polygon eStructuralError in case of error.

This method is using when builder must be reset to construction of new polygon. Input polygon must be valid or empty. If not, then method return error.

Parameters:

  • refPoint (Point2D) –

    New reference point of polygon

  • expectedPointsCount (int) –

    Expected points of new created polygon, with closed points

Returns:

RemoveComponent

RemoveComponent(position: int) -> eGeometryErrorCode

Remove component at the specified position eOutOfRange when position is out of range

Parameters:

  • position (int) –

    Position of removed component. [zero based]

Returns:

SetFinalized

SetFinalized()

SplitToPolygonParts staticmethod

SplitToPolygonParts(polygon: Polygon2D) -> Polygon2DList

Split a polygon to the loop parts

Parameters:

Returns:

__iadd__ overloaded

__iadd__(component: Polygon2D) -> None

Add component

Parameters:

__iadd__(point: Point2D) -> None

Add point to currently opened component

In case of error, method throw geometry exception.

Parameters:

__init__ overloaded

__init__(polygon: Polygon2D)

Attach polygon only

This constructor is using when polygon will be modified, not constructed. Input polygon must be valid or empty. If not, then ctor throw geometry exception.

Parameters:

__init__(polygon: Polygon2D, refPoint: Point2D, expectedPointsCount: int)

Attach polygon and prepare it to creation

This constructor is using when new polygon will be created. New polygon will be initialized with given reference point and allocated on given expected points count. Count of points includes closing points, it's mean that for polygon with square shape we expected 5 points. New created points can have less or more points as was entered as expectedPointsCount.

Parameters:

  • polygon (Polygon2D) –

    Attached polygon

  • refPoint (Point2D) –

    New reference point of polygon

  • expectedPointsCount (int) –

    Expected points of new created polygon, with closed points

Placeholder