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

Allow coordinates to be more types #187

Merged
merged 6 commits into from
Mar 11, 2018
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
Next Next commit
Contains doesn't always need to be Float
  • Loading branch information
Rory McCann committed Mar 11, 2018
commit 2a99dc42630acccff66647903ddaf953bb9b887f
17 changes: 14 additions & 3 deletions src/algorithm/contains.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use num_traits::{Float, ToPrimitive};

use types::{Bbox, Line, LineString, MultiPolygon, Point, Polygon, COORD_PRECISION};
use types::{COORD_PRECISION, CoordinateType, Point, Line, LineString, Polygon, MultiPolygon, Bbox};
use algorithm::intersects::Intersects;
use algorithm::distance::Distance;

Expand Down Expand Up @@ -246,7 +246,7 @@ where

impl<T> Contains<Point<T>> for Bbox<T>
where
T: Float,
T: CoordinateType
{
fn contains(&self, p: &Point<T>) -> bool {
p.x() >= self.xmin && p.x() <= self.xmax && p.y() >= self.ymin && p.y() <= self.ymax
Expand All @@ -255,7 +255,7 @@ where

impl<T> Contains<Bbox<T>> for Bbox<T>
where
T: Float,
T: CoordinateType
{
fn contains(&self, bbox: &Bbox<T>) -> bool {
// All points of LineString must be in the polygon ?
Expand Down Expand Up @@ -600,4 +600,15 @@ mod test {
assert!(linestring1.contains(&line0));
assert!(!linestring2.contains(&line0));
}

#[test]
fn integer_bboxs() {
let p: Point<i32> = Point::new(10, 20);
let bbox: Bbox<i32> = Bbox{ xmin: 0, ymin:0, xmax: 100, ymax: 100 };
assert!(bbox.contains(&p));
assert!(!bbox.contains(&Point::new(-10, -10)));

let smaller_bbox: Bbox<i32> = Bbox{ xmin: 10, ymin: 10, xmax: 20, ymax: 20 };
assert!(bbox.contains(&smaller_bbox));
}
}