Skip to content

Monotone Chain #1466

@cookiedan42

Description

@cookiedan42

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 Geometry and GeometryCollection based 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

  1. How should this new class of structs be named? MonotoneMultiLineString is quite a mouthful
  2. How to disambiguate MonotoneChain concept of monotone from the existing MonoPoly which uses a different concept of Monotonic Geometry

References:
GEOS docs
JTS docs
old JTS blog

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions