w8r / Greinerhormann
Licence: mit
Greiner-Hormann polygon clipping algorithm. Does AND, OR, XOR. Plays nicely with Leaflet. Handles non-convex polygons and multiple clipping areas. ~3kb footprint, no dependencies
Stars: ✭ 176
Programming Languages
javascript
184084 projects - #8 most used programming language
Projects that are alternatives of or similar to Greinerhormann
Geokdbush
The fastest spatial index for geographic locations in JavaScript
Stars: ✭ 251 (+42.61%)
Mutual labels: algorithm, computational-geometry
Flatbush
A very fast static spatial index for 2D points and rectangles in JavaScript
Stars: ✭ 1,031 (+485.8%)
Mutual labels: algorithm, computational-geometry
Kdbush
A fast static index for 2D points
Stars: ✭ 412 (+134.09%)
Mutual labels: algorithm, computational-geometry
Turf
A modular geospatial engine written in JavaScript
Stars: ✭ 6,659 (+3683.52%)
Mutual labels: algorithm, computational-geometry
Turf Swift
A Swift language port of Turf.js.
Stars: ✭ 123 (-30.11%)
Mutual labels: algorithm, computational-geometry
Delaunator Cpp
A really fast C++ library for Delaunay triangulation of 2D points
Stars: ✭ 244 (+38.64%)
Mutual labels: algorithm, computational-geometry
Polysnap
A work in progress polygon operations library with integer snap-rounding
Stars: ✭ 14 (-92.05%)
Mutual labels: algorithm, computational-geometry
Skeleton Tracing
A new algorithm for retrieving topological skeleton as a set of polylines from binary images
Stars: ✭ 241 (+36.93%)
Mutual labels: algorithm, computational-geometry
Delaunator
An incredibly fast JavaScript library for Delaunay triangulation of 2D points
Stars: ✭ 1,641 (+832.39%)
Mutual labels: algorithm, computational-geometry
Earcut
The fastest and smallest JavaScript polygon triangulation library for your WebGL apps
Stars: ✭ 1,359 (+672.16%)
Mutual labels: algorithm, computational-geometry
Supercluster
A very fast geospatial point clustering library for browsers and Node.
Stars: ✭ 1,246 (+607.95%)
Mutual labels: algorithm, computational-geometry
Cavaliercontours
2D polyline library for offsetting, combining, etc.
Stars: ✭ 135 (-23.3%)
Mutual labels: algorithm, computational-geometry
Data structure and algorithms library
A collection of classical algorithms and data-structures implementation in C++ for coding interview and competitive programming
Stars: ✭ 133 (-24.43%)
Mutual labels: algorithm, computational-geometry
Rbush
RBush — a high-performance JavaScript R-tree-based 2D spatial index for points and rectangles
Stars: ✭ 1,881 (+968.75%)
Mutual labels: algorithm, computational-geometry
Fe Interview
宇宙最强的前端面试指南 (https://lucifer.ren/fe-interview)
Stars: ✭ 2,284 (+1197.73%)
Mutual labels: algorithm
Idworker
idworker 是一个基于zookeeper和snowflake算法的分布式ID生成工具,通过zookeeper自动注册机器(最多1024台),无需手动指定workerId和datacenterId
Stars: ✭ 171 (-2.84%)
Mutual labels: algorithm
Textdistance
Compute distance between sequences. 30+ algorithms, pure python implementation, common interface, optional external libs usage.
Stars: ✭ 2,575 (+1363.07%)
Mutual labels: algorithm
Go Jump Consistent Hash
⚡️ Fast, minimal memory, consistent hash algorithm
Stars: ✭ 163 (-7.39%)
Mutual labels: algorithm
Robust Predicates
Fast robust predicates for computational geometry in JavaScript
Stars: ✭ 170 (-3.41%)
Mutual labels: computational-geometry
Greiner-Hormann polygon clipping
- Does AND, OR, XOR (intersection, union, difference, if you're human)
- Plays nicely with Leaflet, comes with an adaptor for it
- Handles non-convex polygons and multiple clipping areas
- ~3kb compressed, no dependencies
Note: If you are looking for something more powerful, take a look at the Martinez polygon clipping implementation.
Install
$ npm install greiner-hormann
Browserify
var greinerHormann = require('greiner-hormann');
Browser
<script src="path/to/greiner-hormann(.leaflet).min.js"></script>
Use
...
var intersection = greinerHormann.intersection(source, clip);
var union = greinerHormann.union(source, clip);
var diff = greinerHormann.diff(source, clip);
...
if(intersection){
if(typeof intersection[0][0] === 'number'){ // single linear ring
intersection = [intersection];
}
for(var i = 0, len = intersection.length; i < len; i++){
L.polygon(intersection[i], {...}).addTo(map);
}
}
Format
Input and output can be {x:x, y:y}
objects or [x,y]
pairs. It will output the points in the same format you put in.
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].