pub fn point_in_polygon<T>(point: &Point<T, T>, polygon: &Polygon<T>) -> boolExpand description
Checks if a point is inside a polygon using the ray casting algorithm
A horizontal ray from the point to the right intersects an edge if:
$$(y_i > q_y) \neq (y_j > q_y) \land q_x < \frac{x_j - x_i}{y_j - y_i}(q_y - y_i) + x_i$$
§Arguments
point- The point to checkpolygon- The polygon to test against
§Returns
true if the point is inside the polygon, false otherwise
§Examples
use physdes::{Point, algorithms::point_in_polygon};
use physdes::Polygon;
let points = vec![
Point::new(0, 0),
Point::new(10, 0),
Point::new(10, 10),
Point::new(0, 10),
];
let polygon = Polygon::new(&points);
assert!(point_in_polygon(&Point::new(5, 5), &polygon));
assert!(!point_in_polygon(&Point::new(15, 15), &polygon));