Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Long long ago, #686 started taking advantage of the fact that all the numeric quantities in
geom
are rounded to a few decimal places, by serializing smaller integers instead of fullf64s
. But that PR had a bug, one which @michaelkirk pointed out. This PR improves the unit tests to catch this problem, then fixes it.The problem is this:
Pt2D::new
, we trim the floats to 4 decimal places.This has extremely scary implications -- #689 hit one in the traffic simulation that I never bothered to dig into. But there are so many more, mentioned in a-b-street/geom#1. When we construct a
PolyLine
most of the time, we guarantee that no adjacent points are equal (up to the epsilon implied by this rounding behavior). That means later we can get individualLine
segments that have nonzero distance. The problem is, this guarantee held when we originally constructed the geometry, but sometimes after deserializing, we lost that guarantee, because the points changed very slightly. This has caused so much havoc.An example of the problem in the unit test, before the fix:
196157.1725
in-memory gets turned into196157.1724
.Next steps
If this fix is truly correct, it has very far-reaching implications. For example,
abstreet/map_model/src/map.rs
Line 884 in aeb14c7
More short-term, I want to simplify a few things within
geom
. We have a customPartialEq
implementation forPt2D
here. I don't think this should be necessary, I'm going to just derive it. I also want to consider removingHashablePt2D
and just makingPt2D
internally useordered_float
, but that's less urgent. (And there's some current bug here where we violate thehash(x) == hash(y) implies x == y
invariant; I need to dig into this...)CC @BudgieInWA