Trait geo::algorithm::coordinate_position::CoordinatePosition
source · pub trait CoordinatePosition {
type Scalar: GeoNum;
// Required method
fn calculate_coordinate_position(
&self,
coord: &Coord<Self::Scalar>,
is_inside: &mut bool,
boundary_count: &mut usize
);
// Provided method
fn coordinate_position(&self, coord: &Coord<Self::Scalar>) -> CoordPos { ... }
}
Expand description
Determine whether a Coord
lies inside, outside, or on the boundary of a geometry.
§Examples
use geo::{polygon, coord};
use geo::coordinate_position::{CoordinatePosition, CoordPos};
let square_poly = polygon![(x: 0.0, y: 0.0), (x: 2.0, y: 0.0), (x: 2.0, y: 2.0), (x: 0.0, y: 2.0), (x: 0.0, y: 0.0)];
let inside_coord = coord! { x: 1.0, y: 1.0 };
assert_eq!(square_poly.coordinate_position(&inside_coord), CoordPos::Inside);
let boundary_coord = coord! { x: 0.0, y: 1.0 };
assert_eq!(square_poly.coordinate_position(&boundary_coord), CoordPos::OnBoundary);
let outside_coord = coord! { x: 5.0, y: 5.0 };
assert_eq!(square_poly.coordinate_position(&outside_coord), CoordPos::Outside);