@bitbybit-dev/jscad 1.1.1 → 1.2.0-rc.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.
@@ -1,3 +1,4 @@
1
+ import { asPath } from "./entity-narrowing";
1
2
  /**
2
3
  * Contains various functions for Path from JSCAD library https://github.com/jscad/OpenJSCAD.org
3
4
  * Thanks JSCAD community for developing this kernel
@@ -8,10 +9,26 @@ export class JSCADPath {
8
9
  this.geometryHelper = geometryHelper;
9
10
  this.math = math;
10
11
  }
12
+ /**
13
+ * Create a 2D path from a list of points
14
+ * @param inputs Points and indication if we want a closed path or not
15
+ * @returns Path
16
+ * @group from
17
+ * @shortname points
18
+ * @drawable true
19
+ */
11
20
  createFromPoints(inputs) {
12
21
  const twoDimensionalPoints = inputs.points.map(pt => [pt[0], pt[1]]);
13
22
  return this.removeDuplicatesAndCreateFromPoints(twoDimensionalPoints, inputs.closed);
14
23
  }
24
+ /**
25
+ * Create 2D paths from a lists of points
26
+ * @param inputs Points lists
27
+ * @returns Paths
28
+ * @group from
29
+ * @shortname paths from points
30
+ * @drawable true
31
+ */
15
32
  createPathsFromPoints(inputs) {
16
33
  return inputs.pointsLists.map(points => {
17
34
  const twoDimensionalPoints = points.map(pt => [pt[0], pt[1]]);
@@ -22,25 +39,72 @@ export class JSCADPath {
22
39
  return this.removeDuplicatesAndCreateFromPoints(twoDimensionalPoints, false);
23
40
  });
24
41
  }
42
+ /**
43
+ * Create a 2D path from a polyline
44
+ * @param inputs Polyline and indication if we want a closed path or not
45
+ * @returns Path
46
+ * @group from
47
+ * @shortname polyline
48
+ * @drawable true
49
+ */
25
50
  createFromPolyline(inputs) {
26
51
  const twoDimensionalPoints = inputs.polyline.points.map(pt => [pt[0], pt[1]]);
27
52
  return this.removeDuplicatesAndCreateFromPoints(twoDimensionalPoints, inputs.closed);
28
53
  }
54
+ /**
55
+ * Create empty 2D path
56
+ * @returns Empty path
57
+ * @group create
58
+ * @shortname empty
59
+ * @drawable false
60
+ */
29
61
  createEmpty() {
30
62
  return this.jscad.geometries.path2.create();
31
63
  }
64
+ /**
65
+ * Closes an open 2D path
66
+ * @param inputs Path
67
+ * @returns Closed path
68
+ * @group edit
69
+ * @shortname close
70
+ * @drawable true
71
+ */
32
72
  close(inputs) {
33
- return this.jscad.geometries.path2.close(inputs.path);
73
+ return this.jscad.geometries.path2.close(asPath(inputs.path, "path operations"));
34
74
  }
75
+ /**
76
+ * Append the path with 2D points
77
+ * @param inputs Path to append and points
78
+ * @returns Appended path
79
+ * @group append
80
+ * @shortname points
81
+ * @drawable true
82
+ */
35
83
  appendPoints(inputs) {
36
84
  const twoDimensionalPoints = inputs.points.map(pt => [pt[0], pt[1]]);
37
85
  const duplicatePointsRemoved = this.geometryHelper.removeConsecutiveVectorDuplicates(twoDimensionalPoints);
38
- return this.jscad.geometries.path2.appendPoints(duplicatePointsRemoved, inputs.path);
86
+ return this.jscad.geometries.path2.appendPoints(duplicatePointsRemoved, asPath(inputs.path, "path operations"));
39
87
  }
88
+ /**
89
+ * Append the path with polyline
90
+ * @param inputs Path to append and polyline
91
+ * @returns Appended path
92
+ * @group append
93
+ * @shortname polyline
94
+ * @drawable true
95
+ */
40
96
  appendPolyline(inputs) {
41
97
  const twoDimensionalPoints = inputs.polyline.points.map(pt => [pt[0], pt[1]]);
42
98
  return this.appendPoints({ points: twoDimensionalPoints, path: inputs.path });
43
99
  }
100
+ /**
101
+ * Append the arc to the path
102
+ * @param inputs Path and arc parameters
103
+ * @returns Appended path
104
+ * @group append
105
+ * @shortname arc
106
+ * @drawable true
107
+ */
44
108
  appendArc(inputs) {
45
109
  const endpoint = [inputs.endPoint[0], inputs.endPoint[1]];
46
110
  const radius = [inputs.radiusX, inputs.radiusY];
@@ -51,7 +115,7 @@ export class JSCADPath {
51
115
  clockwise: inputs.clockwise,
52
116
  large: inputs.large,
53
117
  segments: inputs.segments,
54
- }, inputs.path);
118
+ }, asPath(inputs.path, "path operations"));
55
119
  }
56
120
  removeDuplicatesAndCreateFromPoints(twoDimensionalPoints, closed) {
57
121
  const duplicatePointsRemoved = this.geometryHelper.removeConsecutiveVectorDuplicates(twoDimensionalPoints);
@@ -11,15 +11,99 @@ export declare class JSCADPolygon {
11
11
  private readonly geometryHelper;
12
12
  private readonly math;
13
13
  constructor(jscad: typeof JSCAD, geometryHelper: GeometryHelper, math: MathBitByBit);
14
+ /**
15
+ * Create a 2D polygon from a list of points
16
+ * @param inputs Points
17
+ * @returns Polygons
18
+ * @group from
19
+ * @shortname polygon from points
20
+ * @drawable true
21
+ */
14
22
  createFromPoints(inputs: Inputs.Point.PointsDto): Inputs.JSCAD.JSCADEntity;
23
+ /**
24
+ * Create a 2D polygon from a polyline
25
+ * @param inputs Polyline
26
+ * @returns Polygon
27
+ * @group from
28
+ * @shortname polyline
29
+ * @drawable true
30
+ */
15
31
  createFromPolyline(inputs: Inputs.JSCAD.PolylineDto): Inputs.JSCAD.JSCADEntity;
32
+ /**
33
+ * Create a 2D polygon from a curve
34
+ * @param inputs Nurbs curve
35
+ * @returns Polygon
36
+ * @group from
37
+ * @shortname curve
38
+ * @drawable true
39
+ * @deprecated This takes a verb-nurbs curve, and verb is deprecated for removal in the next major,
40
+ * so this goes with it. It is also the one method here that converts between two different CAD
41
+ * kernels, which belongs above a kernel-specific package rather than inside one. Build the polygon
42
+ * from points or from a polyline instead.
43
+ */
16
44
  createFromCurve(inputs: Inputs.JSCAD.CurveDto): Inputs.JSCAD.JSCADEntity;
45
+ /**
46
+ * Create a 2D polygon from a path
47
+ * @param inputs Path
48
+ * @returns Polygon
49
+ * @group from
50
+ * @shortname path
51
+ * @drawable true
52
+ */
17
53
  createFromPath(inputs: Inputs.JSCAD.PathDto): Inputs.JSCAD.JSCADEntity;
54
+ /**
55
+ * Create a 2D polygon circle
56
+ * @param inputs Circle parameters
57
+ * @returns Circle polygon
58
+ * @group primitives
59
+ * @shortname circle
60
+ * @drawable true
61
+ */
18
62
  circle(inputs: Inputs.JSCAD.CircleDto): Inputs.JSCAD.JSCADEntity;
63
+ /**
64
+ * Create a 2D polygon ellipse
65
+ * @param inputs Ellipse parameters
66
+ * @returns Ellipse polygon
67
+ * @group primitives
68
+ * @shortname ellipse
69
+ * @drawable true
70
+ */
19
71
  ellipse(inputs: Inputs.JSCAD.EllipseDto): Inputs.JSCAD.JSCADEntity;
72
+ /**
73
+ * Create a 2D polygon rectangle
74
+ * @param inputs Rectangle parameters
75
+ * @returns Rectangle polygon
76
+ * @group primitives
77
+ * @shortname rectangle
78
+ * @drawable true
79
+ */
20
80
  rectangle(inputs: Inputs.JSCAD.RectangleDto): Inputs.JSCAD.JSCADEntity;
81
+ /**
82
+ * Create a 2D rounded rectangle
83
+ * @param inputs Rounded rectangle parameters
84
+ * @returns Rounded rectangle polygon
85
+ * @group primitives
86
+ * @shortname rounded rectangle
87
+ * @drawable true
88
+ */
21
89
  roundedRectangle(inputs: Inputs.JSCAD.RoundedRectangleDto): Inputs.JSCAD.JSCADEntity;
90
+ /**
91
+ * Create a 2D polygon square
92
+ * @param inputs Square parameters
93
+ * @returns Square polygon
94
+ * @group primitives
95
+ * @shortname square
96
+ * @drawable true
97
+ */
22
98
  square(inputs: Inputs.JSCAD.SquareDto): Inputs.JSCAD.JSCADEntity;
99
+ /**
100
+ * Create a 2D polygon star
101
+ * @param inputs Star parameters
102
+ * @returns Star polygon
103
+ * @group primitives
104
+ * @shortname star
105
+ * @drawable true
106
+ */
23
107
  star(inputs: Inputs.JSCAD.StarDto): Inputs.JSCAD.JSCADEntity;
24
108
  private removeDuplicatesAndCreateFromPoints;
25
109
  }
@@ -1,3 +1,4 @@
1
+ import { asPath } from "./entity-narrowing";
1
2
  /**
2
3
  * Contains various functions for Polygon from JSCAD library https://github.com/jscad/OpenJSCAD.org
3
4
  * Thanks JSCAD community for developing this kernel
@@ -8,25 +9,76 @@ export class JSCADPolygon {
8
9
  this.geometryHelper = geometryHelper;
9
10
  this.math = math;
10
11
  }
12
+ /**
13
+ * Create a 2D polygon from a list of points
14
+ * @param inputs Points
15
+ * @returns Polygons
16
+ * @group from
17
+ * @shortname polygon from points
18
+ * @drawable true
19
+ */
11
20
  createFromPoints(inputs) {
12
21
  const twoDimensionalPoints = inputs.points.map(pt => [pt[0], pt[1]]);
13
22
  return this.removeDuplicatesAndCreateFromPoints(twoDimensionalPoints);
14
23
  }
24
+ /**
25
+ * Create a 2D polygon from a polyline
26
+ * @param inputs Polyline
27
+ * @returns Polygon
28
+ * @group from
29
+ * @shortname polyline
30
+ * @drawable true
31
+ */
15
32
  createFromPolyline(inputs) {
16
33
  const twoDimensionalPoints = inputs.polyline.points.map(pt => [pt[0], pt[1]]);
17
34
  return this.removeDuplicatesAndCreateFromPoints(twoDimensionalPoints);
18
35
  }
19
- // TODO conversions between various CAD kernels should happen on higher levels of abstraction (this was meant to create jscad polygons from VERB-NURBS curves)
36
+ /**
37
+ * Create a 2D polygon from a curve
38
+ * @param inputs Nurbs curve
39
+ * @returns Polygon
40
+ * @group from
41
+ * @shortname curve
42
+ * @drawable true
43
+ * @deprecated This takes a verb-nurbs curve, and verb is deprecated for removal in the next major,
44
+ * so this goes with it. It is also the one method here that converts between two different CAD
45
+ * kernels, which belongs above a kernel-specific package rather than inside one. Build the polygon
46
+ * from points or from a polyline instead.
47
+ */
20
48
  createFromCurve(inputs) {
21
- const twoDimensionalPoints = inputs.curve.tessellate().map(pt => [pt[0], pt[1]]);
49
+ const twoDimensionalPoints = inputs.curve.tessellate().map((pt) => [pt[0], pt[1]]);
22
50
  return this.removeDuplicatesAndCreateFromPoints(twoDimensionalPoints);
23
51
  }
52
+ /**
53
+ * Create a 2D polygon from a path
54
+ * @param inputs Path
55
+ * @returns Polygon
56
+ * @group from
57
+ * @shortname path
58
+ * @drawable true
59
+ */
24
60
  createFromPath(inputs) {
25
- return this.removeDuplicatesAndCreateFromPoints(inputs.path.points);
61
+ return this.removeDuplicatesAndCreateFromPoints(asPath(inputs.path, "createFromPath").points);
26
62
  }
63
+ /**
64
+ * Create a 2D polygon circle
65
+ * @param inputs Circle parameters
66
+ * @returns Circle polygon
67
+ * @group primitives
68
+ * @shortname circle
69
+ * @drawable true
70
+ */
27
71
  circle(inputs) {
28
72
  return this.jscad.primitives.circle({ center: inputs.center, radius: inputs.radius, segments: inputs.segments });
29
73
  }
74
+ /**
75
+ * Create a 2D polygon ellipse
76
+ * @param inputs Ellipse parameters
77
+ * @returns Ellipse polygon
78
+ * @group primitives
79
+ * @shortname ellipse
80
+ * @drawable true
81
+ */
30
82
  ellipse(inputs) {
31
83
  return this.jscad.primitives.ellipse({
32
84
  center: inputs.center,
@@ -34,12 +86,28 @@ export class JSCADPolygon {
34
86
  segments: inputs.segments
35
87
  });
36
88
  }
89
+ /**
90
+ * Create a 2D polygon rectangle
91
+ * @param inputs Rectangle parameters
92
+ * @returns Rectangle polygon
93
+ * @group primitives
94
+ * @shortname rectangle
95
+ * @drawable true
96
+ */
37
97
  rectangle(inputs) {
38
98
  return this.jscad.primitives.rectangle({
39
99
  center: [inputs.center[0], inputs.center[1]],
40
100
  size: [inputs.width, inputs.length]
41
101
  });
42
102
  }
103
+ /**
104
+ * Create a 2D rounded rectangle
105
+ * @param inputs Rounded rectangle parameters
106
+ * @returns Rounded rectangle polygon
107
+ * @group primitives
108
+ * @shortname rounded rectangle
109
+ * @drawable true
110
+ */
43
111
  roundedRectangle(inputs) {
44
112
  return this.jscad.primitives.roundedRectangle({
45
113
  center: [inputs.center[0], inputs.center[1]],
@@ -48,9 +116,25 @@ export class JSCADPolygon {
48
116
  segments: inputs.segments,
49
117
  });
50
118
  }
119
+ /**
120
+ * Create a 2D polygon square
121
+ * @param inputs Square parameters
122
+ * @returns Square polygon
123
+ * @group primitives
124
+ * @shortname square
125
+ * @drawable true
126
+ */
51
127
  square(inputs) {
52
128
  return this.jscad.primitives.square({ center: [inputs.center[0], inputs.center[1]], size: inputs.size });
53
129
  }
130
+ /**
131
+ * Create a 2D polygon star
132
+ * @param inputs Star parameters
133
+ * @returns Star polygon
134
+ * @group primitives
135
+ * @shortname star
136
+ * @drawable true
137
+ */
54
138
  star(inputs) {
55
139
  return this.jscad.primitives.star({
56
140
  center: [inputs.center[0], inputs.center[1]],
@@ -9,24 +9,184 @@ export declare class JSCADShapes {
9
9
  private readonly math;
10
10
  jscad: typeof JSCAD;
11
11
  constructor(jscad: typeof JSCAD, math: MathBitByBit);
12
+ /**
13
+ * Create a 3D cube shape
14
+ * @param inputs Cube parameters
15
+ * @returns Cube solid
16
+ * @group primitives
17
+ * @shortname cube
18
+ * @drawable true
19
+ */
12
20
  cube(inputs: Inputs.JSCAD.CubeDto): Inputs.JSCAD.JSCADEntity;
21
+ /**
22
+ * Create a 3D cubes on multiple center points
23
+ * @param inputs Cube with multiple center points parameters
24
+ * @returns List of cube solids
25
+ * @group primitives on centers
26
+ * @shortname cubes
27
+ * @drawable true
28
+ */
13
29
  cubesOnCenterPoints(inputs: Inputs.JSCAD.CubeCentersDto): Inputs.JSCAD.JSCADEntity[];
30
+ /**
31
+ * Create a 3D cuboid shape
32
+ * @param inputs Cuboid parameters
33
+ * @returns Cuboid solid
34
+ * @group primitives
35
+ * @shortname cuboid
36
+ * @drawable true
37
+ */
14
38
  cuboid(inputs: Inputs.JSCAD.CuboidDto): Inputs.JSCAD.JSCADEntity;
39
+ /**
40
+ * Create a 3D cuboids on multiple center points
41
+ * @param inputs Cuboids with multiple center point parameters
42
+ * @returns List of cuboid solids
43
+ * @group primitives on centers
44
+ * @shortname cuboids
45
+ * @drawable true
46
+ */
15
47
  cuboidsOnCenterPoints(inputs: Inputs.JSCAD.CuboidCentersDto): Inputs.JSCAD.JSCADEntity[];
48
+ /**
49
+ * Create a 3D elliptic cylinder solid
50
+ * @param inputs Elliptic cylinder parameters
51
+ * @returns Elliptic cylinder solid
52
+ * @group primitives
53
+ * @shortname cylinder elliptic
54
+ * @drawable true
55
+ */
16
56
  cylinderElliptic(inputs: Inputs.JSCAD.CylidnerEllipticDto): Inputs.JSCAD.JSCADEntity;
57
+ /**
58
+ * Create a 3D elliptic cylinders on multiple center points
59
+ * @param inputs Elliptic cylinders with multiple center point parameters
60
+ * @returns List of elliptic cylinders solids
61
+ * @group primitives on centers
62
+ * @shortname cylinder elliptic
63
+ * @drawable true
64
+ */
17
65
  cylinderEllipticOnCenterPoints(inputs: Inputs.JSCAD.CylidnerCentersEllipticDto): Inputs.JSCAD.JSCADEntity[];
66
+ /**
67
+ * Create a 3D cylinder solid
68
+ * @param inputs Cylinder parameters
69
+ * @returns Cylinder solid
70
+ * @group primitives
71
+ * @shortname cylinder
72
+ * @drawable true
73
+ */
18
74
  cylinder(inputs: Inputs.JSCAD.CylidnerDto): Inputs.JSCAD.JSCADEntity;
75
+ /**
76
+ * Create a 3D cylinders on multiple center points
77
+ * @param inputs Cylinders with multiple center point parameters
78
+ * @returns List of cylinder solids
79
+ * @group primitives on centers
80
+ * @shortname cylinder
81
+ * @drawable true
82
+ */
19
83
  cylindersOnCenterPoints(inputs: Inputs.JSCAD.CylidnerCentersDto): Inputs.JSCAD.JSCADEntity[];
84
+ /**
85
+ * Create a 3D ellipsoid solid
86
+ * @param inputs Ellipsoid parameters
87
+ * @returns Ellipsoid solid
88
+ * @group primitives
89
+ * @shortname ellipsoid
90
+ * @drawable true
91
+ */
20
92
  ellipsoid(inputs: Inputs.JSCAD.EllipsoidDto): Inputs.JSCAD.JSCADEntity;
93
+ /**
94
+ * Create a 3D ellipsoids on multiple center points
95
+ * @param inputs Ellipsoid parameters with multiple center points
96
+ * @returns List of ellipsoid solids
97
+ * @group primitives on centers
98
+ * @shortname ellipsoid
99
+ * @drawable true
100
+ */
21
101
  ellipsoidsOnCenterPoints(inputs: Inputs.JSCAD.EllipsoidCentersDto): Inputs.JSCAD.JSCADEntity[];
102
+ /**
103
+ * Create a 3D geodesic sphere solid
104
+ * @param inputs Geodesic sphere parameters
105
+ * @returns Geodesic sphere solid
106
+ * @group primitives
107
+ * @shortname geodesic sphere
108
+ * @drawable true
109
+ */
22
110
  geodesicSphere(inputs: Inputs.JSCAD.GeodesicSphereDto): Inputs.JSCAD.JSCADEntity;
111
+ /**
112
+ * Create a 3D geodesic spheres on multiple center points
113
+ * @param inputs Geodesic sphere parameters with multiple center points
114
+ * @returns List of geodesic spheres
115
+ * @group primitives on centers
116
+ * @shortname geodesic sphere
117
+ * @drawable true
118
+ */
23
119
  geodesicSpheresOnCenterPoints(inputs: Inputs.JSCAD.GeodesicSphereCentersDto): Inputs.JSCAD.JSCADEntity[];
120
+ /**
121
+ * Create a 3D rounded cuboid solid
122
+ * @param inputs Rounded cuboid parameters
123
+ * @returns Rounded cuboid solid
124
+ * @group primitives
125
+ * @shortname rounded cuboid
126
+ * @drawable true
127
+ */
24
128
  roundedCuboid(inputs: Inputs.JSCAD.RoundedCuboidDto): Inputs.JSCAD.JSCADEntity;
129
+ /**
130
+ * Create a 3D rounded cuboids on multiple center points
131
+ * @param inputs Rounded cuboids parameters with multiple center points
132
+ * @returns List of rounded cuboids
133
+ * @group primitives on centers
134
+ * @shortname rounded cuboid
135
+ * @drawable true
136
+ */
25
137
  roundedCuboidsOnCenterPoints(inputs: Inputs.JSCAD.RoundedCuboidCentersDto): Inputs.JSCAD.JSCADEntity[];
138
+ /**
139
+ * Create a 3D rounded cylinder solid
140
+ * @param inputs Rounded cylinder parameters
141
+ * @returns Rounded cylinder solid
142
+ * @group primitives
143
+ * @shortname rounded cylinder
144
+ * @drawable true
145
+ */
26
146
  roundedCylinder(inputs: Inputs.JSCAD.RoundedCylidnerDto): Inputs.JSCAD.JSCADEntity;
147
+ /**
148
+ * Create a 3D rounded cylinders on multiple center points
149
+ * @param inputs Rounded cylinders parameters with multiple center points
150
+ * @returns List of rounded cylinders
151
+ * @group primitives on centers
152
+ * @shortname rounded cylinder
153
+ * @drawable true
154
+ */
27
155
  roundedCylindersOnCenterPoints(inputs: Inputs.JSCAD.RoundedCylidnerCentersDto): Inputs.JSCAD.JSCADEntity[];
156
+ /**
157
+ * Create a 3D sphere solid
158
+ * @param inputs Sphere parameters
159
+ * @returns Sphere solid
160
+ * @group primitives
161
+ * @shortname sphere
162
+ * @drawable true
163
+ */
28
164
  sphere(inputs: Inputs.JSCAD.SphereDto): Inputs.JSCAD.JSCADEntity;
165
+ /**
166
+ * Create a 3D sphere on multiple center points
167
+ * @param inputs Sphere parameters with multiple center points
168
+ * @returns List of spheres
169
+ * @group primitives on centers
170
+ * @shortname sphere
171
+ * @drawable true
172
+ */
29
173
  spheresOnCenterPoints(inputs: Inputs.JSCAD.SphereCentersDto): Inputs.JSCAD.JSCADEntity[];
174
+ /**
175
+ * Create a 3D torus solid
176
+ * @param inputs Torus parameters
177
+ * @returns Torus solid
178
+ * @group primitives
179
+ * @shortname torus
180
+ * @drawable true
181
+ */
30
182
  torus(inputs: Inputs.JSCAD.TorusDto): Inputs.JSCAD.JSCADEntity;
183
+ /**
184
+ * Create a 3D shape from poylgon points that have to be nested arrays of points
185
+ * @param inputs points
186
+ * @returns shape
187
+ * @group shapes
188
+ * @shortname from polygon points
189
+ * @drawable true
190
+ */
31
191
  fromPolygonPoints(inputs: Inputs.JSCAD.FromPolygonPoints): Inputs.JSCAD.JSCADEntity;
32
192
  }