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 all operations in builder
-
AddComponent–Add component at the end of polygon
-
AddPoint–Add point at the end of polygon
-
BeginComponent–Starting of new polygon component
-
CloseComponents–Close all components
-
Dirty–Set polygon as unfinalized
-
EndComponent–End of component
-
Finalize–Finalize created or modified polygon
-
GetComponent–Get the component at the specified position
-
GetCountOfComponents–Get count of components
-
IsComponent–Find out whether is given polygon an existing component
-
ReInitialize–Reinitialize builder with new polygon
-
RemoveComponent–Remove component at the specified position
-
SetFinalized– -
SplitToPolygonParts–Split a polygon to the loop parts
-
__iadd__–Overloaded function. See individual overloads.
-
__init__–Overloaded function. See individual overloads.
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:
-
component(Polygon2D) –Added component
Returns:
-
eGeometryErrorCode–Error code, eOK when no error detected,
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:
-
eGeometryErrorCode–Error code, eOK when no error detected,
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:
-
eGeometryErrorCode–Error code, eOK when no error detected,
CloseComponents
CloseComponents() -> eGeometryErrorCode
Close all components
This method only close all components if there are some opened and have no effect forization.
Returns:
-
eGeometryErrorCode–Error code, eOK when no error detected.
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:
-
eGeometryErrorCode–Error code, eOK when no error detected,
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:
-
eGeometryErrorCode–Error code, eOK when no error detected.
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:
-
tuple[eGeometryErrorCode, Polygon2D]–tuple(Error code, eOK when no error detected,, Copy of component in given position)
GetCountOfComponents
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:
-
tuple[eGeometryErrorCode, Polygon2D]–tuple(Error code, eOK when no error detected,, Attached polygon)
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:
-
eGeometryErrorCode–Error code, eOK when no error detected,
SplitToPolygonParts
staticmethod
SplitToPolygonParts(polygon: Polygon2D) -> Polygon2DList
Split a polygon to the loop parts
Parameters:
-
polygon(Polygon2D) –Polygon to split
Returns:
-
Polygon2DList–Loop parts
__iadd__
overloaded
__iadd__(component: Polygon2D) -> None
__iadd__(point: Point2D) -> None
Add point to currently opened component
In case of error, method throw geometry exception.
Parameters:
-
point(Point2D) –Added point
__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:
-
polygon(Polygon2D) –Attached polygon
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: