Shapemetry API / Shape2d
Class: Shape2d
Defined in: curve2d/Shape2d.ts:305
A single 2D curve loop and the bridge between 2D and 3D. Implements the shared curve interface. Used as sketch plane, section plane, or NURBS UV space, then transformed into 3D.
Implements
Constructors
Constructor
new Shape2d(
segments?):Shape2d
Defined in: curve2d/Shape2d.ts:308
Parameters
segments?
ShapeSegment2d[] = []
Returns
Shape2d
Properties
segments
segments:
ShapeSegment2d[]
Defined in: curve2d/Shape2d.ts:306
Accessors
start
Get Signature
get start():
Point2d
Defined in: curve2d/Shape2d.ts:310
Returns
Implementation of
end
Get Signature
get end():
Point2d
Defined in: curve2d/Shape2d.ts:311
Returns
Implementation of
isClosed
Get Signature
get isClosed():
boolean
Defined in: curve2d/Shape2d.ts:312
Returns
boolean
Implementation of
Methods
toJSON()
toJSON():
Shape2dJSON
Defined in: curve2d/Shape2d.ts:317
Returns
Implementation of
fromPoints()
staticfromPoints(points,isClosed?):Shape2d
Defined in: curve2d/Shape2d.ts:320
Build a shape from a polyline (sequence of points), as chained LineSegment2d.
Parameters
points
Point2d[]
isClosed?
boolean = false
Returns
Shape2d
line()
staticline(start,end):Shape2d
Defined in: curve2d/Shape2d.ts:330
Single LineSegment2d shape.
Parameters
start
end
Returns
Shape2d
fromNurbsCurve()
staticfromNurbsCurve(curve):Shape2d
Defined in: curve2d/Shape2d.ts:347
Wrap a (planar, z≈0) NURBS curve as a Shape2d losslessly by decomposing it into its constituent Bezier spans — one segment per span — preserving the exact curvature (no polyline/chord approximation).
Each Bezier span maps to a native ShapeSegment2d: degree 1 → LineSegment2d, degree 2 → QuadraticBezier2d, degree 3 → CubicBezier2d. Degree-0/1 curves (and degree < 2 spans) are emitted as line segments. Splines of degree > 3 (rare; NurbsCurve.spline clamps to point count) cannot be represented as an exact cubic, so such a span is emitted as a cubic that matches the span endpoints and end tangents — far tighter than the old fixed 0.1 chord polyline.
Parameters
curve
Returns
Shape2d
catmullRom()
staticcatmullRom(points):Shape2d
Defined in: curve2d/Shape2d.ts:398
Catmull-Rom spline through points → chain of cubic Béziers (one per span). Tangent at each interior point: (P[i+1] - P[i-1]) / 6. Endpoints: clamped. Returns line if 2 points, empty Shape2d if fewer.
Parameters
points
Point2d[]
Returns
Shape2d
lastEnd()
lastEnd():
Point2d|undefined
Defined in: curve2d/Shape2d.ts:418
Returns
Point2d | undefined
addCurve()
addCurve(
seg):Shape2d
Defined in: curve2d/Shape2d.ts:420
Parameters
seg
Returns
Shape2d
close()
close():
Shape2d
Defined in: curve2d/Shape2d.ts:424
Returns
Shape2d
length()
length():
number
Defined in: curve2d/Shape2d.ts:431
Returns
number
Implementation of
boundingBox()
boundingBox():
BoundingBox2d
Defined in: curve2d/Shape2d.ts:437
Returns
Implementation of
reverse()
reverse():
Shape2d
Defined in: curve2d/Shape2d.ts:444
Returns
Shape2d
Implementation of
toPolyline()
toPolyline(
chordTolerance):Point2d[]
Defined in: curve2d/Shape2d.ts:451
Sample shape to a polyline (sequence of points). Closed shapes do NOT repeat the first point at the end.
Parameters
chordTolerance
number
Returns
Point2d[]
signedArea()
signedArea():
number
Defined in: curve2d/Shape2d.ts:459
Returns
number
transform()
transform(
m):Shape2d
Defined in: curve2d/Shape2d.ts:472
Parameters
m
Returns
Shape2d
Implementation of
clone()
clone():
Shape2d
Defined in: curve2d/Shape2d.ts:476
Returns
Shape2d
Implementation of
toNurbsCurve()
toNurbsCurve():
NurbsCurve
Defined in: curve2d/Shape2d.ts:478
Returns
pointAt()
pointAt(
t):Point2d
Defined in: curve2d/Shape2d.ts:480
Parameters
t
number
Returns
Implementation of
tangentAt()
tangentAt(
t):Vector2d
Defined in: curve2d/Shape2d.ts:485
Parameters
t
number
Returns
Implementation of
axesAtParam()
axesAtParam(
t):Axes2d
Defined in: curve2d/Shape2d.ts:491
Parameters
t
number
Returns
Implementation of
lengthAt()
lengthAt(
t):number
Defined in: curve2d/Shape2d.ts:496
Parameters
t
number
Returns
number
Implementation of
paramAtLength()
paramAtLength(
s):number
Defined in: curve2d/Shape2d.ts:497
Parameters
s
number
Returns
number
Implementation of
closestPoint()
closestPoint(
p):Point2d
Defined in: curve2d/Shape2d.ts:499
Parameters
p
Returns
Implementation of
splitAt()
splitAt(
t): [Shape2d,Shape2d]
Defined in: curve2d/Shape2d.ts:504
Parameters
t
number
Returns
[Shape2d, Shape2d]
Implementation of
fillet()
fillet(
radius,vertexFilter?):Shape2d
Defined in: curve2d/Shape2d.ts:512
Parameters
radius
number
vertexFilter?
((p, i) => boolean) | null
Returns
Shape2d
chamfer()
chamfer(
distance,vertexFilter?):Shape2d
Defined in: curve2d/Shape2d.ts:538
Parameters
distance
number
vertexFilter?
((p, i) => boolean) | null
Returns
Shape2d
_modifyCorners()
_modifyCorners(
makeCut,vertexFilter):Shape2d
Defined in: curve2d/Shape2d.ts:559
Parameters
makeCut
(vertex, previous, next) => { pointBefore: Point2d; pointAfter: Point2d; seg: ShapeSegment2d; } | null
vertexFilter
((p, i) => boolean) | null
Returns
Shape2d
offset()
offset(
distance,chordTolerance?,joinType?):Shape2d|null
Defined in: curve2d/Shape2d.ts:595
Lateral offset of an open shape by distance (positive = right of direction). Returns one offset shape (the picked side), or null if degenerate. Samples to a polyline first then runs Clipper inflate with butt caps.
Parameters
distance
number
chordTolerance?
number = 0.5
joinType?
JoinType = JoinType.Miter
Returns
Shape2d | null
thicken()
thicken(
distance,chordTolerance?,joinType?,endType?):Shape2d[]
Defined in: curve2d/Shape2d.ts:656
Thicken open shape → closed polygons (one outer + optional holes).
Parameters
distance
number
chordTolerance?
number = 0.5
joinType?
JoinType = JoinType.Round
endType?
EndType = EndType.Round
Returns
Shape2d[]
fitCurve()
staticfitCurve(points,tolerance,minArcPoints?,maxArcRadius?):Shape2d
Defined in: curve2d/Shape2d.ts:683
Fit a polyline of sampled points into a Shape2d of LineSegment2d / Ellipse2d / CubicBezier2d.
Two-pass arc-first segmentation:
- Enumerate maximal arc candidates via incremental algebraic LSQ circle fit at each start index.
- Greedy non-overlap selection (longest first, endpoint-sharing allowed).
- Fill gaps: line if straight-within-tol, otherwise Schneider cubic-bezier fit (Graphics Gems 1990) with arc-derived G1 tangents at boundaries.
Parameters
points
Point2d[]
tolerance
number
squared deviation accepted both for circle membership and bezier max-error.
minArcPoints?
number = 4
minimum points required to form an arc (default 4).
maxArcRadius?
number = 1e6
circles wider than this are treated as lines (default 1e6).
Returns
Shape2d
offset()
staticoffset(shapes,distance,endType?):Shape2d[]
Defined in: curve2d/Shape2d.ts:716
Inflate closed/open shapes by distance. Closed → polygon offset; open → stroke with chosen end type.
Parameters
shapes
Shape2d[]
distance
number
endType?
OffsetEndType = 'round'
Returns
Shape2d[]
thicken()
staticthicken(shapes,distance,joinType?,endType?,miterLimit?):Shape2d[]
Defined in: curve2d/Shape2d.ts:757
Stroke around shapes with distance (open paths capped, closed paths joined). Merges connected open paths first.
Parameters
shapes
Shape2d[]
distance
number
joinType?
OffsetJoinType = 'round'
endType?
OffsetEndType = 'round'
miterLimit?
number = 4
Returns
Shape2d[]