okgeometry-api 1.2.0 → 1.2.1

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 (65) hide show
  1. package/dist/Line.d.ts +10 -1
  2. package/dist/Line.d.ts.map +1 -1
  3. package/dist/Line.js +11 -0
  4. package/dist/Line.js.map +1 -1
  5. package/dist/Mesh.d.ts +82 -9
  6. package/dist/Mesh.d.ts.map +1 -1
  7. package/dist/Mesh.js +329 -26
  8. package/dist/Mesh.js.map +1 -1
  9. package/dist/MeshSurface.d.ts +32 -0
  10. package/dist/MeshSurface.d.ts.map +1 -0
  11. package/dist/MeshSurface.js +51 -0
  12. package/dist/MeshSurface.js.map +1 -0
  13. package/dist/NurbsCurve.d.ts +24 -2
  14. package/dist/NurbsCurve.d.ts.map +1 -1
  15. package/dist/NurbsCurve.js +34 -2
  16. package/dist/NurbsCurve.js.map +1 -1
  17. package/dist/NurbsSurface.d.ts +9 -1
  18. package/dist/NurbsSurface.d.ts.map +1 -1
  19. package/dist/NurbsSurface.js +12 -3
  20. package/dist/NurbsSurface.js.map +1 -1
  21. package/dist/PolyCurve.d.ts +21 -3
  22. package/dist/PolyCurve.d.ts.map +1 -1
  23. package/dist/PolyCurve.js +82 -38
  24. package/dist/PolyCurve.js.map +1 -1
  25. package/dist/Polygon.d.ts +13 -2
  26. package/dist/Polygon.d.ts.map +1 -1
  27. package/dist/Polygon.js +21 -3
  28. package/dist/Polygon.js.map +1 -1
  29. package/dist/Polyline.d.ts +19 -2
  30. package/dist/Polyline.d.ts.map +1 -1
  31. package/dist/Polyline.js +38 -6
  32. package/dist/Polyline.js.map +1 -1
  33. package/dist/Surface.d.ts +17 -0
  34. package/dist/Surface.d.ts.map +1 -0
  35. package/dist/Surface.js +2 -0
  36. package/dist/Surface.js.map +1 -0
  37. package/dist/index.d.ts +4 -2
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +1 -0
  40. package/dist/index.js.map +1 -1
  41. package/dist/types.d.ts +13 -0
  42. package/dist/types.d.ts.map +1 -1
  43. package/dist/wasm-base64.d.ts +1 -1
  44. package/dist/wasm-base64.d.ts.map +1 -1
  45. package/dist/wasm-base64.js +1 -1
  46. package/dist/wasm-base64.js.map +1 -1
  47. package/dist/wasm-bindings.d.ts +65 -2
  48. package/dist/wasm-bindings.d.ts.map +1 -1
  49. package/dist/wasm-bindings.js +100 -2
  50. package/dist/wasm-bindings.js.map +1 -1
  51. package/package.json +1 -1
  52. package/src/Line.ts +38 -20
  53. package/src/Mesh.ts +538 -184
  54. package/src/MeshSurface.ts +72 -0
  55. package/src/NurbsCurve.ts +80 -26
  56. package/src/NurbsSurface.ts +28 -13
  57. package/src/PolyCurve.ts +157 -85
  58. package/src/Polygon.ts +34 -4
  59. package/src/Polyline.ts +74 -24
  60. package/src/Surface.ts +18 -0
  61. package/src/index.ts +5 -0
  62. package/src/types.ts +15 -0
  63. package/src/wasm-base64.ts +1 -1
  64. package/src/wasm-bindings.d.ts +43 -2
  65. package/src/wasm-bindings.js +105 -2
package/src/Polyline.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  import { ensureInit } from "./engine.js";
2
2
  import { Point } from "./Point.js";
3
3
  import { Vec3 } from "./Vec3.js";
