Module boolean_ops

Module boolean_ops 

Source
Expand description

Boolean operations for polygons and polyhedra

This module provides implementations of set-theoretic Boolean operations on polygons (2D) and polyhedra (3D). These operations include union, intersection, difference, and symmetric difference.

§Theory

Boolean operations on polygons are fundamental in computational geometry and are used in CAD systems, GIS applications, and computer graphics. The algorithms implemented here use:

  • Sutherland-Hodgman clipping for convex polygons
  • Weiler-Atherton clipping for general polygons
  • BSP tree decomposition for 3D polyhedra
  • Plane sweep algorithms for efficiency

§Examples

use scirs2_spatial::boolean_ops::{polygon_union, polygon_intersection};
use scirs2_core::ndarray::array;

// Define two overlapping squares
let poly1 = array![
    [0.0, 0.0],
    [2.0, 0.0],
    [2.0, 2.0],
    [0.0, 2.0]
];

let poly2 = array![
    [1.0, 1.0],
    [3.0, 1.0],
    [3.0, 3.0],
    [1.0, 3.0]
];

// Compute union
let union_result = polygon_union(&poly1.view(), &poly2.view()).unwrap();
println!("Union has {} vertices", union_result.nrows());

// Compute intersection
let intersection_result = polygon_intersection(&poly1.view(), &poly2.view()).unwrap();
println!("Intersection has {} vertices", intersection_result.nrows());

Functions§

compute_polygon_area
Compute the area of a polygon
is_convex_polygon
Check if a polygon is convex
is_self_intersecting
Check if a polygon is self-intersecting
polygon_difference
Compute the difference of two polygons (poly1 - poly2)
polygon_intersection
Compute the intersection of two polygons
polygon_symmetric_difference
Compute the symmetric difference (XOR) of two polygons
polygon_union
Compute the union of two polygons