@margoengine/brep 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +14 -0
  3. package/README.md +200 -2
  4. package/dist/geometry/curves.d.ts +31 -0
  5. package/dist/geometry/exact.d.ts +6 -0
  6. package/dist/geometry/nurbs.d.ts +35 -0
  7. package/dist/geometry/read.d.ts +22 -0
  8. package/dist/geometry/surfaces.d.ts +75 -0
  9. package/dist/geometry/vec.d.ts +33 -0
  10. package/dist/iges/file.d.ts +66 -0
  11. package/dist/iges/geometry.d.ts +148 -0
  12. package/dist/iges/shapes.d.ts +30 -0
  13. package/dist/iges/step.d.ts +19 -0
  14. package/dist/index.d.ts +90 -0
  15. package/dist/index.js +16185 -0
  16. package/dist/jt/codec.d.ts +29 -0
  17. package/dist/jt/file.d.ts +70 -0
  18. package/dist/jt/lsg.d.ts +82 -0
  19. package/dist/jt/lzma.d.ts +22 -0
  20. package/dist/jt/mesh.d.ts +17 -0
  21. package/dist/jt/read.d.ts +68 -0
  22. package/dist/mesh/cdt.d.ts +41 -0
  23. package/dist/mesh/tessellate.d.ts +106 -0
  24. package/dist/mesh/validate.d.ts +45 -0
  25. package/dist/model/blend.d.ts +38 -0
  26. package/dist/model/boolean.d.ts +37 -0
  27. package/dist/model/build.d.ts +75 -0
  28. package/dist/model/check.d.ts +8 -0
  29. package/dist/model/distance.d.ts +28 -0
  30. package/dist/model/export.d.ts +17 -0
  31. package/dist/model/faces.d.ts +183 -0
  32. package/dist/model/geometry.d.ts +103 -0
  33. package/dist/model/import.d.ts +30 -0
  34. package/dist/model/index.d.ts +27 -0
  35. package/dist/model/intersect.d.ts +28 -0
  36. package/dist/model/loft.d.ts +12 -0
  37. package/dist/model/march.d.ts +20 -0
  38. package/dist/model/mass.d.ts +28 -0
  39. package/dist/model/offset-surface.d.ts +16 -0
  40. package/dist/model/offset.d.ts +39 -0
  41. package/dist/model/seams.d.ts +26 -0
  42. package/dist/model/setback.d.ts +12 -0
  43. package/dist/model/sew.d.ts +47 -0
  44. package/dist/model/sweep.d.ts +37 -0
  45. package/dist/model/topology.d.ts +116 -0
  46. package/dist/model/validate.d.ts +16 -0
  47. package/dist/sat/read.d.ts +16 -0
  48. package/dist/step/file.d.ts +82 -0
  49. package/dist/step/structure.d.ts +131 -0
  50. package/dist/step/write.d.ts +57 -0
  51. package/dist/xt/read.d.ts +22 -0
  52. package/dist/xt/schema.d.ts +18 -0
  53. package/dist/xt/step.d.ts +19 -0
  54. package/package.json +50 -4
