Skip to content

Commit

Permalink
Merge georust#335
Browse files Browse the repository at this point in the history
335: Remove unneeded `p` helper functions in tests. r=frewsxcv a=frewsxcv



Co-authored-by: Corey Farwell <coreyf@rwell.org>
  • Loading branch information
bors[bot] and frewsxcv committed Jan 13, 2019
2 parents 79a756e + 886d51a commit a64dc8d
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 95 deletions.
8 changes: 2 additions & 6 deletions geo/src/algorithm/bounding_rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,7 @@ where
#[cfg(test)]
mod test {
use algorithm::bounding_rect::BoundingRect;
use {
Coordinate, Line, LineString, MultiLineString, MultiPoint, MultiPolygon, Point, Polygon,
Rect,
};
use {Coordinate, Line, LineString, MultiLineString, MultiPoint, MultiPolygon, Polygon, Rect};

#[test]
fn empty_linestring_test() {
Expand Down Expand Up @@ -191,8 +188,7 @@ mod test {
}
#[test]
fn multipoint_test() {
let p = |x, y| Point(Coordinate { x, y });
let multipoint = MultiPoint(vec![p(1., 1.), p(2., -2.), p(-3., -3.), p(-4., 4.)]);
let multipoint = MultiPoint::from(vec![(1., 1.), (2., -2.), (-3., -3.), (-4., 4.)]);
let bounding_rect = Rect {
min: Coordinate { x: -4., y: -3. },
max: Coordinate { x: 2., y: 4. },
Expand Down
61 changes: 26 additions & 35 deletions geo/src/algorithm/contains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,17 @@ pub trait Contains<Rhs = Self> {
/// use geo::{Coordinate, Point, LineString, Polygon};
/// use geo::algorithm::contains::Contains;
///
/// let p = |x, y| Point(Coordinate { x, y });
/// let v = Vec::new();
/// let linestring = LineString::from(vec![p(0., 0.), p(2., 0.), p(2., 2.), p(0., 2.), p(0., 0.)]);
/// let poly = Polygon::new(linestring.clone(), v);
/// let linestring = LineString::from(vec![(0., 0.), (2., 0.), (2., 2.), (0., 2.), (0., 0.)]);
/// let poly = Polygon::new(linestring.clone(), vec![]);
///
/// //Point in Point
/// assert!(p(2., 0.).contains(&p(2., 0.)));
/// assert!(Point::new(2., 0.).contains(&Point::new(2., 0.)));
///
/// //Point in Linestring
/// assert!(linestring.contains(&p(2., 0.)));
/// assert!(linestring.contains(&Point::new(2., 0.)));
///
/// //Point in Polygon
/// assert!(poly.contains(&p(1., 1.)));
/// assert!(poly.contains(&Point::new(1., 1.)));
///
/// ```
///
Expand Down Expand Up @@ -337,9 +335,8 @@ mod test {
#[test]
// LineString is fully contained
fn linestring_fully_contained_in_polygon() {
let p = |x, y| Coordinate { x, y };
let poly = Polygon::new(
LineString(vec![p(0., 0.), p(5., 0.), p(5., 6.), p(0., 6.), p(0., 0.)]),
LineString::from(vec![(0., 0.), (5., 0.), (5., 6.), (0., 6.), (0., 0.)]),
vec![],
);
let ls = LineString::from(vec![(3.0, 0.5), (3.0, 3.5)]);
Expand All @@ -353,15 +350,13 @@ mod test {
}
#[test]
fn linestring_point_is_vertex_test() {
let p = |x, y| Coordinate { x, y };
let linestring = LineString(vec![p(0., 0.), p(2., 0.), p(2., 2.)]);
assert!(linestring.contains(&Point(p(2., 2.))));
let linestring = LineString::from(vec![(0., 0.), (2., 0.), (2., 2.)]);
assert!(linestring.contains(&Point::new(2., 2.)));
}
#[test]
fn linestring_test() {
let p = |x, y| Coordinate { x, y };
let linestring = LineString(vec![p(0., 0.), p(2., 0.), p(2., 2.)]);
assert!(linestring.contains(&Point(p(1., 0.))));
let linestring = LineString::from(vec![(0., 0.), (2., 0.), (2., 2.)]);
assert!(linestring.contains(&Point::new(1., 0.)));
}
/// Tests: Point in Polygon
#[test]
Expand All @@ -384,34 +379,30 @@ mod test {
}
#[test]
fn polygon_with_point_on_boundary_test() {
let p = |x, y| Coordinate { x, y };
let linestring = LineString(vec![p(0., 0.), p(2., 0.), p(2., 2.), p(0., 2.), p(0., 0.)]);
let linestring = LineString::from(vec![(0., 0.), (2., 0.), (2., 2.), (0., 2.), (0., 0.)]);
let poly = Polygon::new(linestring, Vec::new());
assert!(!poly.contains(&Point(p(1., 0.))));
assert!(!poly.contains(&Point(p(2., 1.))));
assert!(!poly.contains(&Point(p(1., 2.))));
assert!(!poly.contains(&Point(p(0., 1.))));
assert!(!poly.contains(&Point::new(1., 0.)));
assert!(!poly.contains(&Point::new(2., 1.)));
assert!(!poly.contains(&Point::new(1., 2.)));
assert!(!poly.contains(&Point::new(0., 1.)));
}
#[test]
fn point_in_polygon_test() {
let p = |x, y| Coordinate { x, y };
let linestring = LineString(vec![p(0., 0.), p(2., 0.), p(2., 2.), p(0., 2.), p(0., 0.)]);
let linestring = LineString::from(vec![(0., 0.), (2., 0.), (2., 2.), (0., 2.), (0., 0.)]);
let poly = Polygon::new(linestring, Vec::new());
assert!(poly.contains(&Point(p(1., 1.))));
assert!(poly.contains(&Point::new(1., 1.)));
}
#[test]
fn point_out_polygon_test() {
let p = |x, y| Coordinate { x, y };
let linestring = LineString(vec![p(0., 0.), p(2., 0.), p(2., 2.), p(0., 2.), p(0., 0.)]);
let linestring = LineString::from(vec![(0., 0.), (2., 0.), (2., 2.), (0., 2.), (0., 0.)]);
let poly = Polygon::new(linestring, Vec::new());
assert!(!poly.contains(&Point(p(2.1, 1.))));
assert!(!poly.contains(&Point(p(1., 2.1))));
assert!(!poly.contains(&Point(p(2.1, 2.1))));
assert!(!poly.contains(&Point::new(2.1, 1.)));
assert!(!poly.contains(&Point::new(1., 2.1)));
assert!(!poly.contains(&Point::new(2.1, 2.1)));
}
#[test]
fn point_polygon_with_inner_test() {
let p = |x, y| Coordinate { x, y };
let linestring = LineString(vec![p(0., 0.), p(2., 0.), p(2., 2.), p(0., 2.), p(0., 0.)]);
let linestring = LineString::from(vec![(0., 0.), (2., 0.), (2., 2.), (0., 2.), (0., 0.)]);
let inner_linestring = LineString::from(vec![
(0.5, 0.5),
(1.5, 0.5),
Expand All @@ -420,10 +411,10 @@ mod test {
(0.0, 0.0),
]);
let poly = Polygon::new(linestring, vec![inner_linestring]);
assert!(poly.contains(&Point(p(0.25, 0.25))));
assert!(!poly.contains(&Point(p(1., 1.))));
assert!(!poly.contains(&Point(p(1.5, 1.5))));
assert!(!poly.contains(&Point(p(1.5, 1.))));
assert!(poly.contains(&Point::new(0.25, 0.25)));
assert!(!poly.contains(&Point::new(1., 1.)));
assert!(!poly.contains(&Point::new(1.5, 1.5)));
assert!(!poly.contains(&Point::new(1.5, 1.)));
}
/// Tests: Point in MultiPolygon
#[test]
Expand Down
86 changes: 32 additions & 54 deletions geo/src/algorithm/intersects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ pub trait Intersects<Rhs = Self> {
/// use geo::{Coordinate, Point, LineString};
/// use geo::algorithm::intersects::Intersects;
///
/// let p = |x, y| Point(Coordinate { x, y });
/// let linestring = LineString::from(vec![p(3., 2.), p(7., 6.)]);
/// let linestring = LineString::from(vec![(3., 2.), (7., 6.)]);
///
/// assert!(linestring.intersects(&LineString::from(vec![p(3., 4.), p(8., 4.)])));
/// assert!(!linestring.intersects(&LineString::from(vec![p(9., 2.), p(11., 5.)])));
/// assert!(linestring.intersects(&LineString::from(vec![(3., 4.), (8., 4.)])));
/// assert!(!linestring.intersects(&LineString::from(vec![(9., 2.), (11., 5.)])));
///
/// ```
///
Expand Down Expand Up @@ -297,33 +296,30 @@ mod test {
}
#[test]
fn linestring_on_boundary_polygon_test() {
let p = |x, y| Coordinate { x, y };
let poly = Polygon::new(
LineString(vec![p(0., 0.), p(5., 0.), p(5., 6.), p(0., 6.), p(0., 0.)]),
LineString::from(vec![(0., 0.), (5., 0.), (5., 6.), (0., 6.), (0., 0.)]),
Vec::new(),
);
assert!(poly.intersects(&LineString(vec![p(0., 0.), p(5., 0.)])));
assert!(poly.intersects(&LineString(vec![p(5., 0.), p(5., 6.)])));
assert!(poly.intersects(&LineString(vec![p(5., 6.), p(0., 6.)])));
assert!(poly.intersects(&LineString(vec![p(0., 6.), p(0., 0.)])));
assert!(poly.intersects(&LineString::from(vec![(0., 0.), (5., 0.)])));
assert!(poly.intersects(&LineString::from(vec![(5., 0.), (5., 6.)])));
assert!(poly.intersects(&LineString::from(vec![(5., 6.), (0., 6.)])));
assert!(poly.intersects(&LineString::from(vec![(0., 6.), (0., 0.)])));
}
#[test]
fn intersect_linestring_polygon_test() {
let p = |x, y| Coordinate { x, y };
let poly = Polygon::new(
LineString(vec![p(0., 0.), p(5., 0.), p(5., 6.), p(0., 6.), p(0., 0.)]),
LineString::from(vec![(0., 0.), (5., 0.), (5., 6.), (0., 6.), (0., 0.)]),
Vec::new(),
);
assert!(poly.intersects(&LineString(vec![p(2., 2.), p(6., 6.)])));
assert!(poly.intersects(&LineString::from(vec![(2., 2.), (6., 6.)])));
}
#[test]
fn linestring_outside_polygon_test() {
let p = |x, y| Coordinate { x, y };
let poly = Polygon::new(
LineString(vec![p(0., 0.), p(5., 0.), p(5., 6.), p(0., 6.), p(0., 0.)]),
LineString::from(vec![(0., 0.), (5., 0.), (5., 6.), (0., 6.), (0., 0.)]),
Vec::new(),
);
assert!(!poly.intersects(&LineString(vec![p(7., 2.), p(9., 4.)])));
assert!(!poly.intersects(&LineString::from(vec![(7., 2.), (9., 4.)])));
}
#[test]
fn linestring_in_inner_polygon_test() {
Expand Down Expand Up @@ -377,45 +373,30 @@ mod test {
// (2,2) | (14,2)
// (8,1)
//
let p = |x, y| Coordinate { x, y };

let e = LineString(vec![
p(2., 2.),
p(14., 2.),
p(14., 8.),
p(2., 8.),
p(2., 2.),
]);
let e = LineString::from(vec![(2., 2.), (14., 2.), (14., 8.), (2., 8.), (2., 2.)]);
let v = vec![
LineString(vec![p(4., 3.), p(7., 3.), p(7., 6.), p(4., 6.), p(4., 3.)]),
LineString(vec![
p(9., 3.),
p(12., 3.),
p(12., 6.),
p(9., 6.),
p(9., 3.),
]),
LineString::from(vec![(4., 3.), (7., 3.), (7., 6.), (4., 6.), (4., 3.)]),
LineString::from(vec![(9., 3.), (12., 3.), (12., 6.), (9., 6.), (9., 3.)]),
];
let poly = Polygon::new(e, v);
assert!(!poly.intersects(&LineString(vec![p(5., 4.), p(6., 5.)])));
assert!(poly.intersects(&LineString(vec![p(11., 2.5), p(11., 7.)])));
assert!(poly.intersects(&LineString(vec![p(4., 7.), p(6., 7.)])));
assert!(poly.intersects(&LineString(vec![p(8., 1.), p(8., 9.)])));
assert!(!poly.intersects(&LineString::from(vec![(5., 4.), (6., 5.)])));
assert!(poly.intersects(&LineString::from(vec![(11., 2.5), (11., 7.)])));
assert!(poly.intersects(&LineString::from(vec![(4., 7.), (6., 7.)])));
assert!(poly.intersects(&LineString::from(vec![(8., 1.), (8., 9.)])));
}
#[test]
fn polygons_do_not_intersect() {
let p = |x, y| Coordinate { x, y };
let p1 = Polygon::new(
LineString(vec![p(1., 3.), p(3., 3.), p(3., 5.), p(1., 5.), p(1., 3.)]),
LineString::from(vec![(1., 3.), (3., 3.), (3., 5.), (1., 5.), (1., 3.)]),
Vec::new(),
);
let p2 = Polygon::new(
LineString(vec![
p(10., 30.),
p(30., 30.),
p(30., 50.),
p(10., 50.),
p(10., 30.),
LineString::from(vec![
(10., 30.),
(30., 30.),
(30., 50.),
(10., 50.),
(10., 30.),
]),
Vec::new(),
);
Expand All @@ -425,13 +406,12 @@ mod test {
}
#[test]
fn polygons_overlap() {
let p = |x, y| Coordinate { x, y };
let p1 = Polygon::new(
LineString(vec![p(1., 3.), p(3., 3.), p(3., 5.), p(1., 5.), p(1., 3.)]),
LineString::from(vec![(1., 3.), (3., 3.), (3., 5.), (1., 5.), (1., 3.)]),
Vec::new(),
);
let p2 = Polygon::new(
LineString(vec![p(2., 3.), p(4., 3.), p(4., 7.), p(2., 7.), p(2., 3.)]),
LineString::from(vec![(2., 3.), (4., 3.), (4., 7.), (2., 7.), (2., 3.)]),
Vec::new(),
);

Expand All @@ -440,13 +420,12 @@ mod test {
}
#[test]
fn polygon_contained() {
let p = |x, y| Coordinate { x, y };
let p1 = Polygon::new(
LineString(vec![p(1., 3.), p(4., 3.), p(4., 6.), p(1., 6.), p(1., 3.)]),
LineString::from(vec![(1., 3.), (4., 3.), (4., 6.), (1., 6.), (1., 3.)]),
Vec::new(),
);
let p2 = Polygon::new(
LineString(vec![p(2., 4.), p(3., 4.), p(3., 5.), p(2., 5.), p(2., 4.)]),
LineString::from(vec![(2., 4.), (3., 4.), (3., 5.), (2., 5.), (2., 4.)]),
Vec::new(),
);

Expand All @@ -455,13 +434,12 @@ mod test {
}
#[test]
fn polygons_conincident() {
let p = |x, y| Coordinate { x, y };
let p1 = Polygon::new(
LineString(vec![p(1., 3.), p(4., 3.), p(4., 6.), p(1., 6.), p(1., 3.)]),
LineString::from(vec![(1., 3.), (4., 3.), (4., 6.), (1., 6.), (1., 3.)]),
Vec::new(),
);
let p2 = Polygon::new(
LineString(vec![p(1., 3.), p(4., 3.), p(4., 6.), p(1., 6.), p(1., 3.)]),
LineString::from(vec![(1., 3.), (4., 3.), (4., 6.), (1., 6.), (1., 3.)]),
Vec::new(),
);

Expand Down

0 comments on commit a64dc8d

Please sign in to comment.