I just mentioned JTS in a tweet myself
(https://twitter.com/MichaelPaus/status/1351133904409915395)
but I think it would be a mistake to integrate that into JavaFX for
various reasons. The main problem is
that Java never provided and used a graphics system independent geometry
and math library. That's why
I like JTS because it is not tied to any specific graphics system and
therefore it is much easier for me to
get my code running on different graphics systems. The latest being
Jetbrains Compose and Skija.
Michael
Am 18.01.21 um 12:57 schrieb Kay, Jim:
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-r...@openjdk.java.net> On Behalf Of Nir Lisker
Sent: 18 January 2021 11:42
To: Dirk Lemmermann <dlemmerm...@gmail.com>
Cc: OpenJFX <openjfx-dev@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 <dlemmerm...@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