-
Notifications
You must be signed in to change notification settings - Fork 205
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
multipolygon rotate pivot #651
multipolygon rotate pivot #651
Conversation
geo/src/algorithm/rotate.rs
Outdated
] | ||
].into(); | ||
|
||
assert_relative_eq!(multipolygon.rotate(-90.), expected, max_relative=1.0); |
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'm curious, does this still pass if you delete the max_relative=1.0
?
My understanding of max_relative=1.0
is that you're allowing up to 100% error, which seems unnecessarily large.
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.
Removing the max_relative
does indeed fail:
running 1 test
thread 'algorithm::rotate::test::test_rotate_multipolygon_around_centroid' panicked at 'assert_relative_eq!(multipolygon.rotate(-90.), expected, max_relative = 0.1)
left = MultiPolygon([Polygon { exterior: LineString([Coordinate { x: 0.0, y: 0.0 }, Coordinate { x: 0.0000000000000006123233995736766, y: -10.0 }, Coordinate { x: 10.0, y: -10.0 }, Coordinate { x: 10.0, y: 0.0000000000000006123233995736766 }, Coordinate { x: 0.0, y: 0.0 }]), interiors: [] }, Polygon { exterior: LineString([Coordinate { x: 0.0, y: 0.0 }, Coordinate { x: -0.0000000000000006123233995736766, y: 10.0 }, Coordinate { x: -10.0, y: 10.0 }, Coordinate { x: -10.0, y: -0.0000000000000006123233995736766 }, Coordinate { x: 0.0, y: 0.0 }]), interiors: [] }])
right = MultiPolygon([Polygon { exterior: LineString([Coordinate { x: 0.0, y: 0.0 }, Coordinate { x: 10.0, y: 0.0 }, Coordinate { x: 10.0, y: -10.0 }, Coordinate { x: 0.0, y: -10.0 }, Coordinate { x: 0.0, y: 0.0 }]), interiors: [] }, Polygon { exterior: LineString([Coordinate { x: 0.0, y: 0.0 }, Coordinate { x: -10.0, y: 0.0 }, Coordinate { x: -10.0, y: 10.0 }, Coordinate { x: 0.0, y: 10.0 }, Coordinate { x: 0.0, y: 0.0 }]), interiors: [] }])
My knowledge of floating point comparison is sketchy enough to where I'm not sure what tuning param is appropriate. It's possible I've just missed something stupid tho, so I'll look more tomorrow (maybe the polygons aren't right for what I'm trying to verify).
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.
Ignoring the small errors for now (which indeed might be some floating point rounding), a quick glance shows the coords seem to be way off.
e.g. look at the second coord of the first poly:
left.0[0].exterior[1]: Coordinate { x: 0.0000000000000006123233995736766, y: -10.0 }
right.0[0].exterior[1]: Coordinate { x: 10.0, y: 0.0 }
One thing that could be going on... be aware that the equals check is not a topology check — to be eq
, the MultiPolygons can't just have the same shape, but also their member Polygons must be in the same order, and each members coords must be in the same order.
Maybe something going on there?
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.
Thanks for the pointers. I tried to short cut my way to a rotation I thought I could do by hand but I either botched the expected or missed something subtle. I think I'll create a real example and then run it through geos to get the expected values.
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.
Thanks for the PR!
It mostly looks good, but I had some minor nits / questions.
Okay, I've use shapely as an oracle for a multipolygon rotation. I still relaxed the epsilon a tad in the I've also added a test to ensure an un-centroid-able multipolygon returns itself. should we do the same for let empty_polygon: Polygon<f64> = polygon![];
let rotated_empty_polygon = empty_polygon.rotate(90.); |
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.
bors r+
651: multipolygon rotate pivot r=michaelkirk a=mapoulos - [x] I agree to follow the project's [code of conduct](https://github.com/georust/geo/blob/master/CODE_OF_CONDUCT.md). - [x] I added an entry to `CHANGES.md` if knowledge of this change could be valuable to users. --- Co-authored-by: Alex Poulos <alex@equul.us>
That sounds undesirable, but it seems like that's existing behavior, unaffected by this PR, so I'm fine with merging this as is. I've added #652 to track the bug you uncovered. Feel free to work on it =) |
Build failed: |
Shoot, at first glance it looks like some failure in our testing code, unrelated to your change. Unfortunately I don't have more time to dig into this right now. |
Ok, I took a quick peak actually. It looks like I can take a look at revving CI sometime in the next few days. |
@michaelkirk I should have some time over the weekend. Will ping you if I get to it. |
I more or less assume there's nothing that I can or should do to fix the CI, but if I can help with something let me know. |
I'm loooking at CI now. It takes a while to build everything, but is pretty low effort provided everything "Just works"... I'll keep you updated. |
@mapoulos - I've fixed CI. Would you mind rebasing or merging in master and we can give it another go? |
@michaelkirk done! |
bors try |
tryBuild succeeded: |
Thanks @mapoulos! |
CHANGES.md
if knowledge of this change could be valuable to users.