geo-clipper

Crates.iogeo-clipper
lib.rsgeo-clipper
version0.8.0
sourcesrc
created_at2019-08-19 09:58:27.493539
updated_at2023-10-19 17:22:13.350933
descriptionBoolean operations on polygons
homepage
repositoryhttps://github.com/lelongg/geo-clipper
max_upload_size
id158038
size50,343
GĂ©rald Lelong (lelongg)

documentation

https://docs.rs/geo-clipper/

README

geo-clipper

This crate allows to perform boolean and offset operations on polygons.

crate.io docs.rs

It makes use of clipper-sys which is a binding to the C++ version of Clipper.

Example

The following example shows how to compute the intersection of two polygons. The intersection method (as well as difference, union and xor) is provided by the Clipper trait which is implemented for some geo-types.

use geo_types::{Coord, LineString, Polygon};
use geo_clipper::Clipper;

let subject = Polygon::new(
    LineString(vec![
        Coord { x: 180.0, y: 200.0 },
        Coord { x: 260.0, y: 200.0 },
        Coord { x: 260.0, y: 150.0 },
        Coord { x: 180.0, y: 150.0 },
    ]),
    vec![LineString(vec![
        Coord { x: 215.0, y: 160.0 },
        Coord { x: 230.0, y: 190.0 },
        Coord { x: 200.0, y: 190.0 },
    ])],
);

let clip = Polygon::new(
    LineString(vec![
        Coord { x: 190.0, y: 210.0 },
        Coord { x: 240.0, y: 210.0 },
        Coord { x: 240.0, y: 130.0 },
        Coord { x: 190.0, y: 130.0 },
    ]),
    vec![],
);

let result = subject.intersection(&clip, 1.0);
Commit count: 81

cargo fmt