Skip to content
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

Merged
merged 13 commits into from
Feb 25, 2023
Merged

add minimum bounding box func of polygon #959

merged 13 commits into from
Feb 25, 2023

Conversation

hzw456
Copy link
Contributor

@hzw456 hzw456 commented Jan 3, 2023

  • I agree to follow the project's code of conduct.
  • I added an entry to CHANGES.md if knowledge of this change could be valuable to users.

add minimun bounding box of polygon(mbr)

@rmanoka
Copy link
Contributor

rmanoka commented Jan 3, 2023

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> {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any process with this?

Copy link
Contributor

@rmanoka rmanoka left a 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:

  1. compute convex hull of geom: since rectangle is convex, any covering rect. should cover the convex hull of the geom.
  2. 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.

@rmanoka
Copy link
Contributor

rmanoka commented Jan 17, 2023

Looks like all reviewer suggestions/comments have been addressed. Will merge it in a day.

Copy link
Member

@michaelkirk michaelkirk left a 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🤦

@frewsxcv
Copy link
Member

@hzw456 One more thing– can you add this to CHANGES.md?

Copy link
Member

@frewsxcv frewsxcv left a 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!

@frewsxcv
Copy link
Member

bors r+

@bors
Copy link
Contributor

bors bot commented Feb 25, 2023

Build succeeded:

@bors bors bot merged commit 9779c90 into georust:main Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants