fluidcad 0.0.24 → 0.0.26

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 (52) hide show
  1. package/lib/dist/common/scene-object.d.ts +6 -2
  2. package/lib/dist/common/scene-object.js +28 -16
  3. package/lib/dist/common/transformable-primitive.d.ts +16 -0
  4. package/lib/dist/common/transformable-primitive.js +116 -0
  5. package/lib/dist/core/2d/tarc.d.ts +2 -2
  6. package/lib/dist/core/copy.js +5 -4
  7. package/lib/dist/core/cylinder.d.ts +2 -2
  8. package/lib/dist/core/index.d.ts +2 -1
  9. package/lib/dist/core/index.js +1 -0
  10. package/lib/dist/core/interfaces.d.ts +80 -21
  11. package/lib/dist/core/local.d.ts +12 -0
  12. package/lib/dist/core/local.js +18 -0
  13. package/lib/dist/core/mirror.d.ts +2 -2
  14. package/lib/dist/core/mirror.js +42 -60
  15. package/lib/dist/core/plane.d.ts +5 -7
  16. package/lib/dist/core/sphere.d.ts +3 -3
  17. package/lib/dist/features/2d/circle.js +2 -1
  18. package/lib/dist/features/2d/tarc-with-tangent.js +4 -2
  19. package/lib/dist/features/2d/tarc.js +4 -2
  20. package/lib/dist/features/axis-from-edge.js +2 -2
  21. package/lib/dist/features/axis-from-sketch.d.ts +18 -0
  22. package/lib/dist/features/axis-from-sketch.js +58 -0
  23. package/lib/dist/features/copy-linear2d.d.ts +4 -2
  24. package/lib/dist/features/copy-linear2d.js +23 -9
  25. package/lib/dist/features/cylinder.d.ts +2 -2
  26. package/lib/dist/features/cylinder.js +2 -2
  27. package/lib/dist/features/mirror-shape.js +10 -0
  28. package/lib/dist/features/plane-from-object.d.ts +1 -1
  29. package/lib/dist/features/plane-from-object.js +11 -6
  30. package/lib/dist/features/plane-mid.d.ts +1 -1
  31. package/lib/dist/features/plane.d.ts +1 -1
  32. package/lib/dist/features/select.js +0 -1
  33. package/lib/dist/features/sphere.d.ts +2 -2
  34. package/lib/dist/features/sphere.js +2 -2
  35. package/lib/dist/math/axis.d.ts +1 -0
  36. package/lib/dist/math/axis.js +4 -1
  37. package/lib/dist/math/index.d.ts +2 -2
  38. package/lib/dist/math/index.js +1 -1
  39. package/lib/dist/math/plane.d.ts +1 -2
  40. package/lib/dist/math/plane.js +20 -19
  41. package/lib/dist/rendering/render.js +8 -0
  42. package/lib/dist/tests/features/cut-two-distances.test.js +1 -1
  43. package/lib/dist/tests/features/cut.test.js +1 -1
  44. package/lib/dist/tests/features/mirror2d.test.js +34 -0
  45. package/lib/dist/tests/features/primitive-chain.test.d.ts +1 -0
  46. package/lib/dist/tests/features/primitive-chain.test.js +45 -0
  47. package/lib/dist/tsconfig.tsbuildinfo +1 -1
  48. package/package.json +1 -1
  49. package/server/dist/code-editor.d.ts +3 -2
  50. package/server/dist/code-editor.js +244 -121
  51. package/ui/dist/assets/{index-CqP_mgZk.js → index-BeLxRMCv.js} +4 -4
  52. package/ui/dist/index.html +1 -1
@@ -3,6 +3,7 @@ import { setupOC, render } from "../setup.js";
3
3
  import sketch from "../../core/sketch.js";
4
4
  import extrude from "../../core/extrude.js";
5
5
  import mirror from "../../core/mirror.js";
6
+ import local from "../../core/local.js";
6
7
  import { move, rect, circle } from "../../core/2d/index.js";
7
8
  import { ShapeOps } from "../../oc/shape-ops.js";
