Comment 13 for bug 170588

Revision history for this message
Digulla (digulla) wrote :

> I think thats not the way because you have allways to
> potrace the bitmap region to fill, because you have to
> find the vector shape that defines the fill of bitmap.

Why? With my idea, we're just using the bitmap (without
tracing it) to find the vectors which make up the outline of
the fill (the transition points in the bitmap tell us where
to look for the elements of the outline).

But if you insist in a poly-only solution: First, we try to
find an intersection with the outline (send a ray to the
right, select closest intersection). This is point A.

Now, determine all intersections of this object with all others.

Go to the closest intersection (point B). Add the path from
A to B to result.

Determine which side of the intersecting element points
"away". Make the intersection to point A. Repeat.

If, at any stage, you cannot find intersections on the
correct side of A, the outline is not closed.

At this point, we might want to find the closest element and
check if the minimal distance is below a certain (user
specified) limit. If so, we create a line segment between
the two closest points and add that to the result.

If not, we abort with an error. We can even move the view to
the point were we couldn't continue so the user can fill the
gap and retry.

To determine whether to go left or right at an intersection,
this code might be useful:
http://www.alienryderflex.com/polygon/

There is also an example which works with splines.