Class DiskUnion

java.lang.Object
com.github.micycle1.geoblitz.DiskUnion

public final class DiskUnion extends Object
Computes the union of circular disks by preserving circular arcs in the boundary representation instead of linearizing circles upfront.

This algorithm maintains the exact circular arcs that form the union boundary, deferring linearization until the final geometry construction. This approach is significantly faster than polygonizing each circle and using JTS CascadedPolygonUnion, particularly when high-fidelity circle approximations would require many vertices.

Author:
Michael Carleton
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    A boundary arc of the union, oriented so the union interior is on the left.
    static final class 
    Result: boundary as arc cycles (outer shells + holes).
    static final class 
    One closed boundary component: a cyclic list of arcs.
    static final class 
    Immutable disk definition used by this algorithm.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.locationtech.jts.geom.Geometry
    union(List<org.locationtech.jts.geom.Coordinate> circles, double maxSegmentLength)
    Computes the union of the given circles and linearizes the result to a Geometry.
    static org.locationtech.jts.geom.Geometry
    union(List<org.locationtech.jts.geom.Coordinate> circles, double maxSegmentLength, double eps)
    Computes the union of the given circles with specified geometric tolerance.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DiskUnion

      public DiskUnion()
  • Method Details

    • union

      public static org.locationtech.jts.geom.Geometry union(List<org.locationtech.jts.geom.Coordinate> circles, double maxSegmentLength)
      Computes the union of the given circles and linearizes the result to a Geometry.

      Circles are specified as Coordinate objects where x and y define the center point and z defines the radius. The algorithm computes the exact arc boundary of the union, then approximates it with linear segments.

      The maxSegmentLength parameter controls the linearization fidelity. Smaller values produce smoother approximations at the cost of more vertices. For a circle of radius r, approximately 2πr / maxSegmentLength segments will be used per full circle.

      This overload uses a default geometric tolerance of 1e-9. For coordinate systems with unusual magnitude, use union(List, double, double) to specify an appropriate tolerance.

      Parameters:
      circles - list of circles as Coordinates (x,y = center, z = radius)
      maxSegmentLength - maximum chord length for linearized arc segments
      Returns:
      Geometry (Polygon or MultiPolygon) representing the union
      Throws:
      IllegalArgumentException - if any circle has NaN radius
    • union

      public static org.locationtech.jts.geom.Geometry union(List<org.locationtech.jts.geom.Coordinate> circles, double maxSegmentLength, double eps)
      Computes the union of the given circles with specified geometric tolerance.

      This variant allows explicit control over the geometric tolerance eps, which governs coordinate snapping, duplicate circle detection, and intersection point deduplication. The tolerance should be chosen relative to the coordinate system magnitude and desired precision.

      The eps parameter affects:

      • Vertex snapping: points within eps are merged to a single node
      • Circle deduplication: circles with centers and radii within eps are treated as identical
      • Intersection detection: used as a numerical threshold in circle-circle relation tests
      Parameters:
      circles - list of circles as Coordinates (x,y = center, z = radius)
      maxSegmentLength - maximum chord length for linearized arc segments
      eps - geometric tolerance for snapping and intersection detection (typically 1e-9 to 1e-6)
      Returns:
      Geometry (Polygon or MultiPolygon) representing the union
      Throws:
      IllegalArgumentException - if any circle has NaN radius