Polygon Operations Extension

This add-on calculates result polygons based on the input polygons and the operation that is carried out on them.

Input polygons are identified by a name when passed to the add-on and are stored in a previously defined container.
Result polygons are automatically named by the add-on and are stored in a second, target container.
Input and result polygons are thus stored in different containers.

Multiple polygons, possibly with an even greater number of contours, can be created by a single operation.
These will be administered as individual polygons in the target container.
As a result, these polygons can be accessed in subsequent polygon operations.
The principle is the same as with the Solid Geometry Commands (see in the section called “Solid Geometry Commands”).
Input polygons must be contiguous.

A polygon is defined by several contours, each of which is an uninterrupted sequence of connected vertices.
The first contour is the outer boundary.
The subsequent contours must all be inside the first, they may not overlap, and they create cutouts of the first polygon.

Opening a channel

ch = INITADDONSCOPE ("PolyOperations ", "", "")

Opens a channel. The return value is the ID of the opened channel.

Polygon container management

PREPAREFUNCTION ch, "CreateContainer", "myContainer", ""

Creates a new polygon container.

PREPAREFUNCTION ch, "DeleteContainer", "myContainer", ""

Delete an existing polygon container.

PREPAREFUNCTION ch, "EmptyContainer", "myContainer", ""

Emptying an existing polygon container.

PREPAREFUNCTION ch, "SetSourceContainer", "mySourceContainer", ""

Set container as source container.

PREPAREFUNCTION ch, "SetDestinationContainer", "myDestinationContainer", ""

Set container as destination container.

Polygon management

PREPAREFUNCTION ch, "Store", "poly1", nVertices, nContours,
    vertArray, contourArray [, defaultInhEdgeInfo, inhEdgeInfosArray]

Stores the polygon “poly1” with the given parameters in the actual source container.

poly1: name of the stored polygon

nVertices: number of vertices

nContours: number of contours

vertArray: Array containing exactly nVertices items that describes all contours of the polygon. Two dimension array of (x, y, angle)
records where x, y, and angle is real value. The angle parameter is the view-angle (deflection) in case of arched edges.
This is a signed value, reflecting the orientation. Zero value means straight edge.

contourArray: An array which contains the index of the last vertex of the i-th contour. It must have exactly nContours items.

defaultInhEdgeInfo: One piece of inherited edge information.
To the brand new edges (not created with split) in operations performed later this information will be attached.
With the aid of this you can easily trace the newly created edges after complex operations. (Optional)

inhEdgeInfosArray: Array containing information attached to edges. It must of contain exactly nVertices integer type items.
If an edge splits into more than one new edge in an operation, this information will be inherited without change to all new edges created.
You can use it for example to store the side angles of a roof. (Optional)

Remarks:

  • Polygons can have holes and curved edges though these curved edges can be only circle-arcs.

  • This polygon can link to additional data for every edge.

  • The first vertex must be always repeated in the last for all contours.
    So in this representation, a triangle have four vertices, where the first and the last vertex is identical.

  • The first contour is the main contour, and it must contain the others.

PREPAREFUNCTION ch, "Dispose", "poly1", "myContainer"

Deletes the polygon “poly1” from the container “myContainer”.

Polygon operation settings

PREPAREFUNCTION ch, "HalfPlaneParams", "", ca, cb, cc

Set the half plane in 2D to be used in the “PolyCut” operation.

Defining inequality for the half plane: ca * x + cb * y > cc.

ca: Coefficient of x

cb: Coefficient of y

cc: Constant

PREPAREFUNCTION ch, "OffsetParams", "", itemIdx, offsetValue

Set the offset parameters used in “OffsetEdge” and “ResizeContour” operation.

itemIdx: Index of the edge to be translated (for “OffsetEdge” operation). Index of the resizable contour
(for “ResizeContour” operation).

offsetValue: Distance of the translation. Negative and positive offset values make the edge move inside and outside,
respectively. If the offset is big, the neighboring vertices can be cut out.

Polygon operations

In the following polygon operations the “poly1” and “poly2” source polygons are located in the source polygon container.
The resulting polygons are stored in the destination polygon container with an unique name started with “resPolygonID”,
where “ID” is a number.

dim resPolyIDArray[]
nPgon = CALLFUNCTION (ch, "poly1 OP poly2", "", resPolyIDArray)

Executes the “OP” operation with “poly1” and “poly2” polygons and puts the new values into the given parameters. The return value is the
number of the generated polygons

OP: can be:
+: Polygon addition
-: Polygon subtraction
/: Polygon intersection

resPolyIDArray: Array of resulting polygon identifiers.

Copying a polygon from the source container to the destination container

dim resPolyIDArray[]
nPgon = CALLFUNCTION (ch, "CopyPolygon", "poly1", resPolyIDArray)

Regularizing a polygon – Making it geometrically valid.

dim resPolyIDArray[]
nPgon = CALLFUNCTION (ch, "Regularize", "poly1", resPolyIDArray)

A polygon is valid if

  • Its first boundary contains all the others

  • Is oriented correctly (the main contour is a positively oriented curve, the rest is oriented negatively)

  • Has no self-intersections

  • Its area is not zero

  • Has no zero length edges

Intersecting the polygon with a halfplane.

The halfplane must be set with an “HalfPlaneParams” command. The result will be regularized.

dim resPolyIDArray[]
nPgon = CALLFUNCTION (ch, "PolyCut", "poly1", resPolyIDArray)

Translating an edge of a polygon perpendicularly to its direction.


The edge index and translation offset must be set with an “OffsetParams” command. The result will be regularized.

dim resPolyIDArray[]
nPgon = CALLFUNCTION (ch, "OffsetEdge", "poly1", resPolyIDArray)

Enlarges or shrinks a contour of a polygon.


The contour index and translation offset must be set with an “OffsetParams” command. The result will be regularized.

dim resPolyIDArray[]
nPgon = CALLFUNCTION (ch, "ResizeContour", "poly1", resPolyIDArray)

Get resulting polygons

Getting all polygon names from the actual source container.

dim resPolyIDArray[]
nPgon = CALLFUNCTION (ch, "GetSourcePolygons", "", resPolyIDArray

Getting all polygon names from the actual destination container.

dim resPolyIDArray[]
nPgon = CALLFUNCTION (ch, "GetDestinationPolygons", "", resPolyIDArray)

Getting the resulting polygon vertices after any polygon operation call.

The polygon with name “polygonID” located in the destination polygon container.

dim resVertices[]
nVertices = CALLFUNCTION (ch, "GetVertices", polygonID, resVertices)

Getting the resulting polygon contour end indices after any polygon operation call.

The polygon with name “polygonID” located in the destination polygon container.

dim contArr[]
nContours = CALLFUNCTION (ch, "GetContourEnds", polygonID, contArr)

Getting the resulting polygon contour information after any polygon operation call.

dim inhEdgeInfosArr[]
nEdgeInfos = CALLFUNCTION (ch, "GetInhEdgeInfos", polygonID, inhEdgeInfosArr)

The polygon with name “polygonID” located in the destination polygon container.

Closing channel

CLOSEADDONSCOPE (ch)

Closes channel “ch”. Deletes all of the stored polygons.