Re: RFE: Shape Intersection

2021-01-18 Thread Almas Baimagambetov
If I'm not mistaken, the original proposal was only for API, rather a
change in implementation.

On Mon, 18 Jan 2021, 12:47 pm Tom Eugelink,  wrote:

> I'm curious about the reasons, because reinventing the wheel does not seem
> to be smart as well...
>
>
> On 18-1-2021 13:10, Michael Paus wrote:
> > 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  On Behalf Of Nir
> Lisker
> >> Sent: 18 January 2021 11:42
> >> To: Dirk Lemmermann 
> >> Cc: OpenJFX 
> >> 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  >
> >> 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
> >>> =DwIFaQ=ukT25UmkSFgENae3bmQPWw=4CcGGNkvpQC43k2S_CRiSDUcCYYGpfGF1
> >>> AetrfAv2Mw=p3Mxo9ouTmwb0rTqUVuKSgB0UwSHVVoF-Q9F0D_Kr_Y=DRGfselPcMM
> >>> lUyRnLx7wTx4S243tMuSxGIBFhqNKKy8=
> >>> <
> >>> https://urldefense.proofpoint.com/v2/url?u=https-3A__stackoverflow.com
> >>> _questions_15013913_checking-2Dcollision-2Dof-2Dshapes-2Dwith-2Djavafx
> >>> =DwIFaQ=ukT25UmkSFgENae3bmQPWw=4CcGGNkvpQC43k2S_CRiSDUcCYYGpfGF1
> >>> AetrfAv2Mw=p3Mxo9ouTmwb0rTqUVuKSgB0UwSHVVoF-Q9F0D_Kr_Y=DRGfselPcMM
> >>> lUyRnLx7wTx4S243tMuSxGIBFhqNKKy8=
> >>> Dirk
> >>>
> >>>
> >>>
> >
>
>


Re: RFE: Shape Intersection

2021-01-18 Thread Tom Eugelink

I'm curious about the reasons, because reinventing the wheel does not seem to 
be smart as well...


On 18-1-2021 13:10, Michael Paus wrote:

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  On Behalf Of Nir Lisker
Sent: 18 January 2021 11:42
To: Dirk Lemmermann 
Cc: OpenJFX 
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 
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
=DwIFaQ=ukT25UmkSFgENae3bmQPWw=4CcGGNkvpQC43k2S_CRiSDUcCYYGpfGF1
AetrfAv2Mw=p3Mxo9ouTmwb0rTqUVuKSgB0UwSHVVoF-Q9F0D_Kr_Y=DRGfselPcMM
lUyRnLx7wTx4S243tMuSxGIBFhqNKKy8=
<
https://urldefense.proofpoint.com/v2/url?u=https-3A__stackoverflow.com
_questions_15013913_checking-2Dcollision-2Dof-2Dshapes-2Dwith-2Djavafx
=DwIFaQ=ukT25UmkSFgENae3bmQPWw=4CcGGNkvpQC43k2S_CRiSDUcCYYGpfGF1
AetrfAv2Mw=p3Mxo9ouTmwb0rTqUVuKSgB0UwSHVVoF-Q9F0D_Kr_Y=DRGfselPcMM
lUyRnLx7wTx4S243tMuSxGIBFhqNKKy8=
Dirk









RE: RFE: Shape Intersection

2021-01-18 Thread Kay, Jim
Michael
I think I agree, I would not like to see JavaFX incorporated into JTS, for the 
reasons you mention.
But I would like to see JTS, or at least the structure and logic incorporated 
into JavaFX. This would then give the JavaFX world a useful set of tools that 
would greatly extend its rather limited existing functionality.
Jim

-Original Message-
From: openjfx-dev  On Behalf Of Michael Paus
Sent: 18 January 2021 12:11
To: openjfx-dev@openjdk.java.net
Subject: Re: RFE: Shape Intersection

I just mentioned JTS in a tweet myself
(https://urldefense.proofpoint.com/v2/url?u=https-3A__twitter.com_MichaelPaus_status_1351133904409915395=DwIDaQ=ukT25UmkSFgENae3bmQPWw=4CcGGNkvpQC43k2S_CRiSDUcCYYGpfGF1AetrfAv2Mw=biryV2m8HpSXo8rw1EUe0QmCrmnlN1upcYHdN8w-DpM=2wIFL0e2ON6mlE3HXVcSvuook7ipK-x_O62Br__7FxM=
 ) 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://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_locationtech_jts=DwIDaQ=ukT25UmkSFgENae3bmQPWw=4CcGGNkvpQC43k2S_CRiSDUcCYYGpfGF1AetrfAv2Mw=biryV2m8HpSXo8rw1EUe0QmCrmnlN1upcYHdN8w-DpM=nvXIMl8MC1jFYb7rGgQYyrRZ5r7Y00q-1F2s51hGZR0=
