Module polygon

Module polygon 

Source
Expand description

Polygon operations module

This module provides functionality for working with polygons, including:

  • Point in polygon testing
  • Area and centroid calculations
  • Polygon operations (simplification, transformation)

§Examples

use scirs2_core::ndarray::array;
use scirs2_spatial::polygon::point_in_polygon;

// Create a square polygon
let polygon = array![
    [0.0, 0.0],
    [1.0, 0.0],
    [1.0, 1.0],
    [0.0, 1.0],
];

// Test if a point is inside
let inside = point_in_polygon(&[0.5, 0.5], &polygon.view());
assert!(inside);

// Test if a point is outside
let outside = point_in_polygon(&[1.5, 0.5], &polygon.view());
assert!(!outside);

Functions§

convex_hull_graham
Compute the convex hull of a polygon using the Graham scan algorithm.
douglas_peucker_simplify
Simplify a polygon using the Douglas-Peucker algorithm.
is_simple_polygon
Check if a polygon is simple (non-self-intersecting).
point_in_polygon
Tests if a point is inside a polygon using the ray casting algorithm.
point_on_boundary
Tests if a point is on the boundary of a polygon.
polygon_area
Calculate the area of a simple polygon.
polygon_centroid
Calculate the centroid of a simple polygon.
polygon_contains_polygon
Tests if polygon A contains polygon B (every point of B is inside or on the boundary of A).
visvalingam_whyatt_simplify
Simplify a polygon using the Visvalingam-Whyatt algorithm.