curve2.networkFaces
The bounded faces of a network of segments, arcs and circles, each loop given as pieces of the input curves.
Usage
Curve2.networkFaces(edges: readonly Curve2[], tolerance: number): Result<NetworkFace[]>Parameters
edgesreadonly Curve2[]The network’s curves, in any order; they may cross, touch, overlap or dangle. A piece names a curve by its index here. Required. In model.
tolerancenumberThe largest distance between an arc or circle and the chords that stand for it while the faces are found; positive. Required. In model.
Returns
Ok with every bounded face: outer, the pieces of its boundary in order (counter-clockwise), holes, one list per hole (clockwise), and area. A piece is { edge, t0, t1, forward, start }: a stretch of curve edge from parameter t0 to t1, forward when t increases, starting at corner start. On a circle a forward piece with t1 ≤ t0 runs through t = 1 back to 0, and a lone circle is the one piece 0 → 1. An empty list when no curves close a loop.
Errors
Guarantees
- the outer loop winds counter-clockwise and every hole clockwise: the face is on the left of each piece
- every piece’s edge indexes edges, and consecutive pieces meet at the next piece’s start
- area > 0, and the areas of a network’s faces sum to the area it encloses (an n × m grid of unit cells gives n · m faces of area 1)
- dangling curves and bridges (a curve with the face on both sides) are in no loop; an island joined by a bridge is still a hole
- The same result on every machine.
Example
const s = (ax, ay, bx, by) => ({ kind: 'line', a: Point2.of(ax, ay), b: Point2.of(bx, by) })
const r = Curve2.networkFaces([s(0, 0, 1, 0), s(1, 0, 1, 1), s(1, 1, 0, 1), s(0, 1, 0, 0)], 1e-3)
r.ok ? r.value[0].area : Result.error(r).code // → 1, once loadGeometryKernel() has run