Skip to content
Docs
Reference

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).

ts

Line

An infinite line through point; direction is non-zero.

ts

Ray

A half-line from origin; direction is non-zero.

ts

Circle

A circle; radius >= 0.

ts

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.

ts

Plane

The world plane form: points p with dot(normal, p) === distance.

ts

Bounds

An axis-aligned box with min <= max on both axes.

ts

Polygon

Three or more points, implicitly closed. Concave and self-intersecting polygons are allowed; containment uses the even-odd rule.

ts

RayHit

A hit along a ray: the point and its distance from the origin.

ts

Functions

segment

Creates a segment.

ts

line

Creates a line.

ts

Throws: RangeError when direction is zero.

lineThrough

The line through a and b, directed from a to b.

ts

Throws: RangeError when a equals b.

ray

Creates a ray.

ts

Throws: RangeError when direction is zero.

circle

Creates a circle.

ts

Throws: RangeError when radius is negative.

bounds

Creates bounds.

ts

Throws: RangeError when a minimum exceeds its maximum.

plane

The plane through point with the given normal: { normal: unit, distance: dot(point, unit) }.

ts

Throws: RangeError when normal is zero.

arcFromCenter

The arc on the circle around center from startAngle, sweeping sweep radians in the positive-angle direction.

ts

Throws: RangeError unless radius > 0 and sweep ∈ (0, 2π).

arcCenter

The arc's circle center, computed exactly as the physics solver does.

ts

arcRadius

The arc's circle radius, computed exactly as the physics solver does.

ts

arcSweep

The swept angle 2 · atan2(1, curve) in (0, 2π).

ts

arcAngles

Angles of start and end around the center, each in (−π, π].

ts

arcLength

Arc length radius · sweep.

ts

segmentLength

Segment length.

ts

arcPointAt

The point at fraction t ∈ [0, 1] of the arc length; 0 and 1 return the exact endpoints.

ts

segmentPointAt

The point at fraction t ∈ [0, 1] of the segment; 0 and 1 return the exact endpoints.

ts

sampleArc

count >= 2 points evenly spaced along the arc, including both ends. An explicit approximation.

ts

regularPolygon

The vertices of a regular polygon; the first lies at angle rotation and the rest follow in the positive-angle direction.

ts

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).

ts

segmentIntersection

The crossing of two segments, or null when they are disjoint or parallel, including collinear overlap (see segmentOverlap). Shared endpoints are returned exactly.

ts

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.

ts

raySegmentIntersection

The nearest hit of a ray on a segment, or null.

ts

lineCircleIntersections

Line–circle crossings ordered along the line direction.

ts

segmentCircleIntersections

Segment–circle crossings ordered from seg.start.

ts

rayCircleIntersection

The nearest ray–circle hit, or null. An origin inside the circle gives the exit point.

ts

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 [].

ts

lineArcIntersections

Line–arc crossings ordered along the line direction.

ts

segmentArcIntersections

Segment–arc crossings ordered from seg.start.

ts

rayArcIntersection

The nearest ray–arc hit, or null.

ts

projectOnLine

The orthogonal projection of point onto the line.

ts

closestPointOnSegment

The point of the segment nearest to point.

ts

closestPointOnCircle

The point of the circle nearest to point, or null at the center.

ts

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).

ts

closestPointOnBounds

point clamped into the bounds (itself when inside).

ts

distanceToLine

Distance from point to the line.

ts

distanceToSegment

Distance from point to the segment.

ts

distanceToArc

Distance from point to the arc.

ts

signedDistanceToCircle

Distance from point to the circle; negative inside.

ts

signedDistanceToPlane

dot(normal, point) − distance with the normal normalized.

ts

Throws: RangeError when plane.normal is zero.

boundsOfPoints

The bounds of a list of points.

ts

Throws: RangeError on an empty list.

boundsOfSegment

The bounds of a segment.

ts

boundsOfCircle

The bounds of a circle.

ts

boundsOfPolygon

The bounds of a polygon.

ts

boundsOfArc

Exact arc bounds, including the axis extremes inside the sweep.

ts

unionBounds

The smallest bounds containing both.

ts

expandBounds

Bounds grown by margin on every side; a negative margin shrinks them.

ts

Throws: RangeError when shrinking would go below zero size.

boundsCenter

The center of the bounds.

ts

boundsSize

{ width, height } of the bounds.

ts

boundsOverlap

Whether two bounds overlap; touching edges count.

ts

circleContainsPoint

Whether the circle contains point, boundary included.

ts

boundsContainsPoint

Whether the bounds contain point, boundary included.

ts

polygonContainsPoint

Even-odd containment; a point on an edge counts as inside.

ts

circlesOverlap

Whether two circles overlap; touching counts.

ts

pointOnSegment

Whether point lies on the segment.

ts

pointOnArc

Whether point lies on the arc.

ts

polygonArea

Signed polygon area; positive when the vertices run in the positive-angle direction (clockwise on screen).

ts

polygonCentroid

The area centroid.

ts

Throws: RangeError for a polygon with zero area.