I am working on a project where I want to draw a line around some SVG elements in order to make a selection of the objects inside the area.
Here is a screenshot of what I have right now. I have used Paint to add the line in order to make it perfectly clear what I am trying to achieve. I want to select the two rect
inside the drawn circle.
I see a number of steps that has to be solved:
path
element at mousedown
and record the mouse movements until mouseup
path
, in case the user didn't draw a circleWhich approaches do you see, and do you have any recommendations on how to go about it?
I am using D3.js. This slide (by Mike Bostock, the creator of D3) might be interesting to take a look at.
I would go the following steps:
Depending if you test all vertices to lie inside the convex hull you can determine if the element lies fully inside the freehand drawing or just overlaps it.
Unfortunately I am not that familiar with d3.js, but just guess that it provides methods to gain convex hulls, aabbs and test points to be inside a polygon. Probably it even provides you with the ability to make aabb queries to find overlapping aabb in step 2.
good luck...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With