RFE: Shape Intersection
Kay, Jim
Jim.Kay at snclavalin.com
Mon Jan 18 11:57:34 UTC 2021
I have used the JTS library (https://github.com/locationtech/jts) a lot over the years; this is my 'go to' library for all 2D geometry routines. It is very extensive and very well written by it’s main author Martin Davis. This library has entities such as Geometry, LineString, Polygon etc and shows how to do all geometric operations such as: intersect, intersection, difference, union, touches, overlaps etc.
It would be great to incorporate this type of library into JavaFX. I know it would require a bit of a rewrite but I think it would be worth it!
Jim Kay
-----Original Message-----
From: openjfx-dev <openjfx-dev-retn at openjdk.java.net> On Behalf Of Nir Lisker
Sent: 18 January 2021 11:42
To: Dirk Lemmermann <dlemmermann at gmail.com>
Cc: OpenJFX <openjfx-dev at openjdk.java.net>
Subject: Re: RFE: Shape Intersection
If this is to be implemented in JavaFX, then it's better to do (not tested):
1. Extract the intersection computation from Shape.intersect
private static Area intersectionArea(Shape shape1, Shape shape2) {
Area result = shape1.getTransformedArea();
return result.intersect(shape2.getTransformedArea());
}
2. Shape.intersect becomes
public static Shape Shape.intersects(Shape shape1, Shape shape2) {
var intersectionArea = intersectionArea(Shape shape1, Shape shape2);
return createFromGeomShape(intersectionArea);
}
3. Add the new method Shape.intersects
public static boolean Shape.intersects( Shape shape1, Shape shape2) {
var intersectionArea = intersectionArea(Shape shape1, Shape shape2);
return !intersectionArea.isEmpty();
}
Regardless, I wonder why the geometry methods were implemented as static methods. Why not shape1.intersect(shape2)? I assume the new method should follow these, but on a clean slate I think I would have used the non-static approach.
Another thing I would think about is whether it makes sense to just one method or is it a part of a more comprehensive shape geometry bundle. Is "intersects?" the only question we would like to ask?
- Nir
On Mon, Jan 18, 2021 at 12:12 PM Dirk Lemmermann <dlemmermann at gmail.com>
wrote:
> I just noticed that there is no „intuitive“ API to check whether two
> shapes intersect with each other. The only way (I think) to do it is
> as
> follows:
>
> Shape.intersect((Shape) child, circle).getBoundsInLocal().getWidth()
> != -1
>
> If this is indeed the case I would like to propose that a method shall
> be added called „boolean Shape.intersects(Shape,Shape").
>
> See also:
> https://urldefense.proofpoint.com/v2/url?u=https-3A__stackoverflow.com
> _questions_15013913_checking-2Dcollision-2Dof-2Dshapes-2Dwith-2Djavafx
> &d=DwIFaQ&c=ukT25UmkSFgENae3bmQPWw&r=4CcGGNkvpQC43k2S_CRiSDUcCYYGpfGF1
> AetrfAv2Mw&m=p3Mxo9ouTmwb0rTqUVuKSgB0UwSHVVoF-Q9F0D_Kr_Y&s=DRGfselPcMM
> lUyRnLx7wTx4S243tMuSxGIBFhqNKKy8&e=
> <
> https://urldefense.proofpoint.com/v2/url?u=https-3A__stackoverflow.com
> _questions_15013913_checking-2Dcollision-2Dof-2Dshapes-2Dwith-2Djavafx
> &d=DwIFaQ&c=ukT25UmkSFgENae3bmQPWw&r=4CcGGNkvpQC43k2S_CRiSDUcCYYGpfGF1
> AetrfAv2Mw&m=p3Mxo9ouTmwb0rTqUVuKSgB0UwSHVVoF-Q9F0D_Kr_Y&s=DRGfselPcMM
> lUyRnLx7wTx4S243tMuSxGIBFhqNKKy8&e=
> >
>
> Dirk
>
>
>
More information about the openjfx-dev
mailing list