Constraints
Constraint statements declare relationships between the entities of a 2D sketch.
The coordinates written in line(), arc(), circle(), and point() statements
are guesses; the sketch solver moves the entities so every constraint holds.
Each statement appears in the timeline like any other feature.
import { coincident, horizontal, vertical, parallel, perpendicular, tangent, equal, concentric, collinear, midpoint, symmetric, fix, distance, angle, radius, diameter } from 'fluidcad/constraints';
Constraint targets
Every entity argument accepts a ConstraintTarget — one of the following forms:
| Form | Example | Description |
|---|---|---|
| Entity statement | const l = line([0, 0], [40, 0]); horizontal(l) | A SolvedLine, SolvedArc, SolvedCircle, or point() statement — the entity itself. |
| Point accessor | l.start(), l.end(), c.center() | A Vertex naming one of an entity's solver points. l.mid() is accepted by coincident() only (it lowers to the midpoint constraint). |
| Datum | origin(), xAxis(), yAxis() | The sketch plane's fixed origin point and infinite axis lines — see origin, xAxis, yAxis. |
| Fixed reference | project(bore), p.ref(i), p.ref(i).start() | A Reference from project()/intersect() — the statement itself when it produced exactly one edge, a ReferenceEntity via .ref(i), or one of their point accessors. |
Datums and fixed references never move. A constraint must reference at least one drawn (free) entity — a constraint over only fixed targets is an error. Cross-sketch targets are not supported.
Geometric constraints
coincident()
coincident(a: ConstraintTarget, b: ConstraintTarget): SceneObject
Makes two points coincide (2 dims), or puts a point on an entity (1 dim:
point-on-infinite-line, point-on-circle/arc). coincident(p, l.mid())
lowers to the midpoint constraint.
| Parameter | Type | Description |
|---|---|---|
a | ConstraintTarget | A point accessor, point statement, or entity |
b | ConstraintTarget | A point accessor, point statement, or entity |
horizontal()
horizontal(a: ConstraintTarget, b?: ConstraintTarget, ...rest: ConstraintTarget[]): SceneObject
Constrains a line to be horizontal, an ellipse's RX axis to run along the sketch X direction, or two or more points to share a y value. Every point after the first is aligned to the first.
| Parameter | Type | Description |
|---|---|---|
a | ConstraintTarget | A line, an ellipse, or the first point |
b | ConstraintTarget | The second point (point form) (optional) |
...rest | ConstraintTarget[] | Further points to align to the first |
vertical()
vertical(a: ConstraintTarget, b?: ConstraintTarget, ...rest: ConstraintTarget[]): SceneObject
Constrains a line to be vertical, an ellipse's RX axis to run along the sketch Y direction, or two or more points to share an x value. Every point after the first is aligned to the first.
| Parameter | Type | Description |
|---|---|---|
a | ConstraintTarget | A line, an ellipse, or the first point |
b | ConstraintTarget | The second point (point form) (optional) |
...rest | ConstraintTarget[] | Further points to align to the first |
parallel()
parallel(a: ConstraintTarget, b: ConstraintTarget, ...rest: ConstraintTarget[]): SceneObject
Constrains two or more lines to be parallel (1 dim per pair). Every line after the first is paralleled to the first.
| Parameter | Type | Description |
|---|---|---|
a | ConstraintTarget | The reference line |
b | ConstraintTarget | The second line |
...rest | ConstraintTarget[] | Further lines to parallel to the first |
perpendicular()
perpendicular(a: ConstraintTarget, b: ConstraintTarget): SceneObject
Constrains two lines to be perpendicular (1 dim).
| Parameter | Type | Description |
|---|---|---|
a | ConstraintTarget | The first entity |
b | ConstraintTarget | The second entity |
tangent()
tangent(a: ConstraintTarget, b: ConstraintTarget): SceneObject
Constrains two curves to be tangent (1 dim): a line and a circle/arc/ellipse, or any two of circle/arc/ellipse. The tangency side (internal vs external) is locked from the guess positions. Also accepts a fixed reference: tangent(bore, l) with a single-edge project() result.
| Parameter | Type | Description |
|---|---|---|
a | ConstraintTarget | The first entity |
b | ConstraintTarget | The second entity |
equal()
equal(a: ConstraintTarget, b: ConstraintTarget, ...rest: ConstraintTarget[]): SceneObject
Constrains two or more entities to be equal (1 dim per pair): equal line lengths or equal circle/arc radii. Every entity after the first is equated to the first.
| Parameter | Type | Description |
|---|---|---|
a | ConstraintTarget | The reference entity |
b | ConstraintTarget | The second entity |
...rest | ConstraintTarget[] | Further entities to equate to the first |
concentric()
concentric(a: ConstraintTarget, b: ConstraintTarget): SceneObject
Constrains two circles/arcs/ellipses to share a center (2 dims).
| Parameter | Type | Description |
|---|---|---|
a | ConstraintTarget | The first entity |
b | ConstraintTarget | The second entity |
collinear()
collinear(a: ConstraintTarget, b: ConstraintTarget): SceneObject
Constrains line b to lie on the infinite line of a (2 dims). The first slot also takes an axis datum: collinear(xAxis(), l).
| Parameter | Type | Description |
|---|---|---|
a | ConstraintTarget | The first entity |
b | ConstraintTarget | The second entity |
midpoint()
midpoint(p: ConstraintTarget, l: ConstraintTarget, b?: ConstraintTarget): SceneObject
Constrains point p to be the midpoint of line l — or, with three arguments, to sit halfway between points a and b (2 dims either way).
| Parameter | Type | Description |
|---|---|---|
p | ConstraintTarget | The point |
l | ConstraintTarget | The line whose midpoint p takes; with b given, the first of the two points |
b | ConstraintTarget | The second point, for the point-pair form midpoint(p, a, b) (optional) |
symmetric()
symmetric(a: ConstraintTarget, b: ConstraintTarget, l: ConstraintTarget): SceneObject
Constrains a and b to mirror across line l: two points (2 dims), or two entities of one kind — two lines (4), two circles (3: centers mirror, equal radii), two arcs (5: centers and starts mirror, the ends reflect), two ellipses (5: centers mirror, equal semi-radii, the RX axes reflect). The entity forms are what the sketch Mirror tool writes, one statement per mirrored entity.
| Parameter | Type | Description |
|---|---|---|
a | ConstraintTarget | The first point or entity |
b | ConstraintTarget | The second point or entity (same kind as a) |
l | ConstraintTarget | The mirror line — a sketched line or xAxis() / yAxis() |
fix()
fix(p: ConstraintTarget, position?: Point2DLike): SceneObject
Anchors a point in place (2 dims). Without an explicit position the point's current (guess) coordinates are captured at statement time.
| Parameter | Type | Description |
|---|---|---|
p | ConstraintTarget | The point to anchor |
position | Point2DLike | Optional explicit [x, y] anchor position (optional) |
Dimensions
distance()
distance(a: ConstraintTarget, b: ConstraintTarget, value: NumberParam, axis?: 'x' | 'y'): Distance
Distance dimension. Forms by what the targets resolve to: point–point
(optionally measured along one axis), point–line (perpendicular),
point–circle/arc (to the circumference), line–line (pair with parallel),
line–circle/arc (perpendicular to the circumference), circle–circle
(gap between circumferences). Circle/arc measurements take the NEAR
side of the circumference by default; chain .max() for the far side.
Returns: Distance
| Parameter | Type | Description |
|---|---|---|
a | ConstraintTarget | First point/entity |
b | ConstraintTarget | Second point/entity |
value | NumberParam | The distance value |
axis | 'x' | 'y' | Optional 'x' or 'y' to measure along one axis (point–point) (optional) |
angle()
angle(a: ConstraintTarget, b: ConstraintTarget, degrees: NumberParam): SceneObject
Dimensions the counterclockwise angle from line a to line b, in degrees
(0–360). Each argument is a line or one of its endpoint accessors, which
orients the line toward that endpoint — angle(l1, l2.start(), 45)
measures to l2 pointing at its start. A bare line points at its end.
There are no negative angles: a clockwise angle is the counterclockwise
angle of the swapped pair.
| Parameter | Type | Description |
|---|---|---|
a | ConstraintTarget | The first line, optionally oriented via .start()/.end() |
b | ConstraintTarget | The second line, optionally oriented via .start()/.end() |
degrees | NumberParam | The angle in degrees, 0 (inclusive) to 360 (exclusive) |
radius()
radius(c: ConstraintTarget, value: NumberParam, axis?: 'x' | 'y'): SceneObject
Dimensions the radius of a circle or arc, or one semi-radius of an
ellipse: radius(el, 20, 'x') sizes the RX axis, 'y' the RY axis
(the axis is required for an ellipse and refused elsewhere).
| Parameter | Type | Description |
|---|---|---|
c | ConstraintTarget | The circle, arc or ellipse |
value | NumberParam | The radius value |
axis | 'x' | 'y' | Ellipses only: which semi-radius, 'x' (RX) or 'y' (RY) (optional) |
diameter()
diameter(c: ConstraintTarget, value: NumberParam): SceneObject
Dimensions the diameter of a circle or arc.
| Parameter | Type | Description |
|---|---|---|
c | ConstraintTarget | The circle or arc |
value | NumberParam | The diameter value |