Giter VIP home page Giter VIP logo

rust-geo-booleanop's Introduction

Build Status crates.io

Boolean operations on geo shapes

This is an implementation of the Martinez-Rueda Polygon Clipping Algorithm in rust to integrate smoothly into the already exsting geospatial library georust/geo.

In fact the implementation closely follows the "reference" implementation in JavaScript: https://github.com/w8r/martinez. Most of the concepts and fixtures have been taken from there.

At the moment the implementation contains its own splay tree implementation (adapted from https://github.com/alexcrichton/splay-rs) as the JavaScript implementation also uses a splay-tree. This might be refactored out in the future in favor of the standard collection types (like BTreeSet).

IMPORTANT: How to report bugs

Please be aware (so far) this implementation is based on the JavaScript version. If you find a bug (i.e. two polygons not producing the expected result), chances are that the original algorithm has the same problem. So please first check with https://github.com/w8r/martinez and file a report there. Once there is a fix I will happily backport it to the rust version.

If you do not know how to do that (You understand rust but not javascript? ... I mean ... seriously?), you may take a look at this example: https://gist.github.com/untoldwind/e95b7eff8ad61527a5dc4bdd889169b0

I.e. just create package.json, ìnsert your example coordinates in main.js and then do npm install followed by node main.js

Usage

Pretty straightforward:

geo-booleanop = "0.2.1"
extern create geo;
extern crate geo_booleanop;

use geo_booleanop::boolean::BooleanOp;

fn main() {
    let poly1 : geo::Polygon<f64> = ...
    let poly2 : geo::Polygon<f64> = ...

    let intersect = poly1.intersection(&poly2);
    let union = poly1.union(&poly2);
    let diff = poly1.difference(&poly2);
    let xor = poly1.xor(&poly2);

    ...
}

MultiPolygon is supported as well.

rust-geo-booleanop's People

Contributors

aloise avatar bluenote10 avatar boydjohnson avatar bronson-brown-devost avatar frewsxcv avatar kurtronshausen avatar michaelkirk avatar rmanoka avatar sayrer avatar untoldwind avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.