The direction of a multi-polygon loop matters because the area calculation takes into
account the direction of the loop. A loop with counterclockwise direction has a positive area value. Clockwise direction results in a negative value.
To find out the direction of a loop, use the
getLoopDirection() method. The method requires two parameters:
input integer value to specify the loop index
output enumeration of the loopDir type to indicate the loop
direction
The loopDir
enumeration defines the following values for loop directions:
enum loopDir {
kExterior = 0, // Loop direction is counterclockwise
kInterior = 1, // Loop direction is clockwise
kAnnotation = 2 // Text
};
To change the loop direction of a multi-polygon, use the
setLoopDirection() method. It requires two parameters:
input integer value to specify the loop index
input value of the loopDir type to specify the loop direction
Continued previous example:
loopDirection = OdDbMPolygon::kExterior;
pMPolygon->setLoopDirection(0, loopDirection); // change the loop direction from clockwise to counter-clockwise
pMPolygon->getArea(area); // area == 12.5
Automatic correction of the loop direction
To change a loop direction automatically, use the
balanceTree() method.
The direction of the loops is changed to the correct one.
Note: If there are loops that intersect one
another, one of them is marked as invalid and no longer
participates in rendering of the multi-polygon as a filled loop. Depending on the
POLYDISPLAY system variable, the outline of the invalid loop can
be drawn or not.
Continued from the first example:
pMPolygon->balanceTree();
pMPolygon->getArea(area); // area == 12.5
The figure below illustrates the result of the balanceTree()
method when loops intersect each other.
The next figure illustrates the result of executing the
balanceTree() method if the system variable
POLYDISPLAY == 0.
Validate the loop direction and intersection
To validate the correct direction of multi-polygon loops and their intersections,
use the balanceDisplay() method.
If the loop that is drawn has intersections or the wrong direction, it is marked as invalid. If among the invalid loops there are loops that no longer
intersect or have the correct direction, they are marked as valid.
Note: The balanceDisplay() method
does not correct the direction of loops. To do this, use the
balanceTree() or
setLoopDirection() method.