-
Notifications
You must be signed in to change notification settings - Fork 12.6k
optimized approxEquals in GeoObject.java #949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
damn it
|
Best pull request so far. Appreciate the effort. |
|
LGTM |
|
genius |
|
Impossible; an actual PR? On this repo? |
|
Groundbreaking. This could be the missing link. |
|
LGTM |
1 similar comment
|
LGTM |
|
better-algorithm |
|
Groundbreaking |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| } | ||
|
|
||
| return true; | ||
| return a.source == b.source; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can reduce the verbosity further.
if (a == null && b == null) {
return true;
}
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 &&
Double.compare(a.radius, b.radius) == 0 &&
a.source == b.source;
I feel like this is more readable because now we exactly know all the conditions needed for non-null values of a and b to be equal in one concise statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that just the last if/return should be reduced, because its the last one. I dont know. I think that the others are kinda "ok" to be like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, it's definitely more maintainable.
|
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 |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the quick turnaround!
Exactly! |
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.