Closed dennemark closed 6 months ago
I am not sure if it is worth implementing this approach within pointInside component. Maybe it can be a separate classifyPolygon function. Since the only reasonable way to get on polygon
functionality, is by really checking, if a point is on each line of polygon, therefore creating additional checks within classifyPointPolyPair
.
The checks for pt within y range within classifyPointPolyPair vary just slightly ay <= py and by <= py
vs ay < py and by < py
. The latter is necessary for inside check, the former for on line check.
While this decreases performance for point inside checking, it might actually be bit faster, if point is on polygon, since we can just skip iterating over follow up lines of a polygon.
I have it in my code base now... Not sure what you prefer @postspectacular
@dennemark - Looks good & I'm thinking about this, but will have to refamiliarize with the details of that code first (in a different head space right now...)
@postspectacular I stumbled over this one again. Used my above code in our repository, but nearly deleted it for the actualy thi.ng/geom function. Though I prefer the -1, 0, 1 check.
If there is some space, would you be able to look into this?
@dennemark I'm hoping to revisit this once more this week, since I've been working on another set of various major changes to the geom package, mainly related to better return types (#467), but also been adding various new shape types (incl. 3D) and updating type support for many operators....
very nice! thanks a lot :) curious about the progress on types and 3d....
Hi @dennemark — so this should all be done now (updated your version to allow for specifying tolerance). Also included a new example to test & verify visually:
Demo: https://demo.thi.ng/umbrella/geom-classify-point/
Source: https://github.com/thi-ng/umbrella/blob/develop/examples/geom-classify-point/src/index.ts
I am wondering, if it is possible to extend the pointInside function and add a possibility to know if point is on polygon. Since classifyPoint works with -1, 0 and 1 instead of boolean like pointInside, I think it would be possible to integrate the following functions inside classifyPoint and keep pointInside as is. The algorithm looses a bit of efficiency though.
https://github.com/thi-ng/umbrella/blob/65dc2a5c6496854cfcd60b60682b407d06e058bc/packages/geom/src/classify-point.ts#L40
https://github.com/thi-ng/umbrella/blob/d48377c39a333d3e9c40ec816b81db1879ab534b/packages/geom-isec/src/point.ts#L184
Tested for these cases, feel free to test more.