pub fn is_point_in_polygon(test_point: Point, poly: &Vec<Point>) -> bool {

	// Sanity checks.
	let mut num_crossings = 0;
	let num_vertices = poly.len();

	// Need at least three points to make a polygon.
	if num_vertices < 3 {
		return false;
	}

	let test_x = test_point.x;
	let test_y = test_point.y;
	for i in 0..num_vertices {

		// Cache the y coordinate for the first point on the edge.
		let mut poly_pt = poly[i];
		let poly_pt1_y = poly_pt.y;

		// Cache the second point on the edge, handling the wrap around that happens when we close the polygon.
		let poly_pt2_x;
		let poly_pt2_y;
		if i == num_vertices - 1 {
			poly_pt = poly[0];
			poly_pt2_x = poly_pt.x;
			poly_pt2_y = poly_pt.y;
		}
		else {
			poly_pt = poly[i + 1];
			poly_pt2_x = poly_pt.x;
			poly_pt2_y = poly_pt.y;
		}

		// Test if the point is within the y limits of the edge.
		let crosses_y = ((poly_pt1_y <= test_y) && (poly_pt2_y > test_y)) || ((poly_pt1_y > test_y) && (poly_pt2_y <= test_y));
		if crosses_y {

			// Test if the ray extending to the right of the point crosses the edge.
			let poly_pt1_x = poly[i].x;
			if test_x <  poly_pt1_x + ((test_y - poly_pt1_y) / (poly_pt2_y - poly_pt1_y)) * (poly_pt2_x - poly_pt1_x) {
				num_crossings = num_crossings + 1;
			}
		}
	}

	(num_crossings & 1) != 0
}
// Implements the ray casting/crossing number algorithm. Returns TRUE if the point is within the bounds of the points that specify the polygon (poly is a list of points)
Implements the ray casting/crossing number algorithm. Returns TRUE if the point is within the bounds of the points that specify the polygon (poly is a list of points)
Implements the ray casting / crossing number algorithm . Returns TRUE if the point is within the bounds of the points that specify the polygon ( poly is a list of points )
pub fn is_point_in_polygon(test_point: Point, poly: &Vec<Point>) -> bool {
	// Sanity checks.
	let mut num_crossings = 0;
	let num_vertices = poly.len();
	// Need at least three points to make a polygon.
	if num_vertices < 3 {
		return false;
	}
	let test_x = test_point.x;
	let test_y = test_point.y;
	for i in 0..num_vertices {
		// Cache the y coordinate for the first point on the edge.
		let mut poly_pt = poly[i];
		let poly_pt1_y = poly_pt.y;
		// Cache the second point on the edge, handling the wrap around that happens when we close the polygon.
		let poly_pt2_x;
		let poly_pt2_y;
		if i == num_vertices - 1 {
			poly_pt = poly[0];
			poly_pt2_x = poly_pt.x;
			poly_pt2_y = poly_pt.y;
		}
		else {
			poly_pt = poly[i + 1];
			poly_pt2_x = poly_pt.x;
			poly_pt2_y = poly_pt.y;
		}
		// Test if the point is within the y limits of the edge.
		let crosses_y = ((poly_pt1_y <= test_y) && (poly_pt2_y > test_y)) || ((poly_pt1_y > test_y) && (poly_pt2_y <= test_y));
		if crosses_y {
			// Test if the ray extending to the right of the point crosses the edge.
			let poly_pt1_x = poly[i].x;
			if test_x <  poly_pt1_x + ((test_y - poly_pt1_y) / (poly_pt2_y - poly_pt1_y)) * (poly_pt2_x - poly_pt1_x) {
				num_crossings = num_crossings + 1;
			}
		}
	}
	(num_crossings & 1) != 0
}
pub fn is_point_in_polygon ( test_point : Point , poly : & Vec < Point > ) -> bool { // Sanity checks. let mut num_crossings = 0 ; let num_vertices = poly . len ( ) ; // Need at least three points to make a polygon. if num_vertices < 3 { return false ; } let test_x = test_point . x ; let test_y = test_point . y ; for i in 0 .. num_vertices { // Cache the y coordinate for the first point on the edge. let mut poly_pt = poly [ i ] ; let poly_pt1_y = poly_pt . y ; // Cache the second point on the edge, handling the wrap around that happens when we close the polygon. let poly_pt2_x ; let poly_pt2_y ; if i == num_vertices - 1 { poly_pt = poly [ 0 ] ; poly_pt2_x = poly_pt . x ; poly_pt2_y = poly_pt . y ; } else { poly_pt = poly [ i + 1 ] ; poly_pt2_x = poly_pt . x ; poly_pt2_y = poly_pt . y ; } // Test if the point is within the y limits of the edge. let crosses_y = ( ( poly_pt1_y <= test_y ) && ( poly_pt2_y > test_y ) ) || ( ( poly_pt1_y > test_y ) && ( poly_pt2_y <= test_y ) ) ; if crosses_y { // Test if the ray extending to the right of the point crosses the edge. let poly_pt1_x = poly [ i ] . x ; if test_x < poly_pt1_x + ( ( test_y - poly_pt1_y ) / ( poly_pt2_y - poly_pt1_y ) ) * ( poly_pt2_x - poly_pt1_x ) { num_crossings = num_crossings + 1 ; } } } ( num_crossings & 1 ) != 0 }
Implements the ray casting/crossing number algorithm.
Implements the ray casting / crossing number algorithm .
test_point
Point
poly
&Vec<Point>