11 releases (7 breaking)

0.8.0 Oct 19, 2023
0.7.3 Mar 16, 2022
0.7.1 Nov 13, 2021
0.7.0 Jul 10, 2021
0.1.0 Aug 19, 2019

#290 in Algorithms

Download history 1281/week @ 2024-07-23 2072/week @ 2024-07-30 1889/week @ 2024-08-06 1508/week @ 2024-08-13 1201/week @ 2024-08-20 1423/week @ 2024-08-27 1233/week @ 2024-09-03 1796/week @ 2024-09-10 1876/week @ 2024-09-17 1764/week @ 2024-09-24 1609/week @ 2024-10-01 1967/week @ 2024-10-08 1787/week @ 2024-10-15 1760/week @ 2024-10-22 1697/week @ 2024-10-29 2199/week @ 2024-11-05

7,988 downloads per month
Used in 7 crates

ISC license

45KB
1K SLoC

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);

Dependencies

~0.8–1.2MB
~25K SLoC