Skip to content

Allocation-free spherical_arc_intersection #418

Description

@briochemc

UnitSpherical.spherical_arc_intersection is correct (matches a hand-rolled d3 great-circle intersector on every case tried, including the degenerate zero-length-segment guard), but it returns an ArcIntersectionResult holding Vectors and builds a candidates vector, so each call heap-allocates (~4 allocations / 240 B). That blocks using it inside a tight edge×edge polygon-clip loop.

An allocation-free entry point — a small immutable result (type + ≤2 UnitSphericalPoints + a frac tuple, no Vectors), or an in-place variant — would let downstreams delegate the core spherical primitive.

using GeometryOps.UnitSpherical, BenchmarkTools
u = UnitSphereFromGeographic()
@btime spherical_arc_intersection($(u((0.,0.))), $(u((40.,0.))), $(u((20.,-20.))), $(u((20.,20.))))  # ~4 allocations: 240 bytes

Context: an in-review GeoMakie PR (MakieOrg/GeoMakie.jl#381) keeps an allocation-free hand-rolled great-circle intersector for its hot clip loop to work around this — released GeoMakie does not have or need this. (cf. #414, which adds an allocation cache for ConvexConvexSutherlandHodgman.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions