Skip to main content

intersect_polygons_pooled

Function intersect_polygons_pooled 

Source
pub fn intersect_polygons_pooled(
    poly1: &Polygon,
    poly2: &Polygon,
) -> Result<PoolGuard<'static, Polygon>>
Expand description

Computes intersection of two polygons using object pooling

This is the pooled version of intersect_polygons that reuses allocated polygons from a thread-local pool. Returns the first result polygon.

§Arguments

  • poly1 - First polygon
  • poly2 - Second polygon

§Returns

A pooled polygon guard representing the intersection (first result if multiple)

§Errors

Returns error if polygons are invalid

§Performance

For batch operations, this can reduce allocations by 2-3x compared to the non-pooled version.

§Example

use oxigdal_algorithms::vector::{intersect_polygons_pooled, Coordinate, LineString, Polygon};

let coords1 = vec![
    Coordinate::new_2d(0.0, 0.0),
    Coordinate::new_2d(10.0, 0.0),
    Coordinate::new_2d(10.0, 10.0),
    Coordinate::new_2d(0.0, 10.0),
    Coordinate::new_2d(0.0, 0.0),
];
let ext1 = LineString::new(coords1)?;
let poly1 = Polygon::new(ext1, vec![])?;
let result = intersect_polygons_pooled(&poly1, &poly2)?;