On this page
Methods · 31
get area(): numberThe enclosed area, or 0 for anything open.
get bounds(): Boxget boundsVertices(): Vec[]The four corners of Geometry2d.bounds.
get center(): Vecconstructor(opts: Geometry2dOptions)distanceToLineSegment(A: VecLike, B: VecLike, filters?: Geometry2dFilters): numberThe shortest distance from any point of this geometry to the segment A→B.
distanceToPoint(point: VecLike, hitInside?: boolean, filters?: Geometry2dFilters): numbergetArea(): numberThe enclosed area by the shoelace formula. Open geometry encloses nothing.
getBounds(): BoxThe bounds this geometry contributes to its shape. Memoized by bounds.
getBoundsVertices(): Vec[]getLength(_filters?: Geometry2dFilters): numberThe total length of the outline, walked vertex to vertex.
getSvgPathData(first?: boolean): stringThis geometry as one subpath of an SVG d attribute.
@param first - whether this is the first subpath in the d. A later one
starts with L rather than M, so it joins what came before instead of
lifting the pen.
abstract getVertices(filters?: Geometry2dFilters): Vec[]Flattened outline vertices in shape-local space.
hitTestLineSegment(A: VecLike, B: VecLike, distance?: number, filters?: Geometry2dFilters): booleanWhether the segment A→B comes within distance of this geometry.
hitTestPoint(point: VecLike, margin?: number, hitInside?: boolean, _filters?: Geometry2dFilters): booleanWhether point hits this geometry, within margin.
The interior counts when the shape is **filled**, or when the caller asks
for hitInside — the two are alternatives, not a requirement and a
refinement. hitInside means "count the interior of a HOLLOW shape too",
which is what a marquee or a drop target wants; it is not the only way the
interior is ever reachable.
This used to test hitInside alone, so a solid rectangle could not be
selected by clicking its middle — only its outline answered. Nothing failed
and nothing warned: every feature built on hit testing simply returned
nothing, which reads as several unrelated bugs rather than one.
An unfilled shape still misses in the middle. A hollow rectangle is a frame around empty space, and clicking the space inside it should reach whatever is behind.
ignoreHit(_point: VecLike): booleanWhether a hit at _point should be discarded even though it landed. The
default answer comes from the ignore flag; a subclass may look at where
the hit was.
interpolateAlongEdge(t: number, _filters?: Geometry2dFilters): VecThe point t of the way along the outline, t in [0, 1]. This is how a
label, a handle or an arrow terminal is placed a fixed fraction along a
shape's edge and stays there as the shape resizes.
intersectCircle(center: VecLike, radius: number, _filters?: Geometry2dFilters): VecLike[]intersectLineSegment(A: VecLike, B: VecLike, _filters?: Geometry2dFilters): VecLike[]intersectPolygon(polygon: VecLike[], _filters?: Geometry2dFilters): VecLike[]intersectPolyline(polyline: VecLike[], _filters?: Geometry2dFilters): VecLike[]isExcludedByFilter(filters?: Geometry2dFilters): booleanWhether filters says to skip this geometry.
isPointInBounds(point: VecLike, margin?: number): booleanWhether point lies within the bounding box, which is the cheap pre-test.
get length(): numberThe length of the outline — the perimeter, for anything closed.
nearestPoint(point: VecLike, _filters?: Geometry2dFilters): VecoverlapsPolygon(_polygon: VecLike[]): booleanWhether _polygon overlaps this geometry at all — including the case where
one lies entirely within the other, which no edge crossing would reveal.
abstract toPathWords(): number[]Serialize to the engine's flat path encoding.
toSimpleSvgPath(): stringThe whole geometry as a standalone SVG path d.
transform(transform: MatModel, opts?: TransformedGeometry2dOptions): Geometry2dThis geometry seen through transform — the form a parent needs when it
asks a child for its outline in the parent's own space. The result is a view
onto this geometry, not a copy of it, so transforming is cheap.
uninterpolateAlongEdge(point: VecLike, _filters?: Geometry2dFilters): numberThe inverse of Geometry2d.interpolateAlongEdge: how far along the
outline the nearest point to point sits, as a t in [0, 1].
get vertices(): Vec[]Properties · 8
readonly debugColor: string | undefinedreadonly excludeFromShapeBounds: booleanreadonly ignore: booleanreadonly isClosed: booleanreadonly isEmptyLabel: booleanreadonly isFilled: booleanreadonly isInternal: booleanreadonly isLabel: booleanmocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.