-
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
add minimum bounding box func of polygon #959
Conversation
Thanks for the excellent contribution @hzw456 . A couple of suggestions: The bounding box in the name is ambiguous as it typically used for axis aligned ones. Shapely calls this functionality as "minimum_rotated_rectangle". Since the approach uses convex hull, would it generalize to all geoms that support conv hull? |
/// Returns the minimun bounding rect of polygon. | ||
/// | ||
|
||
pub trait MinimunRotatedRect<'a, T> { |
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.
It looks like T
is unused in the definition. Remove?
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 found ConvexHull
function has same usage for T
,not sure about its real meaning.
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.
if i delete T
,it will have lifetime error
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.
Oh lol, let me create a separate issue to track removing it there. Let's leave this as-is for now.
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.
any process with this?
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've added a few minor code suggestions, but otherwise lgtm!
To summarize for other reviewers: this PR adds support for the minimum_rotated_rect
algorithm for all our geometry types. This is the smallest area rectangle that contains the given geometry. The algorithm involves two steps:
- compute convex hull of geom: since rectangle is convex, any covering rect. should cover the convex hull of the geom.
- for any convex shape, it is known that the min rectangle overlaps with some side of the polygon (citation needed). This implementation iterates over all sides and computes the min. area rectangle. The current implementation constructs rotated polygons, to compute the bounding rect thus giving a quadratic total run-time for this step. This may be optimized in the future via the rotating calipers technique.
@urschrei @frewsxcv @michaelkirk Any one else have time for a quick skim? We could merge it in a week if all looks good.
Looks like all reviewer suggestions/comments have been addressed. Will merge it in a day. |
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.
Please add an entry for this new algorithm in our top level docs: https://docs.rs/geo/latest/geo/#boundary
edit: fixed link🤦
@hzw456 One more thing– can you add this to |
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 so much!
bors r+ |
Build succeeded: |
CHANGES.md
if knowledge of this change could be valuable to users.add minimun bounding box of polygon(mbr)