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 type Bbox and trait BoundingBox #41

Merged
merged 21 commits into from
Jul 21, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Merge branch 'master' into bbox resolving conflicts with PR #43
  • Loading branch information
Zambelli Pietro committed Jul 20, 2016
commit 03293f5560c4a085b4b57ca9c73908e5df17f33e
25 changes: 23 additions & 2 deletions src/algorithm/area.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use num::Float;
use types::{Polygon, Bbox};
use types::{LineString, Polygon, MultiPolygon, Bbox};

/// Calculation of the area.

Expand Down Expand Up @@ -59,7 +59,7 @@ impl<T> Area<T> for Bbox<T>

#[cfg(test)]
mod test {
use types::{Coordinate, Point, LineString, Polygon, Bbox};
use types::{Coordinate, Point, LineString, Polygon, MultiPolygon, Bbox};
use algorithm::area::Area;
// Area of the polygon
#[test]
Expand All @@ -85,4 +85,25 @@ mod test {
let bbox = Bbox {xmin: 10., xmax: 20., ymin: 30., ymax: 40.};
assert_eq!(100., bbox.area());
}
#[test]
fn area_polygon_inner_test() {
let p = |x, y| Point(Coordinate { x: x, y: y });
let outer = LineString(vec![p(0., 0.), p(10., 0.), p(10., 10.), p(0., 10.), p(0., 0.)]);
let inner0 = LineString(vec![p(1., 1.), p(2., 1.), p(2., 2.), p(1., 2.), p(1., 1.)]);
let inner1 = LineString(vec![p(5., 5.), p(6., 5.), p(6., 6.), p(5., 6.), p(5., 5.)]);
let poly = Polygon(outer, vec![inner0, inner1]);
assert_eq!(poly.area(), 98.);
}
#[test]
fn area_multipolygon_test() {
let p = |x, y| Point(Coordinate { x: x, y: y });
let poly0 = Polygon(LineString(vec![p(0., 0.), p(10., 0.), p(10., 10.), p(0., 10.), p(0., 0.)]),
Vec::new());
let poly1 = Polygon(LineString(vec![p(1., 1.), p(2., 1.), p(2., 2.), p(1., 2.), p(1., 1.)]),
Vec::new());
let poly2 = Polygon(LineString(vec![p(5., 5.), p(6., 5.), p(6., 6.), p(5., 6.), p(5., 5.)]),
Vec::new());
let mpoly = MultiPolygon(vec![poly0, poly1, poly2]);
assert_eq!(mpoly.area(), 102.);
}
}
You are viewing a condensed version of this merge commit. You can view the full changes here.