-
Notifications
You must be signed in to change notification settings - Fork 200
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 type Bbox and trait BoundingBox #41
Merged
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
7c65977
Implement BoundingBox for LineString
0337873
Implement BoundingBox for Polygon
eccc0c9
Substitute &LineString<T> with &Vec<Point<T>> in get_bbox function
b65d3c0
Implement BoundingBox for MultiPoint
74a316d
Cleanup test syntax when creating new instances
49b6172
Implement the Add trait to Bbox
ce28cca
Implement AddAssign trait for Bbox struct
2134a69
Implement BoundingBox for MultiLineString and cleanup tests
de27c9e
Implement BoundingBox for MultiPolygon
ac69af5
Implement Centroid for Bbox
12ef2a5
Implement Area for Bbox
3ecca84
Implement trait Contains for Bbox
6556567
Implement Intersects trait for Bbox
8fdb5c9
Merge branch 'generics' into bbox
8e348a3
Merge branch 'master' into bbox
ab61011
Cleanup the get_bbox function to remove some duplicate code
c213d43
Update the get_bbox function removing the else block
5bae671
Substitute println! with assert_eq! in trait documentation
9bec1b8
Rewrite get_bbox function to accept as input an IntoIterator instead …
6f16131
Remove duplicate code in MultiLineString and MultiPolygon, credits to…
03293f5
Merge branch 'master' into bbox resolving conflicts with PR #43
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Implement BoundingBox for MultiPolygon
- Loading branch information
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
use num::{Float}; | ||
|
||
use types::{Bbox, Point, MultiPoint, LineString, MultiLineString, Polygon}; | ||
use types::{Bbox, Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon}; | ||
|
||
/// Calculation of the bounding box of a geometry. | ||
|
||
|
@@ -99,8 +99,6 @@ impl<T> BoundingBox<T> for MultiLineString<T> | |
} | ||
} | ||
Some(bbox) | ||
// vect[1..].iter() | ||
// .fold(bbox, |bbfinal, (geo0, geo1)| bbfinal + geo0.bbox().unwrap() + geo1.bbox().unwrap()); | ||
} | ||
} | ||
} | ||
|
@@ -117,12 +115,37 @@ impl<T> BoundingBox<T> for Polygon<T> | |
} | ||
} | ||
|
||
impl<T> BoundingBox<T> for MultiPolygon<T> | ||
where T: Float | ||
{ | ||
/// | ||
/// Return the BoundingBox for a MultiLineString | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bad comment |
||
/// | ||
fn bbox(&self) -> Option<Bbox<T>> { | ||
let vect = &self.0; | ||
if vect.is_empty() { | ||
return None; | ||
} | ||
if vect.len() == 1 { | ||
return vect[0].bbox() | ||
} else { | ||
let mut bbox = vect[0].bbox().unwrap(); | ||
for geo in vect[1..].iter() { | ||
let gopt = geo.bbox(); | ||
if gopt.is_some() { | ||
bbox += gopt.unwrap(); | ||
} | ||
} | ||
Some(bbox) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... that. |
||
} | ||
} | ||
|
||
|
||
|
||
#[cfg(test)] | ||
mod test { | ||
use types::{Bbox, Coordinate, Point, MultiPoint, LineString, MultiLineString, Polygon}; | ||
use types::{Bbox, Coordinate, Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon}; | ||
use algorithm::boundingbox::BoundingBox; | ||
|
||
#[test] | ||
|
@@ -173,4 +196,14 @@ mod test { | |
let poly = Polygon(linestring, Vec::new()); | ||
assert_eq!(line_bbox, poly.bbox().unwrap()); | ||
} | ||
#[test] | ||
fn multipolygon_test(){ | ||
let p = |x, y| Point(Coordinate { x: x, y: y }); | ||
let mpoly = MultiPolygon(vec![Polygon(LineString(vec![p(0., 0.), p(50., 0.), p(0., -70.), p(0., 0.)]), Vec::new()), | ||
Polygon(LineString(vec![p(0., 0.), p(5., 0.), p(0., 80.), p(0., 0.)]), Vec::new()), | ||
Polygon(LineString(vec![p(0., 0.), p(-60., 0.), p(0., 6.), p(0., 0.)]), Vec::new()), | ||
]); | ||
let bbox = Bbox{xmin: -60., ymax: 80., xmax: 50., ymin: -70.}; | ||
assert_eq!(bbox, mpoly.bbox().unwrap()); | ||
} | ||
} |
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.
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.
duplicated code with...