Skip to content

Rust crate to perform boolean operations on polygons.

Notifications You must be signed in to change notification settings

dungeonfog/geo-clipper

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

geo-clipper

This crate allows to perform boolean 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);

About

Rust crate to perform boolean operations on polygons.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 98.8%
  • Nix 1.2%