It can be necessary to obtain points of the outer contour (or other
components for working with a specific loop) of a multi-polygon, but it is
unknown at what index this loop is stored in the multi-polygon. The following
function allows you to determine the position (depth) of a loop in a
multi-polygon.
virtual int getParentLoop(int curLoop) const
The function receives the loop index as a parameter and returns:
Non-negative index if the loop is found.
-1 if the specified loop does not have a parent loop.
-2 if the specified loop does not exist.
-3 if the specified loop intersects with a possible outer loop.
Simple example
The following figure shows a simple multi-polygon
composed of two loops.
To determine the order of loops for the above multi-polygon:
Call
getParentLoop(0).
It returns "1", which means that the
loop with index "0" is inside the loop with index "1".
Repeat the same
step, passing "1" to getParentLoop() as a parameter.
It returns "-1", which means that this
loop does not have a parent loop.
When determining the parent loop is impossible
The next figure shows a multi-polygon with four loops. The loop numbers are
shown in red.
The table below shows the correlation between input and output values of
getParentLoop() for the multi-polygon in the figure.
Input value
Return value
0
-1
1
0
2
0
3
1
If the current loop has an intersection with the parent loop, the parent of
the parent loop is returned (if it exists). In the table above, getParentLoop() returns "0" as the parent loop for the loop
number 2 because the number 2 and 1 loops intersect each other.
For loop number 3, it is also impossible to correctly determine the parent
loop, since the parent loop has an intersection with the parent-parent loop.
In the following figure there are only two loops that intersect each other
and no more outer loops without intersections. For the number 0 and 1 loops,
getParentLoop() returns "-3", which means the specified loop
intersects with a possible outer loop.