4
- import { Mesh } from "./Mesh.js";
5
- import { Line } from "./Line.js";
6
- import { PolyCurve } from "./PolyCurve.js";
7
- import type { Plane } from "./Plane.js";
8
- import type { RotationAxis } from "./types.js";
9
- import { pointsToCoords, coordsToPoints } from "./BufferCodec.js";
10
- import * as wasm from "./wasm-bindings.js";
4
+ import { Mesh } from "./Mesh.js";
5
+ import { Line } from "./Line.js";
6
+ import { PolyCurve } from "./PolyCurve.js";
7
+ import type { Plane } from "./Plane.js";
8
+ import type { CurveOffsetOptions, RotationAxis } from "./types.js";
9
+ import { pointsToCoords } from "./BufferCodec.js";
10
+ import * as wasm from "./wasm-bindings.js";
11
11
 
12
12
  /**
13
13
  * Open or closed polyline defined by a sequence of points.
@@ -95,23 +95,73 @@ export class Polyline {
95
95
  return new Polyline(this.points.map(p => p.rotate(axis, angle)));
96
96
  }
97
97
 
98
- /**
99
- * Offset this polyline perpendicular to its segments.
100
- * @param distance - Offset distance
101
- * @param normal - Reference normal for determining offset direction
102
- * @returns New offset polyline
103
- */
104
- offset(distance: number, normal?: Vec3): Polyline {
105
- ensureInit();
106
- const nx = normal?.x ?? 0, ny = normal?.y ?? 0, nz = normal?.z ?? 0;
107
- const result = wasm.offset_polyline_curve(this.toCoords(), distance, nx, ny, nz);
108
- return new Polyline(coordsToPoints(result));
109
- }
110
-
111
- /**
112
- * Project this polyline onto a plane.
113
- * @param plane - Target plane
114
- * @param direction - Optional projection direction (default: perpendicular to plane)
98
+ /**
99
+ * Offset this polyline perpendicular to its segments.
100
+ * @param distance - Offset distance
101
+ * @param normal - Reference normal for determining offset direction
102
+ * @param arcSamples - Number of samples per arc join in the returned polyline(s)
103
+ * @param options - Offset options such as join style
104
+ * @returns New offset polyline
105
+ */
106
+ offset(
107
+ distance: number,
108
+ normal?: Vec3,
109
+ arcSamples = 32,
110
+ options: CurveOffsetOptions = {},
111
+ ): Polyline {
112
+ const results = this.offsetAll(distance, normal, arcSamples, options);
113
+ if (results.length === 1) return results[0];
114
+ if (results.length === 0) {
115
+ throw new Error("Polyline.offset() collapsed and produced no valid result polylines");
116
+ }
117
+ throw new Error(
118
+ `Polyline.offset() produced ${results.length} result polylines. Use Polyline.offsetAll() instead.`,
119
+ );
120
+ }
121
+
122
+ /**
123
+ * Offset this polyline and return every sampled result polyline.
124
+ * @param distance - Offset distance
125
+ * @param normal - Reference normal for determining offset direction
126
+ * @param arcSamples - Number of samples per exact arc segment in the returned polylines
127
+ * @param options - Offset options such as join style
128
+ * @returns Every valid offset polyline
129
+ */
130
+ offsetAll(
131
+ distance: number,
132
+ normal?: Vec3,
133
+ arcSamples = 32,
134
+ options: CurveOffsetOptions = {},
135
+ ): Polyline[] {
136
+ const exact = this.toPolyCurve().offsetAll(distance, normal, options);
137
+ const samples = Number.isFinite(arcSamples) ? Math.max(3, Math.floor(arcSamples)) : 32;
138
+ return exact.map(curve => new Polyline(curve.sample(samples)));
139
+ }
140
+
141
+ /**
142
+ * Thicken this open polyline into a closed PolyCurve suitable for extrusion.
143
+ * When `bothSides` is false, the source polyline forms one side of the result.
144
+ * When true, the thickness is added on each side of the source polyline.
145
+ */
146
+ thicken(
147
+ distance: number,
148
+ bothSides = false,
149
+ normal?: Vec3,
150
+ options: CurveOffsetOptions = {},
151
+ ): PolyCurve {
152
+ if (this.points.length < 2) {
153
+ throw new Error("Polyline.thicken() requires at least 2 points");
154
+ }
155
+ if (this.isClosed()) {
156
+ throw new Error("Polyline.thicken() requires an open polyline");
157
+ }
158
+ return this.toPolyCurve().thicken(distance, bothSides, normal, options);
159
+ }
160
+
161
+ /**
162
+ * Project this polyline onto a plane.
163
+ * @param plane - Target plane
164
+ * @param direction - Optional projection direction (default: perpendicular to plane)
115
165
  * @returns New projected polyline
116
166
  */
