10 releases (6 breaking)

0.7.3 Mar 16, 2022
0.7.1 Nov 13, 2021
0.7.0 Jul 10, 2021
0.4.0 Sep 26, 2020
0.1.0 Aug 19, 2019

#120 in Algorithms

Download history 447/week @ 2022-10-15 565/week @ 2022-10-22 633/week @ 2022-10-29 500/week @ 2022-11-05 673/week @ 2022-11-12 429/week @ 2022-11-19 608/week @ 2022-11-26 764/week @ 2022-12-03 518/week @ 2022-12-10 759/week @ 2022-12-17 255/week @ 2022-12-24 342/week @ 2022-12-31 444/week @ 2023-01-07 397/week @ 2023-01-14 474/week @ 2023-01-21 666/week @ 2023-01-28

2,052 downloads per month
Used in 4 crates

ISC license

44KB
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::{Coordinate, LineString, Polygon};
use geo_clipper::Clipper;

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

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

let result = subject.intersection(&clip, 1.0);

Dependencies

~435–640KB
~13K SLoC