>  ) 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  On Behalf Of Nir 
> Lisker
> Sent: 18 January 2021 11:42
> To: Dirk Lemmermann 
> Cc: OpenJFX 
> 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 
> 
> 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.co
>> m 
>> _questions_15013913_checking-2Dcollision-2Dof-2Dshapes-2Dwith-2Djavaf
>> x
>> =DwIFaQ=ukT25UmkSFgENae3bmQPWw=4CcGGNkvpQC43k2S_CRiSDUcCYYGpfGF
>> 1 
>> AetrfAv2Mw=p3Mxo9ouTmwb0rTqUVuKSgB0UwSHVVoF-Q9F0D_Kr_Y=DRGfselPcM
>> M
>> lUyRnLx7wTx4S243tMuSxGIBFhqNKKy8=
>> <
>> https://urldefense.proofpoint.com/v2/url?u=https-3A__stackoverflow.co
>> m 
>> _questions_15013913_checking-2Dcollision-2Dof-2Dshapes-2Dwith-2Djavaf
>> x
>> =DwIFaQ=ukT25UmkSFgENae3bmQPWw=4CcGGNkvpQC43k2S_CRiSDUcCYYGpfGF
>> 1 
>> AetrfAv2Mw=p3Mxo9ouTmwb0rTqUVuKSgB0UwSHVVoF-Q9F0D_Kr_Y=DRGfselPcM
>> M
>> lUyRnLx7wTx4S243tMuSxGIBFhqNKKy8=
>> Dirk
>>
>>
>>



Re: RFE: Shape Intersection

2021-01-18 Thread Michael Paus
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  On Behalf Of Nir Lisker
Sent: 18 January 2021 11:42
To: Dirk Lemmermann 
Cc: OpenJFX 
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 
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
=DwIFaQ=ukT25UmkSFgENae3bmQPWw=4CcGGNkvpQC43k2S_CRiSDUcCYYGpfGF1
AetrfAv2Mw=p3Mxo9ouTmwb0rTqUVuKSgB0UwSHVVoF-Q9F0D_Kr_Y=DRGfselPcMM
lUyRnLx7wTx4S243tMuSxGIBFhqNKKy8=
<
https://urldefense.proofpoint.com/v2/url?u=https-3A__stackoverflow.com
_questions_15013913_checking-2Dcollision-2Dof-2Dshapes-2Dwith-2Djavafx
=DwIFaQ=ukT25UmkSFgENae3bmQPWw=4CcGGNkvpQC43k2S_CRiSDUcCYYGpfGF1
AetrfAv2Mw=p3Mxo9ouTmwb0rTqUVuKSgB0UwSHVVoF-Q9F0D_Kr_Y=DRGfselPcMM
lUyRnLx7wTx4S243tMuSxGIBFhqNKKy8=
Dirk







Re: RFE: Shape Intersection

2021-01-18 Thread Almas Baimagambetov
If we are adding non-static methods, then the whole "bundle" should
probably be included for consistency. E.g. union, subtract, etc.

On Mon, 18 Jan 2021, 11:43 am Nir Lisker,  wrote:

> 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 
> 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://stackoverflow.com/questions/15013913/checking-collision-of-shapes-with-javafx
> > <
> >
> https://stackoverflow.com/questions/15013913/checking-collision-of-shapes-with-javafx
> > >
> >
> > Dirk
> >
> >
> >
>


RE: RFE: Shape Intersection

2021-01-18 Thread 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  On Behalf Of Nir Lisker
Sent: 18 January 2021 11:42
To: Dirk Lemmermann 
Cc: OpenJFX 
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 
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
> =DwIFaQ=ukT25UmkSFgENae3bmQPWw=4CcGGNkvpQC43k2S_CRiSDUcCYYGpfGF1
> AetrfAv2Mw=p3Mxo9ouTmwb0rTqUVuKSgB0UwSHVVoF-Q9F0D_Kr_Y=DRGfselPcMM
> lUyRnLx7wTx4S243tMuSxGIBFhqNKKy8=
> <
> https://urldefense.proofpoint.com/v2/url?u=https-3A__stackoverflow.com
> _questions_15013913_checking-2Dcollision-2Dof-2Dshapes-2Dwith-2Djavafx
> =DwIFaQ=ukT25UmkSFgENae3bmQPWw=4CcGGNkvpQC43k2S_CRiSDUcCYYGpfGF1
> AetrfAv2Mw=p3Mxo9ouTmwb0rTqUVuKSgB0UwSHVVoF-Q9F0D_Kr_Y=DRGfselPcMM
> lUyRnLx7wTx4S243tMuSxGIBFhqNKKy8=
> >
>
> Dirk
>
>
>


Re: RFE: Shape Intersection

2021-01-18 Thread Nir Lisker
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 
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://stackoverflow.com/questions/15013913/checking-collision-of-shapes-with-javafx
> <
> https://stackoverflow.com/questions/15013913/checking-collision-of-shapes-with-javafx
> >
>
> Dirk
>
>
>


RFE: Shape Intersection

2021-01-18 Thread Dirk Lemmermann
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://stackoverflow.com/questions/15013913/checking-collision-of-shapes-with-javafx
 


Dirk