117
167
  projectOntoPlane(plane: Plane, direction?: Vec3): Polyline {
package/src/Surface.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { Point } from "./Point.js";
2
+ import type { Vec3 } from "./Vec3.js";
3
+
4
+ /**
5
+ * Common parametric surface contract shared by NURBS surfaces and mesh-face surfaces.
6
+ */
7
+ export interface Surface {
8
+ /**
9
+ * Evaluate a point on the surface at normalized parameters.
10
+ * Returns `Point(NaN, NaN, NaN)` when the query falls outside the valid surface patch.
11
+ */
12
+ evaluate(u: number, v: number): Point;
13
+
14
+ /**
15
+ * Evaluate the unit normal on the surface at normalized parameters.
16
+ */
17
+ normal(u: number, v: number): Vec3;
18
+ }
package/src/index.ts CHANGED
@@ -7,6 +7,8 @@ export type {
7
7
  LoftableCurve,
8
8
  RotationAxis,
9
9
  CurveSegment,
10
+ CurveOffsetJoinStyle,
11
+ CurveOffsetOptions,
10
12
  } from "./types.js";
11
13
  export { CurveTypeCode, SegmentTypeCode } from "./types.js";
12
14
  export {
@@ -31,6 +33,8 @@ export { Polygon } from "./Polygon.js";
31
33
  export { PolyCurve } from "./PolyCurve.js";
32
34
  export { NurbsCurve } from "./NurbsCurve.js";
33
35
  export { NurbsSurface } from "./NurbsSurface.js";
36
+ export { MeshSurface } from "./MeshSurface.js";
37
+ export type { Surface } from "./Surface.js";
34
38
 
35
39
  // Mesh and operations
36
40
  export { Mesh, MeshBooleanExecutionError } from "./Mesh.js";
@@ -50,6 +54,7 @@ export type {
50
54
  MeshPlaneSplitResult,
51
55
  MeshPlaneSplitOptions,
52
56
  MeshCurveSplitOptions,
57
+ MeshPlanarFace,
53
58
  MeshDebugBounds,
54
59
  MeshDebugRayHit,
55
60
  MeshDebugSummary,
package/src/types.ts CHANGED
@@ -47,6 +47,21 @@ export type RotationAxis = Vec3 | Line;
47
47
  */
48
48
  export type CurveSegment = Line | Arc;
49
49
 
50
+ /**
51
+ * Join style used when offsetting polycurves and sampled curve types.
52
+ * - `miter`: extend adjacent offset segments until they intersect
53
+ * - `round`: connect outside corners with an arc
54
+ * - `bevel`: connect outside corners with a straight bridge segment
55
+ */
56
+ export type CurveOffsetJoinStyle = "miter" | "round" | "bevel";
57
+
58
+ /**
59
+ * Optional settings for curve offset operations.
60
+ */
61
+ export interface CurveOffsetOptions {
62
+ joinStyle?: CurveOffsetJoinStyle;
63
+ }
64
+
50
65
  // ── WASM Buffer Encoding Constants ─────────────────────────────────
51
66
 
52
67
  /**