Closed marcospassos closed 6 years ago
This is implemented in some of the intersection routines. However, my current thinking is to pull this functionality out into a separate IntersectionQuery class. The current intersection code could be streamlined a bit (and made a little faster as a result) if I remove this kind of logic. Likewise, these types of queries often involve simpler math than calculating intersections.
Out of curiosity, do you need this for any shapes in particular?
For now, we're using a suboptimal solution that involves creating a line with as a point Shapes.line(x-0.5, y-0.5, x, y)
(once 0.5 is less than one pixel, no collateral effects here). However, a more robust solution would be very appreciated :).
Out of curiosity, are you looking for this to supported for any shapes in particular?
As the shape is configurable, we're not looking for a form in particular.
However, my current thinking is to pull this functionality out into a separate IntersectionQuery class.
Please, let me know if decide to pull out such feature.
Are you looking for something like this? Please note that these have not been tested in any way, but it should give you an idea of what I'm thinking.
Yeah, but I would like to suggest an API more close to the Intersection
:
const shape = Shapes.circle(10, 10, 50);
const point = new Point2D(10, 20);
IntersectionQuery.containsPoint(shape, point);
What do you think?
Agreed, something like that would be nicer. My thinking is that I would approach this like Intersection
where you could call the low-level API directly (which is what I'm using in my example) and then there would be a convenience method that figures out what method to invoke for you. The low-level methods use kld-affine types and Numbers only. The convenience function would use types like you're showing in your example: i.e., IntersectionArgs
.
Perfect! It definitely gets the job done. Looking forward to testing it on our app.
Btw, as this new class is completely isolated, it looks like a good point to start with unit tests :)
@thelonious, any plans to release the InteserctionQuery
?
I started a new full-time job this month which has limited my time considerably. Is it useful to you in its current form? There's not much there.
It would be very useful to me, even in it's current form. I'm mainly looking for the pointInPolygon
functionality. Would it be possible to release the current IntersectionQuery
stuff?
Thanks @Grepsy. I went ahead and pushed v0.4.0. I incremented the minor revision since this is an API change, but really all this does is expose IntersectionQuery
. I've also added the start of a new section on that class in the README
Great, thanks a lot!
It would be nice to have a method that checks if a 2DPoint is inside or outside the boundaries of a given shape.