-
Notifications
You must be signed in to change notification settings - Fork 230
Description
Overview
Montone Chains are a way of preprocessing an array of coordinates so that intersections can be efficiently calculated using binary search, and looks to be a primitive used in JTS and GEOS for some internal operations
I built a proof of concept #1467 which uses &[Coord] to an existing geometry's backing Vec(s) as the backing data and implemented Intersects for existing geometries.
Overall there's a significant speedup on larger geometries in Intersects and ContainsProperly features where I replaced the brute force linestring-linestring intersections, but slowdown in smaller geoms. Haven't done the benching to find the crossing point, so the current threshold const is arbitrary
Discussion points
1. Integration
Option 1: Monotone Geometry analogous to Prepared Geometry (leaning toward this option)
struct MonotoneLineString{
geom:LineString
chain: MonotoneChain
}
struct MonotoneMultiLineString{
geom:MultiLineString
chain: Vec<MonotoneChain>
// or maybe Vec<MonotoneLineString>?
}
struct MonotonePolygon{
geom:Polygon
exterior: MonotoneChain
interiors:Vec<MonotoneChain>
}- Make the choice to use Monotone-based geometries and algorithms explicit
- Possible to delegate to base geometry for anything not implemented
- Easier to reuse already constructed Monotone-based geometry multiple times
However
- Not all base geometries have a useful Monoton-based equivalent
- Adds cognitive overhead when choosing to convert into this type
Option 2: Integrate into existing methods
- Requires tuning of thresholds to switch between the different approaches to not cause performance regression
- pay the conversion overhead every invocation
- most "discoverable"
- most compatible with
GeometryandGeometryCollectionbased workflows
Option 3: Independent Function
- least disruptive
- pay the conversion overhead every invocation
I'm personally leaning toward option 1, with selective use of option 2 when benefit is clear
2. Naming
- How should this new class of structs be named?
MonotoneMultiLineStringis quite a mouthful - How to disambiguate
MonotoneChainconcept of monotone from the existingMonoPolywhich uses a different concept of Monotonic Geometry