disko:geometry
Plain-data shapes, intersections, projections, bounds and containment.
Import with import { … } from "disko:geometry". Generated from the module's
shipped declarations. See Map geometry for a guide.
disko:geometry — plain-data shapes, intersections, projections, bounds and containment.
Every function is pure and deterministic. Comparisons are exact unless an opts argument supplies { epsilon }, which widens every boundary comparison by that absolute amount. Boundaries count as inside. Functions with zero to two answers return arrays ordered along the first argument; a tangency gives one point.
Types
Segment
A segment between two points, which may be equal (world.crossing form).
Line
An infinite line through point; direction is non-zero.
Ray
A half-line from origin; direction is non-zero.
Circle
A circle; radius >= 0.
Arc
A world-native arc, the data world.createSegment and segment.setCurve take. start and end differ. The center is midpoint(start, end) + perpendicular((end − start) / 2) · curve, and the arc runs from start to end in the positive-angle direction, sweeping θ ∈ (0, 2π) with curve = cot(θ / 2): 0 is a semicircle, positive curves are minor arcs and negative curves are major arcs.
Plane
The world plane form: points p with dot(normal, p) === distance.
Bounds
An axis-aligned box with min <= max on both axes.
Polygon
Three or more points, implicitly closed. Concave and self-intersecting polygons are allowed; containment uses the even-odd rule.
RayHit
A hit along a ray: the point and its distance from the origin.
Functions
segment
Creates a segment.
line
Creates a line.
Throws: RangeError when direction is zero.
lineThrough
The line through a and b, directed from a to b.
Throws: RangeError when a equals b.
ray
Creates a ray.
Throws: RangeError when direction is zero.
circle
Creates a circle.
Throws: RangeError when radius is negative.
bounds
Creates bounds.
Throws: RangeError when a minimum exceeds its maximum.
plane
The plane through point with the given normal: { normal: unit, distance: dot(point, unit) }.
Throws: RangeError when normal is zero.
arcFromCenter
The arc on the circle around center from startAngle, sweeping sweep radians in the positive-angle direction.
Throws: RangeError unless radius > 0 and sweep ∈ (0, 2π).
arcCenter
The arc's circle center, computed exactly as the physics solver does.
arcRadius
The arc's circle radius, computed exactly as the physics solver does.
arcSweep
The swept angle 2 · atan2(1, curve) in (0, 2π).
arcAngles
Angles of start and end around the center, each in (−π, π].
arcLength
Arc length radius · sweep.
segmentLength
Segment length.
arcPointAt
The point at fraction t ∈ [0, 1] of the arc length; 0 and 1 return the exact endpoints.
segmentPointAt
The point at fraction t ∈ [0, 1] of the segment; 0 and 1 return the exact endpoints.
sampleArc
count >= 2 points evenly spaced along the arc, including both ends. An explicit approximation.
regularPolygon
The vertices of a regular polygon; the first lies at angle rotation and the rest follow in the positive-angle direction.
Throws: RangeError unless sides is an integer >= 3 and radius > 0.
lineIntersection
The crossing of two lines, or null when they are parallel or coincident (unit directions whose cross product is within epsilon).
segmentIntersection
The crossing of two segments, or null when they are disjoint or parallel, including collinear overlap (see segmentOverlap). Shared endpoints are returned exactly.
segmentOverlap
The shared piece of two collinear segments, running from the point nearest a.start, or null when they are not collinear or do not overlap. A single shared point gives a zero-length segment.
raySegmentIntersection
The nearest hit of a ray on a segment, or null.
lineCircleIntersections
Line–circle crossings ordered along the line direction.
segmentCircleIntersections
Segment–circle crossings ordered from seg.start.
rayCircleIntersection
The nearest ray–circle hit, or null. An origin inside the circle gives the exit point.
circleIntersections
Circle–circle crossings. Walking around a in the positive-angle direction from the direction toward b.center, the first point comes first. Concentric circles give [].
lineArcIntersections
Line–arc crossings ordered along the line direction.
segmentArcIntersections
Segment–arc crossings ordered from seg.start.
rayArcIntersection
The nearest ray–arc hit, or null.
projectOnLine
The orthogonal projection of point onto the line.
closestPointOnSegment
The point of the segment nearest to point.
closestPointOnCircle
The point of the circle nearest to point, or null at the center.
closestPointOnArc
The point of the arc nearest to point: the radial projection inside the sweep, otherwise the nearer endpoint (start on a tie or at the center).
closestPointOnBounds
point clamped into the bounds (itself when inside).
distanceToLine
Distance from point to the line.
distanceToSegment
Distance from point to the segment.
distanceToArc
Distance from point to the arc.
signedDistanceToCircle
Distance from point to the circle; negative inside.
signedDistanceToPlane
dot(normal, point) − distance with the normal normalized.
Throws: RangeError when plane.normal is zero.
boundsOfPoints
The bounds of a list of points.
Throws: RangeError on an empty list.
boundsOfSegment
The bounds of a segment.
boundsOfCircle
The bounds of a circle.
boundsOfPolygon
The bounds of a polygon.
boundsOfArc
Exact arc bounds, including the axis extremes inside the sweep.
unionBounds
The smallest bounds containing both.
expandBounds
Bounds grown by margin on every side; a negative margin shrinks them.
Throws: RangeError when shrinking would go below zero size.
boundsCenter
The center of the bounds.
boundsSize
{ width, height } of the bounds.
boundsOverlap
Whether two bounds overlap; touching edges count.
circleContainsPoint
Whether the circle contains point, boundary included.
boundsContainsPoint
Whether the bounds contain point, boundary included.
polygonContainsPoint
Even-odd containment; a point on an edge counts as inside.
circlesOverlap
Whether two circles overlap; touching counts.
pointOnSegment
Whether point lies on the segment.
pointOnArc
Whether point lies on the arc.
polygonArea
Signed polygon area; positive when the vertices run in the positive-angle direction (clockwise on screen).
polygonCentroid
The area centroid.
Throws: RangeError for a polygon with zero area.