8
9
  describe("mirror (2D)", () => {
@@ -72,4 +73,37 @@ describe("mirror (2D)", () => {
72
73
  expect(shapes.length).toBeGreaterThanOrEqual(2);
73
74
  });
74
75
  });
76
+ describe("local() axis wrapper", () => {
77
+ it("should fail when mirroring across a world axis parallel to the sketch plane normal", () => {
78
+ let mirrorRef;
79
+ sketch("front", () => {
80
+ move([30, 0]);
81
+ const c = circle(20);
82
+ mirrorRef = mirror("y", c);
83
+ });
84
+ render();
85
+ expect(mirrorRef.getError()).toBeTruthy();
86
+ });
87
+ it("should mirror across sketch-local Y on a non-XY plane via local()", () => {
88
+ sketch("front", () => {
89
+ move([30, 0]);
90
+ const c = circle(20);
91
+ mirror(local("y"), c);
92
+ });
93
+ const e = extrude(10);
94
+ render();
95
+ const shapes = e.getShapes();
96
+ expect(shapes.length).toBeGreaterThanOrEqual(1);
97
+ // Mirroring across sketch-local Y on the "front" plane flips world X,
98
+ // so bbox should span both sides of X=0.
99
+ const allBBoxes = shapes.map(s => ShapeOps.getBoundingBox(s));
100
+ const minX = Math.min(...allBBoxes.map(b => b.minX));
101
+ const maxX = Math.max(...allBBoxes.map(b => b.maxX));
102
+ expect(minX).toBeLessThan(0);
103
+ expect(maxX).toBeGreaterThan(0);
104
+ });
105
+ it("should throw when local() is called outside a sketch", () => {
106
+ expect(() => local("y")).toThrow();
107
+ });
108
+ });
75
109
  });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,45 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { setupOC, render } from "../setup.js";
3
+ import sphere from "../../core/sphere.js";
4
+ import cylinder from "../../core/cylinder.js";
5
+ import { ShapeOps } from "../../oc/shape-ops.js";
6
+ describe("chained transforms on primitive shapes", () => {
7
+ setupOC();
8
+ it("applies .translate() on a cylinder", () => {
9
+ const c = cylinder(5, 10).translate(20, 0, 0);
10
+ render();
11
+ const shapes = c.getShapes();
12
+ expect(shapes).toHaveLength(1);
13
+ const bbox = ShapeOps.getBoundingBox(shapes[0]);
14
+ expect(bbox.minX).toBeCloseTo(15, 0);
15
+ expect(bbox.maxX).toBeCloseTo(25, 0);
16
+ });
17
+ it("composes chained transforms left-to-right on a sphere", () => {
18
+ const s = sphere(1).translate(5, 0, 0).rotate("z", 90);
19
+ render();
20
+ const shapes = s.getShapes();
21
+ const bbox = ShapeOps.getBoundingBox(shapes[0]);
22
+ const cx = (bbox.minX + bbox.maxX) / 2;
23
+ const cy = (bbox.minY + bbox.maxY) / 2;
24
+ expect(cx).toBeCloseTo(0, 1);
25
+ expect(cy).toBeCloseTo(5, 1);
26
+ });
27
+ it("accepts a PointLike array in .translate()", () => {
28
+ const s = sphere(1).translate([7, 8, 9]);
29
+ render();
30
+ const bbox = ShapeOps.getBoundingBox(s.getShapes()[0]);
31
+ const cx = (bbox.minX + bbox.maxX) / 2;
32
+ const cy = (bbox.minY + bbox.maxY) / 2;
33
+ const cz = (bbox.minZ + bbox.maxZ) / 2;
34
+ expect(cx).toBeCloseTo(7, 1);
35
+ expect(cy).toBeCloseTo(8, 1);
36
+ expect(cz).toBeCloseTo(9, 1);
37
+ });
38
+ it("chained .mirror() across a plane", () => {
39
+ const c = cylinder(5, 10).translate(15, 0, 0).mirror("yz");
40
+ render();
41
+ const bbox = ShapeOps.getBoundingBox(c.getShapes()[0]);
42
+ expect(bbox.maxX).toBeCloseTo(-10, 0);
43
+ expect(bbox.minX).toBeCloseTo(-20, 0);
44
+ });
45
+ });