MCPcopy Index your code
hub / github.com/21re/rust-geo-booleanop

github.com/21re/rust-geo-booleanop @v0.3.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.3.0 ↗ · + Follow
231 symbols 608 edges 29 files 13 documented · 6%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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.

Extension points exported contracts — how you extend this code

BooleanOp (Interface)
(no doc) [4 implementers]
lib/src/boolean/mod.rs
WriteIndented (Interface)
(no doc) [1 implementers]
tests/src/compact_geojson.rs
NextAfter (Interface)
(no doc) [2 implementers]
lib/src/boolean/helper.rs
JsonDebug (Interface)
(no doc) [1 implementers]
lib/src/boolean/sweep_event.rs
Float (Interface)
(no doc) [1 implementers]
lib/src/boolean/helper.rs

Core symbols most depended-on inside this repo

make_simple
called by 38
lib/src/boolean/compare_segments.rs
get_other_event
called by 23
lib/src/boolean/sweep_event.rs
insert
called by 21
lib/src/splay/set.rs
write_indented
called by 19
tests/src/compact_geojson.rs
se_pair
called by 18
lib/src/boolean/sweep_event.rs
len
called by 15
lib/src/splay/set.rs
is_left
called by 15
lib/src/boolean/sweep_event.rs
make_simple
called by 14
lib/src/boolean/fill_queue.rs

Shape

Function 122
Method 87
Class 10
Enum 7
Interface 5

Languages

Rust97%
Python3%

Modules by API surface

lib/src/boolean/sweep_event.rs40 symbols
lib/src/splay/tree.rs29 symbols
lib/src/splay/set.rs18 symbols
lib/src/boolean/connect_edges.rs14 symbols
lib/src/splay/mod.rs13 symbols
lib/src/boolean/segment_intersection.rs12 symbols
tests/src/helper.rs11 symbols
lib/src/boolean/helper.rs11 symbols
lib/src/boolean/compare_segments.rs11 symbols
tests/src/data_generators.rs9 symbols
lib/src/boolean/mod.rs9 symbols
lib/src/boolean/fill_queue.rs9 symbols

For agents

$ claude mcp add rust-geo-booleanop \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact