I have two intersecting paths in a xy plane see image.
A path is defined by a set of points in order so that every two consecutive points form an edge of path. Paths are always closed. Points are flagged to indicated that whether they from edges or curve.
I am trying to write a function to get three paths as following.
I tried the following.
create temp path Object path_C
go through every edge in path_A
go through every edge in path_B
if current edge of path_A intersects edge of path_B
find the intersection
store the intersection point in path_C
inner loop ends here
outer loop ends here
go through every point in path_A
if a point lies within the path_B
add it to the path_C
and remove it from path_A
end of loop
go through every point in path_B
if a point lies within the path_A
add it to the path_C
and remove it from path_B
end the loop
before I could run it one of my friend pointed out that there is no guarantee that path_C has got the points in correct order. Now I can't figure out how can I fix this problem. If you can suggest some optimizations that will be even better.
Side note : I am actually trying to implement the divide feature in adobe illustrator's pathfinder panel.