the-algorithm icon indicating copy to clipboard operation
the-algorithm copied to clipboard

optimized approxEquals in GeoObject.java

Open ttomczak3 opened this issue 2 years ago • 14 comments

To make the code more concise and efficient, we can simplify the conditional expressions and combine multiple conditions into a single return statement using short-circuit evaluation.

ttomczak3 avatar Apr 01 '23 17:04 ttomczak3

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Apr 01 '23 17:04 CLAassistant

Best pull request so far. Appreciate the effort.

RickHPotter avatar Apr 01 '23 17:04 RickHPotter

LGTM

hungtruong avatar Apr 01 '23 17:04 hungtruong

genius

Quinn-Barber avatar Apr 01 '23 18:04 Quinn-Barber

Impossible; an actual PR?

On this repo?

preland avatar Apr 01 '23 18:04 preland

Groundbreaking. This could be the missing link.

0o120 avatar Apr 01 '23 18:04 0o120

LGTM

Claaas avatar Apr 01 '23 19:04 Claaas

LGTM

Conradyen avatar Apr 01 '23 21:04 Conradyen

better-algorithm

peiwenxu avatar Apr 02 '23 01:04 peiwenxu

Groundbreaking

hexaquarks avatar Apr 02 '23 13:04 hexaquarks

Feature is a little too big for the scope of this project; perhaps create a fork?

numberisnan avatar Apr 02 '23 21:04 numberisnan

this would be the least lines and most maintainable.

return a!=null&&b!=null&&a.accuracy==b.accuracy&&Math.abs(a.latitude-b.latitude)<=COORDS_EQUALITY_THRESHOLD&&Math.abs(a.longitude-b.longitude)<=COORDS_EQUALITY_THRESHOLD&&a.radius==b.radius&&a.source==b.source;

davidawad avatar Apr 05 '23 21:04 davidawad

this would be the least lines and most maintainable.

return a!=null&&b!=null&&a.accuracy==b.accuracy&&Math.abs(a.latitude-b.latitude)<=COORDS_EQUALITY_THRESHOLD&&Math.abs(a.longitude-b.longitude)<=COORDS_EQUALITY_THRESHOLD&&a.radius==b.radius&&a.source==b.source;

I noticed that the Double.compare() method was removed. Can you explain the reason for this? It seems to be a more accurate way to compare two double values.

ttomczak3 avatar Apr 05 '23 22:04 ttomczak3

this would be the least lines and most maintainable.

return a!=null&&b!=null&&a.accuracy==b.accuracy&&Math.abs(a.latitude-b.latitude)<=COORDS_EQUALITY_THRESHOLD&&Math.abs(a.longitude-b.longitude)<=COORDS_EQUALITY_THRESHOLD&&a.radius==b.radius&&a.source==b.source;

I noticed that the Double.compare() method was removed. Can you explain the reason for this? It seems to be a more accurate way to compare two double values.

I would stick with the compare() method. Double values can have rounding inaccuracies due to their representation in the computer's limited memory space of (usually) 64 bits.

https://www.baeldung.com/java-comparing-doubles

shailrshah avatar Apr 06 '23 00:04 shailrshah

this would be the least lines and most maintainable.

return a!=null&&b!=null&&a.accuracy==b.accuracy&&Math.abs(a.latitude-b.latitude)<=COORDS_EQUALITY_THRESHOLD&&Math.abs(a.longitude-b.longitude)<=COORDS_EQUALITY_THRESHOLD&&a.radius==b.radius&&a.source==b.source;

I noticed that the Double.compare() method was removed. Can you explain the reason for this? It seems to be a more accurate way to compare two double values.

I would stick with the compare() method. Double values can have rounding inaccuracies due to their representation in the computer's limited memory space of (usually) 64 bits.

https://www.baeldung.com/java-comparing-doubles

Exactly!

ttomczak3 avatar Apr 06 '23 02:04 ttomczak3