-
Notifications
You must be signed in to change notification settings - Fork 199
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
Tests are brittle. Use the concept of in_delta #565
Comments
Most places we try to use the (as a side note, I think most of the time we actually want a "relatively equals" check vs a "within an epsilon" check, but that's somewhat pedantic.) I haven't looked to see if it's possible - but I personally think it'd be ideal to be able to say something like:
Maybe we can implement the approx traits for geo? e.g. https://docs.rs/approx/0.4.0/approx/trait.RelativeEq.html edited: clarity |
Thank you for shaping my thinking, the comments above were really useful -- and save a lots of time for me. I have the start of solution pushed into a branch in my area -- so not ready for a PR yet. But I am far enough alone to know that I need to discuss a major breaking change. First a minor comment 'relative equal' is for dissimilar type like i32 and f64. What we need is AbsDiffEq - the approximate equality check for identical types. For Point the solution looks like
here is a fragment of the doc test in my branch
I need to signal a major breaking change for all the other geometry types Line, LineString, Polygon etc There is a security issue we need to be aware of .. Any implementation of a trait need to be for security in cannot be defined in a third module C) as you can see from my version of Line - below what this mean is that I need a breaking change that is to move the coords_iter() trait from the geo module into the geo-types module - to meet that security concern and so I do a zip which will be used to compare an object point by poiint
|
My understanding is that "relative equality" aims to solve the repeated problem of "Which epsilon should I choose?".
I really enjoyed this https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ which I think uses the same terminology. Here's the relevant excerpt:
so tldr; the epsilon is chosen relative to the size of the values you're comparing.
Hmm... that might be possible. But how heinous would it be to instead implement the equality traits without using Also, I wonder if it's worth putting the approx-equality |
I have found a less "bull in a china shop approach" .. which will eventually look like succinct library grade code.. This is the point where I shut up and implement it. |
Thanks for correcting me and providing a common set of definitions.. That really help michaelkirk++ I am about to upload and submit a PR. This is more inline with library grade code. In short I started over. To balance effort with usefulness I have only implemented 'relative_eq' for a few of the 10 geometry types. In terms of review .. I mostly copied the algorithm for Points::relative_eq() from approx's default reference implementation. I used the euclidean distance .. but I considered using the simpler Manhattan distance. An overview of the PR
|
Ok here is the PR |
Done in #567, using approx and relative_eq |
When I say brittle ... I mean for example
look at
the 0.9999999999999999 is a hard coded rounding artifact -- the expected value is 1.0.
numerically two numbers x0 and x1 are considered equal if
(x0 - x1).abs() < T::EPSILON
I am coming from a related d3 "geo-spatial" library and they have a in_delta concept.
d3-geo the in_delta() function
In short a test helper function which compares objects on a point by point basis and asserts that two objects are identical if every thing is "in delta"
Anyway I am going to work on this.
The text was updated successfully, but these errors were encountered: