Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG Paths detect overlapping or enclosed shapes

Tags:

svg

I have brown filled svg paths and i want to detect and alert my user if there is any shape behind or above another shape. I know intersection list gets if they intersect at the edges but what happens if i want to detect a shape that is behind another shape but doesnt intersect at the edges?

The encoluseList method seems to be dealing with bounding boxes and not this.

Any ideas?

like image 371
user2252997 Avatar asked Apr 08 '13 08:04

user2252997


1 Answers

To detect if a path/shape overlaps another
1. Calculating the area covered by the final shape achieved
2. Calculating the sum of areas of all the shapes independently(since this is SVG and the details of each path element is known, this can be done)
3. Comparing the 2 areas.If the 2 areas are the same, then there is no overlapping otherwise at least 2 shapes overlap.

The tricky step is step 1 which can be approximately calculated using pixel painting algorithm(my preference). For other methods, you can go through the following stackoverflow question concerning area of overlapping circles

like image 87
user2409836 Avatar answered Oct 01 '22 02:10

user2409836