@@ -0,0 +1,28 @@
1
+ import { type XYZ } from '../geometry/vec.js';
2
+ import { type CurveDef, type SurfaceDef } from './geometry.js';
3
+ /**
4
+ * The nearest place on a spline surface to `p`: its (u, v), point and unit normal; found from where the last point
5
+ * landed, or (`fresh`) by the surface's own search.
6
+ */
7
+ export declare function splineFoot(s: SurfaceDef, p: XYZ, fresh?: boolean): {
8
+ uv: [number, number];
9
+ q: XYZ;
10
+ n: XYZ;
11
+ };
12
+ /** Signed distance from `p` to a surface along its natural normal (positive on the normal's side). */
13
+ export declare function signedDistance(s: SurfaceDef, p: XYZ): number;
14
+ /** Gradient of the signed distance at `p`: the unit surface normal there, on the surface's natural side. */
15
+ export declare function distanceGradient(s: SurfaceDef, p: XYZ): XYZ;
16
+ /** The unit direction of the curve two surfaces meet in at `p` (undefined where they touch tangentially). */
17
+ export declare function meetDirection(a: SurfaceDef, b: SurfaceDef, p: XYZ): XYZ | undefined;
18
+ /** A bound on the curve's speed |C'(t)|, so on the signed distance's rate of change along it (distances change no faster than the point moves). */
19
+ export declare function speedBound(curve: CurveDef): number;
20
+ /**
21
+ * Parameters in [t0, t1] where the curve crosses the surface (its signed distance changes sign), each found to the
22
+ * last bit. Intervals are split until each either provably holds no crossing or is shorter than `resolution` (a
23
+ * distance; default 1e-9 of the curve's length), so no crossing is missed however close to another; a touch counts
24
+ * twice and stretches lying on the surface count none. An interval holds no crossing when the distance at its ends is
25
+ * more than the curve can travel between them, or, near a touch (where the distance grows with the square of the
26
+ * parameter and that test fails down to `resolution`), more than the distance's second derivative can bend it back by.
27
+ */
28
+ export declare function curveSurfaceCrossings(curve: CurveDef, surface: SurfaceDef, t0: number, t1: number, resolution?: number): number[];
@@ -0,0 +1,17 @@
1
+ import type { STEPModel } from '../index.js';
2
+ import { type BodyMesh, type TessellationOptions } from '../mesh/tessellate.js';
3
+ import type { Body, Name } from './topology.js';
4
+ /**
5
+ * An AP214 STEP file of the bodies, in metres. Faces on closed surfaces that go round them are cut open along the
6
+ * surface's seam, with a seam edge (and on a sphere, vertices at the poles it covers), as CAD readers expect.
7
+ */
8
+ export declare function bodiesToSTEP(bodies: readonly Body[]): string;
9
+ /** Meshes of bodies through STEP, with each mesh face run's persistent face name. */
10
+ export interface BodyMeshes {
11
+ readonly model: STEPModel;
12
+ readonly meshes: BodyMesh[];
13
+ /** The persistent name of the face a mesh run (`mesh.faces[i].id`) belongs to. */
14
+ faceName(id: number): Name | undefined;
15
+ }
16
+ /** Tessellates bodies with the kernel's tessellator (`options` as for tessellateSTEP). */
17
+ export declare function meshBodies(bodies: readonly Body[], options?: TessellationOptions): BodyMeshes;
@@ -0,0 +1,183 @@
1
+ import type { Curve } from '../geometry/curves.js';
2
+ import { type Surface } from '../geometry/surfaces.js';
3
+ import { type XYZ } from '../geometry/vec.js';
4
+ import type { Edge, Face } from './topology.js';
5
+ export type UV = [number, number];
6
+ /** A closed loop in (u', v): points in order, the last joined back to the first moved by `wrap` periods in u'. */
7
+ export interface UVLoop {
8
+ readonly points: UV[];
9
+ /** Whole periods the loop goes round in u' (a loop round a cylinder: 1 or -1). */
10
+ readonly wrap: number;
11
+ /**
12
+ * A slit: a loop of edges each run both ways, through no pole and not round the period, so it bounds nothing (a seam
13
+ * from near one pole to near the other, run up and back). The face lies all round it, as round a hole.
14
+ */
15
+ readonly slit?: boolean;
16
+ /**
17
+ * The loop's signed area with each edge's curve end put in where it is apart from the next edge's start (at a
18
+ * tolerant vertex), when that differs from the points'; its sign is the loop's sense.
19
+ */
20
+ readonly area?: number;
21
+ }
22
+ /** Samples per edge in (u, v): a line maps to a straight line on the surfaces Booleans take; a curve takes enough points to follow its turn. */
23
+ export declare const edgeSamples: (edge: Edge) => 1 | 128;
24
+ /**
25
+ * Whether a face's u and v are swapped so its loops can go round in u': always on a surface closed in v only (a ruled
26
+ * band round in v); on one closed both ways, when closed loops through these points go round it in v (a torus cut
27
+ * through its axis: round its tube). Throws a RangeError for a loop that goes round both ways (a helix's thread across a torus).
28
+ */
29
+ export declare function roundV(s: Surface, loops: readonly (readonly XYZ[])[], name: string): boolean;
30
+ export declare class FaceUV {
31
+ #private;
32
+ readonly face: Face;
33
+ readonly surface: Surface;
34
+ /** The face's own surface (`surface` is it with u and v swapped when its loops go round a torus's tube). */
35
+ readonly raw: Surface;
36
+ /** Whether u and v are swapped: the face's loops go round in v of its own surface. */
37
+ readonly swapped: boolean;
38
+ /** The face's sense against `surface`'s natural normal (reversed when u and v are swapped). */
39
+ readonly sense: boolean;
40
+ /** u is mirrored (u' = -u) when the face normal is the reverse of the surface's natural normal. */
41
+ readonly flip: boolean;
42
+ /** The u' period (0 when u is open). */
43
+ readonly period: number;
44
+ readonly loops: UVLoop[];
45
+ /** The loops' (u', v) bounds: [u0, u1, v0, v1]. */
46
+ readonly box: [number, number, number, number];
47
+ /**
48
+ * On a surface closed in v as well (a torus): where its tube is cut open, a v no loop crosses and outside the face,
49
+ * so v runs from here one period on and the face's loops and points lie in that range.
50
+ */
51
+ vCut: number;
52
+ /** Whether the face contains the circle at `vCut` (a torus with holes): its v then runs the whole period from it. */
53
+ cutInside: boolean;
54
+ /**
55
+ * Where a loop runs through a pole or apex (a cone's sector, a sphere's lune): there u has no meaning, so the loop
56
+ * runs along the pole's line at v (its points `at` and `at + 1`) from the u' it arrives with to the u' it leaves with.
57
+ * `from` and `to` are those exactly: the meridians its edges run along into and out of the pole, where the loop's
58
+ * points take the samples beside it (an edge that is not a meridian drifts off its meridian on the way).
59
+ */
60
+ readonly poleLines: {
61
+ loop: number;
62
+ at: number;
63
+ v: number;
64
+ from: number;
65
+ to: number;
66
+ }[];
67
+ /** `swapped` takes u and v swapped or not (for loops traced later); by default, as the face's own loops need. */
68
+ constructor(face: Face, swapped?: boolean);
69
+ /**
70
+ * Where a curve passes through one of the poles strictly between parameters t0 and t1 (not at either end, where the
71
+ * sample itself is at the pole): the parameter there, found as the least distance to the pole by golden section once
72
+ * the chord passes near it. Undefined when it does not reach a pole (within the distance at which points are at it).
73
+ */
74
+ overPole(curve: Curve, t0: number, t1: number, poles: readonly number[][]): number | undefined;
75
+ /**
76
+ * An edge's curve as the face's loops follow it: the curve itself, or where it ends or passes within a pole's reach
77
+ * (`poleReach`) but not at it, the curve taken through the pole. An imported vertex lies a little off a pole (within
78
+ * its tolerance), and an edge passes a little off one: within that distance of the pole it turns round it, by up to
79
+ * half a turn in u. The loop counts the point at the pole, its line running from the meridian the edge comes in along
80
+ * to the one it leaves along; a walk along the edge itself counted the turn as well, or part of it, as finely as it
81
+ * sampled there (a spline sphere's seam tilted 1e-9 rad came out 25% low). So the curve is moved by the offset from
82
+ * the pole of its end there, and of its nearest point where it passes one, in full there and less in proportion to the
83
+ * parameter towards the next such point or end: it reaches each pole along a meridian, with no turn. `kinks` are the
84
+ * passes' parameters, where it turns at the pole (a walk along it breaks there). Mass integrals take the strip from
85
+ * its feet out to the edge itself, so the shell still closes along the edge.
86
+ */
87
+ edgeCurve(edge: Edge): Curve;
88
+ /** `edgeCurve`, the edge's own curve (the same object where it is not moved), and where it passes a pole. */
89
+ edgeCurves(edge: Edge): {
90
+ curve: Curve;
91
+ edge: Curve;
92
+ kinks: number[];
93
+ };
94
+ /**
95
+ * Parameters along a curve (ascending or descending), more between them where it passes a pole of the surface nearer
96
+ * than they lie apart. Round a pole u' turns as fast as the curve passes it is near: an edge from a vertex 0.8
97
+ * micrometres off a 4 mm sphere's pole (just past `poleReach`) turns up to half a turn round it within about that, so
98
+ * its samples a 128th of the edge apart left u' jumping by over a quarter turn between two (refused as a loop over the
99
+ * pole), or by nearly half, read the wrong way round (a loop round the pole read as one beside it), and a walk's
100
+ * nodes missed its turn. Cut in halves until each part is no longer than its distance from the pole: u' turns by
101
+ * under 60 degrees along it, smoothly. A part that reaches a pole (within `poleReach`: into a pole vertex, or over a
102
+ * pole, where the loop runs along its line) is not cut for it; nor past 48 halvings.
103
+ */
104
+ graded(curve: Curve, ts: readonly number[]): number[];
105
+ /**
106
+ * A loop through points of the surface, in order: continuous (u', v) points, running along a pole's line where it
107
+ * passes through a pole or apex (`lines`: the first point of each such line, and the samples just before and just
108
+ * after the line), and growing the face's box.
109
+ */
110
+ trace(samples: readonly XYZ[]): {
111
+ loop: UVLoop;
112
+ lines: {
113
+ at: number;
114
+ before: number;
115
+ after: number;
116
+ }[];
117
+ };
118
+ /**
119
+ * A loop from continuous (u', v) points: how many periods it goes round, from where its start falls when reached again.
120
+ * `onPoles` are the points of its pole lines; the face's box grows to take the points unless `grow` is false.
121
+ */
122
+ close(points: UV[], onPoles?: ReadonlySet<number>, grow?: boolean): {
123
+ points: UV[];
124
+ wrap: number;
125
+ };
126
+ /**
127
+ * `out` moved by whole turns so a pole's line at v from `from` runs the way the face lies. The face lies below the line
128
+ * at the high pole and above it at the low one, and on the left of the loop, so the line runs towards -u' at the high
129
+ * pole and +u' at the low, by more than none and at most a whole turn (a loop up a seam to an apex and back down runs a
130
+ * whole turn round it). Rounding to the nearer u' would pick a side at random for half a turn (a hemisphere cut
131
+ * through both poles) and the wrong one beyond it.
132
+ */
133
+ lineEnd(v: number, from: number, out: number): number;
134
+ /**
135
+ * The u' of the meridian along which a curve meets the pole at `hint`'s v, at its parameter t, coming from or going
136
+ * on to parameter `toward`: the limit there, moved by whole periods next to `hint`. Where u is the angle about an axis
137
+ * through the pole (a sphere, a cone's apex), that is the angle of the curve's tangent itself. Elsewhere, u' from two
138
+ * short steps along the curve, extrapolated to the pole (it drifts in proportion to the step).
139
+ */
140
+ meridian(curve: Curve, t: number, toward: number, hint: UV): number;
141
+ /** The points of the surface's poles and apexes. */
142
+ get polePoints(): readonly (readonly number[])[];
143
+ /** How near a pole a point is at it (`poleOf`): a ten-thousandth of the face's size. */
144
+ get poleReach(): number;
145
+ /**
146
+ * Whether `p` lies at a pole or apex to within a billionth of the face's size, where a foot's u' is no more than its
147
+ * projection's rounding (an edge taken through a pole by `edgeCurve` reaches it exactly).
148
+ */
149
+ atPole(p: readonly number[]): boolean;
150
+ /** Where `p` is a pole or apex: the v of one where u has no meaning, or the u' of one where v has none. */
151
+ poleOf(p: XYZ): {
152
+ v: number;
153
+ } | {
154
+ u: number;
155
+ } | undefined;
156
+ /** (u', v) of a point on the surface, its u (and v) moved by whole periods next to `hint` when given. */
157
+ near(p: XYZ, hint?: UV): UV;
158
+ /**
159
+ * The foot uv of p to the last digits the surface's evaluation holds. A spline's projection stops once its steps move
160
+ * the foot under a millionth of a millionth of the surface's size, and near a pole (Su almost nothing) that leaves u'
161
+ * off by that over the distance to the pole: 1e-10 of a turn 8 micrometres from it on a 4 mm sphere. Mass integrals
162
+ * weigh u' there by the whole meridian's integral (a seam's rates moved a sphere's volume by 3e-10, a pole's line from
163
+ * an edge's meridian by 8e-11). Gauss-Newton steps on from it while they shrink (it converges in two), never past an
164
+ * open parameter's end (a foot held there stays). The surface is left evaluated at the foot.
165
+ */
166
+ exact(p: readonly number[], uv: UV): UV;
167
+ /** The 3D point at (u', v). */
168
+ at(uv: UV): XYZ;
169
+ /** The face normal (out of its solid) at a point of the face. */
170
+ normal(p: XYZ): XYZ;
171
+ /** Whether a point of the surface lies inside the face: left of every loop (a face with no loops is the whole surface). */
172
+ contains(p: XYZ): boolean;
173
+ }
174
+ /** Whether (u, v) lies on the left of a loop: inside a counter-clockwise one, outside a clockwise one, on the side a loop round the period turns to. */
175
+ export declare function leftOf(loop: UVLoop, period: number, u: number, v: number): boolean;
176
+ /** Parameters `ts` (ascending or descending) with `breaks` among them added in order (those strictly inside). */
177
+ export declare function withBreaks(ts: readonly number[], breaks: readonly number[]): number[];
178
+ /** The v extent of a loop. */
179
+ export declare function vRange(loop: UVLoop): [number, number];
180
+ /** The loop moved by whole periods in v so it starts at or above `cut` (it lies below `cut` + period when no part crosses the cut). */
181
+ export declare function shiftV(loop: UVLoop, cut: number, period: number): UVLoop;
182
+ /** Middles of the stretches of a periodic coordinate that none of the ranges covers, widest first. */
183
+ export declare function gaps(ranges: readonly (readonly [number, number])[], period: number): number[];
@@ -0,0 +1,103 @@
1
+ import { type Curve } from '../geometry/curves.js';
2
+ import type { Frame } from '../geometry/read.js';
3
+ import { type Surface } from '../geometry/surfaces.js';
4
+ import { type XYZ } from '../geometry/vec.js';
5
+ import type { StepWriter, WriterSpline } from '../step/write.js';
6
+ export type { Frame };
7
+ /** A surface: its kind and defining values. Every surface's natural normal is Su x Sv. */
8
+ export type SurfaceDef = {
9
+ readonly kind: 'plane';
10
+ readonly frame: Frame;
11
+ }
12
+ /** Normal pointing away from the axis. */
13
+ | {
14
+ readonly kind: 'cylinder';
15
+ readonly frame: Frame;
16
+ readonly radius: number;
17
+ }
18
+ /** Radius at the frame origin, growing along +z by tan(angle). */
19
+ | {
20
+ readonly kind: 'cone';
21
+ readonly frame: Frame;
22
+ readonly radius: number;
23
+ readonly angle: number;
24
+ } | {
25
+ readonly kind: 'sphere';
26
+ readonly frame: Frame;
27
+ readonly radius: number;
28
+ } | {
29
+ readonly kind: 'torus';
30
+ readonly frame: Frame;
31
+ readonly major: number;
32
+ readonly minor: number;
33
+ } | ({
34
+ readonly kind: 'spline';
35
+ readonly uClosed?: boolean;
36
+ readonly vClosed?: boolean;
37
+ } & WriterSpline);
38
+ /** A curve: its kind and defining values. */
39
+ export type CurveDef =
40
+ /** `direction` is a unit vector; the parameter is the distance from `origin`. */
41
+ {
42
+ readonly kind: 'line';
43
+ readonly origin: XYZ;
44
+ readonly direction: XYZ;
45
+ }
46
+ /** Counter-clockwise about frame z from frame x. */
47
+ | {
48
+ readonly kind: 'circle';
49
+ readonly frame: Frame;
50
+ readonly radius: number;
51
+ } | {
52
+ readonly kind: 'ellipse';
53
+ readonly frame: Frame;
54
+ readonly a: number;
55
+ readonly b: number;
56
+ } | ({
57
+ readonly kind: 'spline';
58
+ readonly closed?: boolean;
59
+ } & WriterSpline);
60
+ /** An orthonormal frame at `origin` with axis `z` and x towards `x` (any perpendicular when omitted or parallel). */
61
+ export declare function frameOf(origin: XYZ, z: XYZ, x?: XYZ): Frame;
62
+ /** The kernel evaluator of a surface (cached per definition object). */
63
+ export declare function surfaceEvaluator(def: SurfaceDef): Surface;
64
+ /** The kernel evaluator of a curve (cached per definition object). */
65
+ export declare function curveEvaluator(def: CurveDef): Curve;
66
+ /**
67
+ * Whether `p` lies farther than `gap` from every point of a B-spline curve, judged by its control points' box (the curve
68
+ * lies inside it while every weight is positive). False for other curves, where a projection is cheap anyway.
69
+ */
70
+ export declare function apart(def: CurveDef, p: readonly number[], gap: number): boolean;
71
+ /**
72
+ * The stretch [a, b] of a B-spline curve as a curve of its own, exactly (knots inserted at a and b until the curve
73
+ * passes through its control points there, Boehm's algorithm, in homogeneous coordinates for rational curves). On a
74
+ * closed curve b may run past the domain's end: the two stretches either side of its seam are joined. An end within
75
+ * 1e-9 of the domain of a knot is that knot (a span a rounding error long would leave the curve undefined there).
76
+ * Other curves are returned as they are.
77
+ */
78
+ export declare function sliceCurve(def: CurveDef, a: number, b: number): CurveDef;
79
+ /** Writes a surface as STEP and returns its id. */
80
+ export declare function writeSurface(w: StepWriter, def: SurfaceDef): string;
81
+ /** Writes a curve as STEP and returns its id. */
82
+ export declare function writeCurve(w: StepWriter, def: CurveDef): string;
83
+ type SplineCurveDef = Extract<CurveDef, {
84
+ kind: 'spline';
85
+ }>;
86
+ /**
87
+ * A curve as a B-spline tracing the same points the same way: a B-spline as it is; a line from parameter t0 to t1 as
88
+ * one span of degree 1; a whole circle or ellipse from its frame's x, counter-clockwise about its z, as four rational
89
+ * quadratic arcs (the ellipse an affine image of the circle's, so exact as well).
90
+ */
91
+ export declare function splineOf(c: CurveDef, t0?: number, t1?: number): SplineCurveDef;
92
+ /**
93
+ * A B-spline curve C(u) swept along the unit vector d from v0 to v1, S(u, v) = C(u) + v d, as a B-spline surface of
94
+ * degree 1 in v (ISO 10303-42's surface of linear extrusion, its v measured along d). Closed in u where C is.
95
+ */
96
+ export declare function extrudedSurface(c: SplineCurveDef, d: XYZ, v0: number, v1: number): SurfaceDef;
97
+ /**
98
+ * A B-spline curve C(v) turned a whole turn about the axis through o along the unit vector z, counter-clockwise about
99
+ * z as u grows (ISO 10303-42's surface of revolution, u the turn), exactly: each control point's circle as rational
100
+ * quadratic arcs, its weight times theirs. Turning every control point by one angle turns the curve by it, so this
101
+ * holds for a curve out of any plane through the axis too. Closed in u, and in v where C is.
102
+ */
103
+ export declare function revolvedSurface(c: SplineCurveDef, o: XYZ, z: XYZ): SurfaceDef;
@@ -0,0 +1,30 @@
1
+ import type { STEPModel } from '../index.js';
2
+ import { Body } from './topology.js';
3
+ /** The bodies of `step`, one per STEP body (undefined for a tessellated or faceted-only one, or a failed one). */
4
+ export interface ImportedBodies {
5
+ readonly bodies: readonly (Body | undefined)[];
6
+ /**
7
+ * Why a body was left out, or what is wrong with one that was imported (validateBody's problems, as
8
+ * `<name>: <problem>`): its index in `step.bodies` and the reason.
9
+ */
10
+ readonly problems: readonly {
11
+ readonly body: number;
12
+ readonly problem: string;
13
+ }[];
14
+ /**
15
+ * What was approximated in a body that was imported (an offset of a B-spline surface, fitted as a B-spline, and how
16
+ * closely), as `#<entity id>: <note>`: its index in `step.bodies` and the note.
17
+ */
18
+ readonly notes: readonly {
19
+ readonly body: number;
20
+ readonly note: string;
21
+ }[];
22
+ }
23
+ /**
24
+ * Modeler bodies from a parsed STEP file's solids and sheets (`parseSTEP`, or a JT part's `brep`), in metres, with
25
+ * names from their entity ids (`<body>/face:#<id>` and so on). Each body lines up with `step.bodies`; a body using a
26
+ * surface or curve the modeler does not have is undefined, with the reason in `problems`; so is one with no faces or
27
+ * one referring to instances the file never defines (`unresolved`), never an empty solid or one short of faces. Every
28
+ * imported body is validated (validateBody), and what is wrong with it is in `problems` too; checkBody checks it fully.
29
+ */
30
+ export declare function bodiesFromSTEP(step: STEPModel): ImportedBodies;
@@ -0,0 +1,27 @@
1
+ export { Body, Coedge, Edge, Face, History, Loop, Shell, Vertex } from './topology.js';
2
+ export type { HistoryEntry, Name } from './topology.js';
3
+ export { frameOf, curveEvaluator, surfaceEvaluator } from './geometry.js';
4
+ export type { CurveDef, Frame, SurfaceDef } from './geometry.js';
5
+ export type { WriterSpline } from '../step/write.js';
6
+ export { box, cone, cylinder, extrude, revolve, sphere, torus } from './build.js';
7
+ export type { Profile, ProfileSegment } from './build.js';
8
+ export { validateBody } from './validate.js';
9
+ export { checkBody } from './check.js';
10
+ export { massProperties } from './mass.js';
11
+ export type { MassProperties } from './mass.js';
12
+ export type { ValidityProblem } from './validate.js';
13
+ export { bodiesToSTEP, meshBodies } from './export.js';
14
+ export { bodiesFromSTEP } from './import.js';
15
+ export type { ImportedBodies } from './import.js';
16
+ export type { BodyMeshes } from './export.js';
17
+ export { boolean } from './boolean.js';
18
+ export type { BooleanOperation } from './boolean.js';
19
+ export { chamfer, fillet } from './blend.js';
20
+ export { sew } from './sew.js';
21
+ export { draft, offsetFaces, shell } from './offset.js';
22
+ export { sweep } from './sweep.js';
23
+ export { loft } from './loft.js';
24
+ export type { Path, PathSegment } from './sweep.js';
25
+ export type { SewReport } from './sew.js';
26
+ export { curveSurfaceCrossings, intersectSurfaces, signedDistance } from './intersect.js';
27
+ export type { SurfaceIntersection } from './intersect.js';
@@ -0,0 +1,28 @@
1
+ import { type XYZ } from '../geometry/vec.js';
2
+ import { type CurveDef, type SurfaceDef } from './geometry.js';
3
+ import { type Box3 } from './march.js';
4
+ export { curveSurfaceCrossings, signedDistance } from './distance.js';
5
+ /** What two surfaces share: curves, the same surface (coincident), or nothing. */
6
+ export type SurfaceIntersection =
7
+ /** `crossings`: points where two curves cross (the surfaces touch tangentially there). */
8
+ {
9
+ kind: 'curves';
10
+ curves: CurveDef[];
11
+ crossings?: XYZ[];
12
+ } | {
13
+ kind: 'coincident';
14
+ } | {
15
+ kind: 'none';
16
+ };
17
+ /**
18
+ * What two analytic surfaces share: curves, the same surface, or nothing. Exact where a closed form exists (plane with
19
+ * plane, plane with cylinder, a plane through the axis of a torus or a cone (its meridians), parallel cylinders, and
20
+ * surfaces of revolution on one axis: planes across it, spheres centred on it, cylinders, cones and tori about it,
21
+ * which meet in circles); otherwise the curves are traced inside
22
+ * `box` (march.ts), which those pairs (and every pair with a spline surface) need. Surfaces that come within
23
+ * `tolerance` of touching (a plane or a cylinder along a cylinder, surfaces about one axis along a circle, or two
24
+ * traced surfaces at a point) are taken to touch: one line or circle where they run alongside, crossing curves where
25
+ * they meet at a point (the Booleans pass 1e-6 of the model). Traced surfaces touching along a curve give no curve
26
+ * there: only the curves crossing it, traced straight through it.
27
+ */
28
+ export declare function intersectSurfaces(a: SurfaceDef, b: SurfaceDef, box?: Box3, tolerance?: number): SurfaceIntersection;
@@ -0,0 +1,12 @@
1
+ import { type Profile } from './build.js';
2
+ import { Body, type History, type Name } from './topology.js';
3
+ /**
4
+ * Lofts a solid named `name` through two or more closed planar sections of lines and arcs (see the file header). Each
5
+ * section's segments are matched in order from its start point; a section given clockwise about the loft direction is
6
+ * reversed about its start point. Faces: `start` and `end` (planes on the first and last section) and a side face per
7
+ * span and segment, named `<span>/<segment>` (spans s0, s1 and so on; segments by the first section's names, e0, e1
8
+ * and so on by default).
9
+ */
10
+ export declare function loft(name: Name, sections: readonly Profile[], { history }?: {
11
+ history?: History;
12
+ }): Body;
@@ -0,0 +1,20 @@
1
+ import { type XYZ } from '../geometry/vec.js';
2
+ import { type CurveDef, type SurfaceDef } from './geometry.js';
3
+ /** An axis-aligned box. */
4
+ export interface Box3 {
5
+ readonly min: XYZ;
6
+ readonly max: XYZ;
7
+ }
8
+ /**
9
+ * Curves where surfaces `a` and `b` meet inside `box` (closed loops, and branches cut where they leave it), and the
10
+ * points where two of them cross: there the surfaces touch tangentially (two equal cylinders at right angles), and the
11
+ * Booleans put a vertex. Surfaces that come within `tolerance` of touching at a point (1e-6 of the box unless given)
12
+ * are taken to touch there: their curves cross there too, or, where the surfaces curve apart every way (they kiss), the
13
+ * loop round the point is dropped (they only touch). Where they come further apart than that, the curves passing each
14
+ * other there are traced apart, however close. Surfaces touching along a curve give no curve along it; the curves
15
+ * crossing it cross it at a vertex, also where the surfaces come within the tolerance of touching along it.
16
+ */
17
+ export declare function traceIntersections(a: SurfaceDef, b: SurfaceDef, box: Box3, tolerance?: number): {
18
+ curves: CurveDef[];
19
+ crossings: XYZ[];
20
+ };
@@ -0,0 +1,28 @@
1
+ import type { XYZ } from '../geometry/vec.js';
2
+ import { FaceUV } from './faces.js';
3
+ import type { Body, Face } from './topology.js';
4
+ /** Mass properties of a solid of unit density. */
5
+ export interface MassProperties {
6
+ /** Volume in m^3 (for a sheet body, the signed volume its faces would enclose). */
7
+ readonly volume: number;
8
+ /** Area of all faces in m^2. */
9
+ readonly area: number;
10
+ /** Centre of the volume. */
11
+ readonly centroid: XYZ;
12
+ /**
13
+ * Inertia tensor about the centroid, unit density: [Ixx, Iyy, Izz, Ixy, Iyz, Izx], where Ixx is the integral of
14
+ * y^2 + z^2 and Ixy is minus the integral of x y (the convention of a moment-of-inertia matrix).
15
+ */
16
+ readonly inertia: readonly [number, number, number, number, number, number];
17
+ }
18
+ /**
19
+ * The volume some faces enclose, signed: positive when they face out of it (a solid's shell), negative for a cavity's.
20
+ * `uv` may hold the faces' FaceUVs, so that a caller which has them does not trace each face's loops again.
21
+ */
22
+ export declare function enclosedVolume(faces: readonly Face[], uv?: ReadonlyMap<Face, FaceUV>): number;
23
+ /**
24
+ * Exact mass properties of a body of unit density (multiply volume and inertia by a density for mass): integrated
25
+ * over its faces' surfaces within their edges, with no mesh. Faces of cavity shells face into the cavity, so their
26
+ * contributions subtract.
27
+ */
28
+ export declare function massProperties(body: Body): MassProperties;
@@ -0,0 +1,16 @@
1
+ import { type SurfaceDef } from './geometry.js';
2
+ type SplineSurfaceDef = Extract<SurfaceDef, {
3
+ kind: 'spline';
4
+ }>;
5
+ /** A fitted offset: its surface and the most it strays from the offset at the points it was measured at. */
6
+ export interface FittedOffset {
7
+ readonly surface: SplineSurfaceDef;
8
+ readonly error: number;
9
+ }
10
+ /**
11
+ * The offset of a B-spline surface by `d` (metres, along Su x Sv), fitted within `tolerance` where it can be in up to
12
+ * `maxPoints` control points a direction (else as near as it came: the caller compares the error). Throws a RangeError
13
+ * where the basis has no normal even beside the place (a crease), as the offset has no single place there.
14
+ */
15
+ export declare function offsetSpline(s: SplineSurfaceDef, d: number, tolerance: number, maxPoints?: number): FittedOffset;
16
+ export {};
@@ -0,0 +1,39 @@
1
+ import { type XYZ } from '../geometry/vec.js';
2
+ import { Body, type History, type Name } from './topology.js';
3
+ /**
4
+ * The body with each face named in `distances` moved along its outward normal by its distance (metres; negative moves
5
+ * it into the material), every face keeping its name and kind of surface. Throws a RangeError for a body with faces
6
+ * not on planes, cylinders, cones, spheres or tori, a face name the body does not have, and an offset that would
7
+ * change the body's topology or leave it invalid.
8
+ */
9
+ export declare function offsetBody(name: Name, body: Body, distances: ReadonlyMap<Name, number>, operation?: string): Body;
10
+ /**
11
+ * Moves the faces of `body` named in `faces` along their outward normals by `distance` metres (negative into the
12
+ * material) and re-solves their neighbours, into a body named `name`. Throws a RangeError where `offsetBody` does.
13
+ */
14
+ export declare function offsetFaces(name: Name, body: Body, faces: readonly Name[], distance: number, { history }?: {
15
+ history?: History;
16
+ }): Body;
17
+ /**
18
+ * Hollows `body` into walls `thickness` metres thick, open at the faces named in `open`: outside the body when
19
+ * thickness is positive (the body's faces are the walls' inner faces), inside it when negative (its faces are their
20
+ * outer faces). With no open face the hollow is a closed cavity. Throws a RangeError for a zero or non-finite
21
+ * thickness, and where the offsets would change the body's topology (walls too thick for a face).
22
+ */
23
+ export declare function shell(name: Name, body: Body, open: readonly Name[], thickness: number, { history }?: {
24
+ history?: History;
25
+ }): Body;
26
+ /**
27
+ * Drafts the faces of `body` named in `faces` by `angle` radians for a mould pulled along `pull`: each turns about the
28
+ * line where it meets the neutral plane (through `neutral.origin`, normal `neutral.normal`) until it makes `angle`
29
+ * with the pull direction, a positive angle leaning its outward normal towards `pull` (the faces close in along it).
30
+ * The other faces stay on their planes and the body is re-solved round the drafted ones. Throws a RangeError for an
31
+ * angle not inside (-90, 90) degrees, a face parallel to the neutral plane or square to the pull, one meeting the
32
+ * neutral plane along a line not square to the pull, and where the new planes would change the body's topology.
33
+ */
34
+ export declare function draft(name: Name, body: Body, faces: readonly Name[], neutral: {
35
+ readonly origin: XYZ;
36
+ readonly normal: XYZ;
37
+ }, pull: XYZ, angle: number, { history }?: {
38
+ history?: History;
39
+ }): Body;
@@ -0,0 +1,26 @@
1
+ import { type CurveDef, type SurfaceDef } from './geometry.js';
2
+ import { Vertex, type Face, type Name } from './topology.js';
3
+ /** An edge as written: a modeler edge, a piece of one between the points a seam splits it at, or a seam. */
4
+ export interface WrittenEdge {
5
+ readonly name: Name;
6
+ readonly curve: CurveDef;
7
+ readonly start: Vertex;
8
+ readonly end: Vertex;
9
+ readonly sameSense: boolean;
10
+ }
11
+ /** One use of a written edge by a face loop, along it or against it. */
12
+ interface WrittenUse {
13
+ readonly edge: WrittenEdge;
14
+ readonly forward: boolean;
15
+ }
16
+ /** How faces are written: each one's surface (its frame turned to put the seam where the face is cut) and loops. */
17
+ interface WrittenFaces {
18
+ surface(face: Face): SurfaceDef;
19
+ loops(face: Face): WrittenUse[][];
20
+ }
21
+ /**
22
+ * Faces as written: those that need it cut open, and edges split where seams and spline starts cross them and where
23
+ * a B-spline edge turns too far.
24
+ */
25
+ export declare function writtenFaces(faces: readonly Face[]): WrittenFaces;
26
+ export {};
@@ -0,0 +1,12 @@
1
+ import { type XYZ } from '../geometry/vec.js';
2
+ import type { Blend, Selected } from './blend.js';
3
+ import { Body, Edge, Face, type History, type Name, Vertex } from './topology.js';
4
+ /** The unit direction along an edge away from one of its vertices. */
5
+ export declare function away(edge: Edge, v: Vertex): XYZ;
6
+ /** A planar face's normal out of its solid. */
7
+ export declare function outward(f: Face): XYZ;
8
+ /**
9
+ * The blend of `selected` edges of `body` built in place (see above), or undefined when it is not that case. `balls`
10
+ * holds the corners a ball rounds, with the ball's centre.
11
+ */
12
+ export declare function setBack(name: Name, body: Body, selected: readonly Selected[], how: Blend, balls: ReadonlyMap<Vertex, XYZ>, history?: History): Body | undefined;
@@ -0,0 +1,47 @@
1
+ import { Body, Face, type History, type Name } from './topology.js';
2
+ import { type ValidityProblem } from './validate.js';
3
+ /** What sewing did and what it could not do. */
4
+ export interface SewReport {
5
+ /** The sewn body: a solid when `closed`, otherwise a sheet. */
6
+ readonly body: Body;
7
+ /** Whether every shell closed, faces agree on their sides, and the body passed checkBody: a valid solid. */
8
+ readonly closed: boolean;
9
+ /** Pairs of edges joined into one, with the largest distance between them (0 where they were the same curve). */
10
+ readonly joined: readonly {
11
+ readonly edges: readonly [Name, Name];
12
+ readonly gap: number;
13
+ }[];
14
+ /** Vertices joined into one, with the largest distance of any of them from the point they became. */
15
+ readonly merged: readonly {
16
+ readonly vertices: readonly Name[];
17
+ readonly gap: number;
18
+ }[];
19
+ /**
20
+ * Edges shorter than the tolerance (both their ends became one vertex) and faces left with no boundary by them (a
21
+ * sliver within the tolerance), removed.
22
+ */
23
+ readonly dropped: readonly Name[];
24
+ /** Edges split where another face's vertex lies on them, and the names of their pieces. */
25
+ readonly split: readonly {
26
+ readonly edge: Name;
27
+ readonly into: readonly Name[];
28
+ }[];
29
+ /** Edges left with one face, each with the nearest other such edge and how far it is (Infinity when there is none). */
30
+ readonly open: readonly {
31
+ readonly edge: Name;
32
+ readonly nearest?: Name;
33
+ readonly gap: number;
34
+ }[];
35
+ /** Faces turned over so that each shared edge is run one way by one face and the other way by the other. */
36
+ readonly flipped: readonly Name[];
37
+ /** Everything else that kept the body from being a valid solid. */
38
+ readonly problems: readonly ValidityProblem[];
39
+ }
40
+ /**
41
+ * Sews `faces` (faces, or every face of sheets and solids) into one body named `name`, closing gaps of at most
42
+ * `tolerance` metres. The faces' surfaces and curves are shared with the inputs, which are not changed. Throws a
43
+ * RangeError for a tolerance that is not positive and finite, and for no faces.
44
+ */
45
+ export declare function sew(name: Name, faces: readonly (Face | Body)[], tolerance: number, { history }?: {
46
+ history?: History;
47
+ }): SewReport;