@bitbybit-dev/jscad 1.3.2 → 1.4.0-rc.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.
- package/README.md +1 -1
- package/lib/api/dto-registry.d.ts +8 -0
- package/lib/api/dto-registry.js +139 -0
- package/lib/api/inputs/jscad-inputs.d.ts +332 -432
- package/lib/api/inputs/jscad-inputs.js +251 -301
- package/lib/api/jscad-service.js +8 -5
- package/lib/api/resolved-inputs/index.d.ts +80 -0
- package/lib/api/resolved-inputs/index.js +1 -0
- package/lib/api/services/jscad-colors.js +5 -2
- package/lib/api/services/jscad-expansions.d.ts +1 -1
- package/lib/api/services/jscad-expansions.js +11 -8
- package/lib/api/services/jscad-extrusions.js +18 -12
- package/lib/api/services/jscad-path.js +16 -11
- package/lib/api/services/jscad-polygon.d.ts +4 -4
- package/lib/api/services/jscad-polygon.js +28 -20
- package/lib/api/services/jscad-shapes.js +94 -73
- package/lib/api/services/jscad-text.js +20 -15
- package/lib/api/validation/index.d.ts +11 -0
- package/lib/api/validation/index.js +17 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +3 -0
- package/package.json +2 -2
package/lib/api/jscad-service.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GeometryHelper, Lists, Point, Transforms, Vector } from "@bitbybit-dev/base";
|
|
1
|
+
import { GeometryHelper, Lists, Point, Transforms, Vector, resolveDto } from "@bitbybit-dev/base";
|
|
2
2
|
import { MathBitByBit } from "@bitbybit-dev/base";
|
|
3
3
|
import { computeVertexNormals } from "@bitbybit-dev/base/lib/api/services/helpers/mesh-normals";
|
|
4
4
|
import { JSCADExpansions } from "./services/jscad-expansions";
|
|
@@ -8,6 +8,7 @@ import { JSCADPath } from "./services/jscad-path";
|
|
|
8
8
|
import { JSCADPolygon } from "./services/jscad-polygon";
|
|
9
9
|
import { JSCADShapes } from "./services/jscad-shapes";
|
|
10
10
|
import { JSCADText } from "./services/jscad-text";
|
|
11
|
+
import * as Inputs from "./inputs/jscad-inputs";
|
|
11
12
|
import { JSCADHulls } from "./services/jscad-hulls";
|
|
12
13
|
import { JSCADColors } from "./services/jscad-colors";
|
|
13
14
|
/**
|
|
@@ -274,8 +275,9 @@ export class Jscad {
|
|
|
274
275
|
* ```
|
|
275
276
|
*/
|
|
276
277
|
downloadGeometryDxf(inputs) {
|
|
277
|
-
const
|
|
278
|
-
const
|
|
278
|
+
const resolved = resolveDto(Inputs.JSCAD.DownloadGeometryDto, inputs);
|
|
279
|
+
const options = resolved.options ? resolved.options : {};
|
|
280
|
+
const rawData = this.jscad.DXFSERIALIZER.serialize(options, resolved.geometry);
|
|
279
281
|
const madeBlob = new Blob(rawData);
|
|
280
282
|
return { blob: madeBlob };
|
|
281
283
|
}
|
|
@@ -294,8 +296,9 @@ export class Jscad {
|
|
|
294
296
|
* ```
|
|
295
297
|
*/
|
|
296
298
|
downloadGeometry3MF(inputs) {
|
|
297
|
-
const
|
|
298
|
-
const
|
|
299
|
+
const resolved = resolveDto(Inputs.JSCAD.DownloadGeometryDto, inputs);
|
|
300
|
+
const options = resolved.options ? resolved.options : {};
|
|
301
|
+
const rawData = this.jscad.THREEMFSERIALIZER.serialize(options, resolved.geometry);
|
|
299
302
|
const madeBlob = new Blob(rawData);
|
|
300
303
|
return { blob: madeBlob };
|
|
301
304
|
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { WithDefaults } from "@bitbybit-dev/base";
|
|
2
|
+
import * as Inputs from "../inputs";
|
|
3
|
+
export * from "@bitbybit-dev/base/lib/api/resolved-inputs";
|
|
4
|
+
/**
|
|
5
|
+
* The JSCAD inputs DTOs as their defaults leave them: every property with a default is present,
|
|
6
|
+
* the way `resolveDto` hands a DTO to the code that reads it.
|
|
7
|
+
*/
|
|
8
|
+
export declare namespace JSCAD {
|
|
9
|
+
type BooleanObjectsDto = Inputs.JSCAD.BooleanObjectsDto;
|
|
10
|
+
type BooleanObjectsFromDto = Inputs.JSCAD.BooleanObjectsFromDto;
|
|
11
|
+
type BooleanTwoObjectsDto = Inputs.JSCAD.BooleanTwoObjectsDto;
|
|
12
|
+
type CircleDto = WithDefaults<Inputs.JSCAD.CircleDto, "center" | "radius" | "segments">;
|
|
13
|
+
type ColorizeDto = WithDefaults<Inputs.JSCAD.ColorizeDto, "color">;
|
|
14
|
+
type CubeCentersDto = WithDefaults<Inputs.JSCAD.CubeCentersDto, "size">;
|
|
15
|
+
type CubeDto = WithDefaults<Inputs.JSCAD.CubeDto, "center" | "size">;
|
|
16
|
+
type CuboidCentersDto = WithDefaults<Inputs.JSCAD.CuboidCentersDto, "width" | "length" | "height">;
|
|
17
|
+
type CuboidDto = WithDefaults<Inputs.JSCAD.CuboidDto, "center" | "width" | "length" | "height">;
|
|
18
|
+
type CuboidSharedDto = WithDefaults<Inputs.JSCAD.CuboidSharedDto, "width" | "length" | "height">;
|
|
19
|
+
type CurveDto = Inputs.JSCAD.CurveDto;
|
|
20
|
+
type CylidnerCentersDto = WithDefaults<Inputs.JSCAD.CylidnerCentersDto, "height" | "radius" | "segments">;
|
|
21
|
+
type CylidnerCentersEllipticDto = WithDefaults<Inputs.JSCAD.CylidnerCentersEllipticDto, "height" | "startRadius" | "endRadius" | "segments">;
|
|
22
|
+
type CylidnerDto = WithDefaults<Inputs.JSCAD.CylidnerDto, "center" | "height" | "radius" | "segments">;
|
|
23
|
+
type CylidnerEllipticDto = WithDefaults<Inputs.JSCAD.CylidnerEllipticDto, "center" | "height" | "startRadius" | "endRadius" | "segments">;
|
|
24
|
+
type CylinderSharedDto = WithDefaults<Inputs.JSCAD.CylinderSharedDto, "height" | "radius" | "segments">;
|
|
25
|
+
type CylinderTextDto = WithDefaults<Inputs.JSCAD.CylinderTextDto, "text" | "extrusionHeight" | "extrusionSize" | "segments" | "xOffset" | "yOffset" | "height" | "lineSpacing" | "letterSpacing" | "align" | "extrudeOffset">;
|
|
26
|
+
type DownloadGeometryDto = WithDefaults<Inputs.JSCAD.DownloadGeometryDto, "fileName">;
|
|
27
|
+
type DownloadSolidDto = Inputs.JSCAD.DownloadSolidDto;
|
|
28
|
+
type DownloadSolidsDto = Inputs.JSCAD.DownloadSolidsDto;
|
|
29
|
+
type DrawPathDto<T> = WithDefaults<Inputs.JSCAD.DrawPathDto<T>, "colour" | "opacity" | "width" | "updatable">;
|
|
30
|
+
type DrawSolidMeshDto<T> = WithDefaults<Inputs.JSCAD.DrawSolidMeshDto<T>, "opacity" | "colours" | "updatable" | "hidden" | "drawTwoSided" | "backFaceColour" | "backFaceOpacity">;
|
|
31
|
+
type DrawSolidMeshesDto<T> = WithDefaults<Inputs.JSCAD.DrawSolidMeshesDto<T>, "opacity" | "colours" | "updatable" | "hidden" | "drawTwoSided" | "backFaceColour" | "backFaceOpacity">;
|
|
32
|
+
type EllipseDto = WithDefaults<Inputs.JSCAD.EllipseDto, "center" | "radius" | "segments">;
|
|
33
|
+
type EllipsoidCentersDto = WithDefaults<Inputs.JSCAD.EllipsoidCentersDto, "radius" | "segments">;
|
|
34
|
+
type EllipsoidDto = WithDefaults<Inputs.JSCAD.EllipsoidDto, "center" | "radius" | "segments">;
|
|
35
|
+
type EllipsoidSharedDto = WithDefaults<Inputs.JSCAD.EllipsoidSharedDto, "radius" | "segments">;
|
|
36
|
+
type ExpandDto = WithDefaults<Inputs.JSCAD.ExpandDto, "delta" | "corners" | "segments">;
|
|
37
|
+
type ExpansionDto = WithDefaults<Inputs.JSCAD.ExpansionDto, "delta" | "corners" | "segments">;
|
|
38
|
+
type ExtrudeLinearDto = WithDefaults<Inputs.JSCAD.ExtrudeLinearDto, "height" | "twistAngle" | "twistSteps">;
|
|
39
|
+
type ExtrudeRectangularDto = WithDefaults<Inputs.JSCAD.ExtrudeRectangularDto, "height" | "size">;
|
|
40
|
+
type ExtrudeRectangularPointsDto = WithDefaults<Inputs.JSCAD.ExtrudeRectangularPointsDto, "height" | "size">;
|
|
41
|
+
type ExtrudeRectangularSharedDto = WithDefaults<Inputs.JSCAD.ExtrudeRectangularSharedDto, "height" | "size">;
|
|
42
|
+
type ExtrudeRotateDto = WithDefaults<Inputs.JSCAD.ExtrudeRotateDto, "angle" | "startAngle" | "segments">;
|
|
43
|
+
type FromPolygonPoints = Inputs.JSCAD.FromPolygonPoints;
|
|
44
|
+
type GeodesicSphereCentersDto = WithDefaults<Inputs.JSCAD.GeodesicSphereCentersDto, "radius" | "frequency">;
|
|
45
|
+
type GeodesicSphereDto = WithDefaults<Inputs.JSCAD.GeodesicSphereDto, "center" | "radius" | "frequency">;
|
|
46
|
+
type GeodesicSphereSharedDto = WithDefaults<Inputs.JSCAD.GeodesicSphereSharedDto, "radius" | "frequency">;
|
|
47
|
+
type HullDto = Inputs.JSCAD.HullDto;
|
|
48
|
+
type MeshDto = Inputs.JSCAD.MeshDto;
|
|
49
|
+
type MeshesDto = Inputs.JSCAD.MeshesDto;
|
|
50
|
+
type MinkowskiSumDto = Inputs.JSCAD.MinkowskiSumDto;
|
|
51
|
+
type PathAppendArcDto = WithDefaults<Inputs.JSCAD.PathAppendArcDto, "endPoint" | "xAxisRotation" | "clockwise" | "large" | "segments" | "radiusX" | "radiusY">;
|
|
52
|
+
type PathAppendPointsDto = Inputs.JSCAD.PathAppendPointsDto;
|
|
53
|
+
type PathAppendPolylineDto = Inputs.JSCAD.PathAppendPolylineDto;
|
|
54
|
+
type PathDto = Inputs.JSCAD.PathDto;
|
|
55
|
+
type PathFromPointsDto = WithDefaults<Inputs.JSCAD.PathFromPointsDto, "closed">;
|
|
56
|
+
type PathFromPolylineDto = WithDefaults<Inputs.JSCAD.PathFromPolylineDto, "closed">;
|
|
57
|
+
type PathsFromPointsDto = Inputs.JSCAD.PathsFromPointsDto;
|
|
58
|
+
type PointsDto = Inputs.JSCAD.PointsDto;
|
|
59
|
+
type PolylineDto = Inputs.JSCAD.PolylineDto;
|
|
60
|
+
type PolylinePropertiesDto = WithDefaults<Inputs.JSCAD.PolylinePropertiesDto, "isClosed">;
|
|
61
|
+
type RectangleDto = WithDefaults<Inputs.JSCAD.RectangleDto, "center" | "width" | "length">;
|
|
62
|
+
type RoundedCuboidCentersDto = WithDefaults<Inputs.JSCAD.RoundedCuboidCentersDto, "roundRadius" | "width" | "length" | "height" | "segments">;
|
|
63
|
+
type RoundedCuboidDto = WithDefaults<Inputs.JSCAD.RoundedCuboidDto, "center" | "roundRadius" | "width" | "length" | "height" | "segments">;
|
|
64
|
+
type RoundedCuboidSharedDto = WithDefaults<Inputs.JSCAD.RoundedCuboidSharedDto, "roundRadius" | "width" | "length" | "height" | "segments">;
|
|
65
|
+
type RoundedCylidnerCentersDto = WithDefaults<Inputs.JSCAD.RoundedCylidnerCentersDto, "roundRadius" | "height" | "radius" | "segments">;
|
|
66
|
+
type RoundedCylidnerDto = WithDefaults<Inputs.JSCAD.RoundedCylidnerDto, "center" | "roundRadius" | "height" | "radius" | "segments">;
|
|
67
|
+
type RoundedCylinderSharedDto = WithDefaults<Inputs.JSCAD.RoundedCylinderSharedDto, "roundRadius" | "height" | "radius" | "segments">;
|
|
68
|
+
type RoundedRectangleDto = WithDefaults<Inputs.JSCAD.RoundedRectangleDto, "center" | "roundRadius" | "segments" | "width" | "length">;
|
|
69
|
+
type SolidDto = Inputs.JSCAD.SolidDto;
|
|
70
|
+
type SphereCentersDto = WithDefaults<Inputs.JSCAD.SphereCentersDto, "radius" | "segments">;
|
|
71
|
+
type SphereDto = WithDefaults<Inputs.JSCAD.SphereDto, "center" | "radius" | "segments">;
|
|
72
|
+
type SphereSharedDto = WithDefaults<Inputs.JSCAD.SphereSharedDto, "radius" | "segments">;
|
|
73
|
+
type SphereTextDto = WithDefaults<Inputs.JSCAD.SphereTextDto, "text" | "radius" | "segments" | "xOffset" | "yOffset" | "height" | "lineSpacing" | "letterSpacing" | "align" | "extrudeOffset">;
|
|
74
|
+
type SquareDto = WithDefaults<Inputs.JSCAD.SquareDto, "center" | "size">;
|
|
75
|
+
type StarDto = WithDefaults<Inputs.JSCAD.StarDto, "center" | "vertices" | "density" | "outerRadius" | "innerRadius" | "startAngle">;
|
|
76
|
+
type TextDto = WithDefaults<Inputs.JSCAD.TextDto, "text" | "segments" | "xOffset" | "yOffset" | "height" | "lineSpacing" | "letterSpacing" | "align" | "extrudeOffset">;
|
|
77
|
+
type TorusDto = WithDefaults<Inputs.JSCAD.TorusDto, "center" | "innerRadius" | "outerRadius" | "innerSegments" | "outerSegments" | "innerRotation" | "outerRotation" | "startAngle">;
|
|
78
|
+
type TransformSolidDto = Inputs.JSCAD.TransformSolidDto;
|
|
79
|
+
type TransformSolidsDto = Inputs.JSCAD.TransformSolidsDto;
|
|
80
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@bitbybit-dev/base/lib/api/resolved-inputs";
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as Inputs from "../inputs/jscad-inputs";
|
|
2
|
+
import { resolveDto } from "@bitbybit-dev/base";
|
|
1
3
|
/**
|
|
2
4
|
* Giving JSCAD geometry a color of its own. A colored entity is always drawn in that color, ahead
|
|
3
5
|
* of whatever color the drawing options ask for; the color survives transforms but a boolean result
|
|
@@ -24,8 +26,9 @@ export class JSCADColors {
|
|
|
24
26
|
* ```
|
|
25
27
|
*/
|
|
26
28
|
colorize(inputs) {
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
+
const resolved = resolveDto(Inputs.JSCAD.ColorizeDto, inputs);
|
|
30
|
+
const geometry = resolved.geometry;
|
|
31
|
+
const color = resolved.color;
|
|
29
32
|
return this.jscad.colors.colorize(this.jscad.colors.hexToRgb(color), geometry);
|
|
30
33
|
}
|
|
31
34
|
}
|
|
@@ -27,7 +27,7 @@ export declare class JSCADExpansions {
|
|
|
27
27
|
* const grown = await bitbybit.jscad.expansions.expand({ geometry: square, delta: 1, corners: Bit.Inputs.JSCAD.solidCornerTypeEnum.round, segments: 16 });
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
|
-
expand(inputs: Inputs.JSCAD.
|
|
30
|
+
expand(inputs: Inputs.JSCAD.ExpandDto): Inputs.JSCAD.JSCADEntity;
|
|
31
31
|
/**
|
|
32
32
|
* Builds the outline of a 2D shape or path at distance `delta` from the original, outward for
|
|
33
33
|
* positive and inward for negative.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as Inputs from "../inputs/jscad-inputs";
|
|
2
2
|
import { asEntity, asKind, oneOrMany } from "./entity-narrowing";
|
|
3
|
+
import { resolveDto } from "@bitbybit-dev/base";
|
|
3
4
|
/**
|
|
4
5
|
* Growing and shrinking JSCAD geometry by a distance: `expand` moves every boundary outward, or
|
|
5
6
|
* inward for a negative distance, and `offset` builds the outline at that distance. Both work on
|
|
@@ -29,12 +30,13 @@ export class JSCADExpansions {
|
|
|
29
30
|
* ```
|
|
30
31
|
*/
|
|
31
32
|
expand(inputs) {
|
|
32
|
-
const
|
|
33
|
-
const
|
|
33
|
+
const resolved = resolveDto(Inputs.JSCAD.ExpandDto, inputs);
|
|
34
|
+
const geometry = asKind(oneOrMany(resolved.geometry));
|
|
35
|
+
const corners = resolved.corners;
|
|
34
36
|
const result = this.jscad.expansions.expand({
|
|
35
|
-
delta:
|
|
37
|
+
delta: resolved.delta,
|
|
36
38
|
corners,
|
|
37
|
-
segments:
|
|
39
|
+
segments: resolved.segments,
|
|
38
40
|
}, ...geometry);
|
|
39
41
|
return asEntity(result);
|
|
40
42
|
}
|
|
@@ -56,12 +58,13 @@ export class JSCADExpansions {
|
|
|
56
58
|
* ```
|
|
57
59
|
*/
|
|
58
60
|
offset(inputs) {
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
+
const resolved = resolveDto(Inputs.JSCAD.ExpansionDto, inputs);
|
|
62
|
+
const geometry = asKind(oneOrMany(resolved.geometry));
|
|
63
|
+
const corners = resolved.corners;
|
|
61
64
|
const result = this.jscad.expansions.offset({
|
|
62
|
-
delta:
|
|
65
|
+
delta: resolved.delta,
|
|
63
66
|
corners,
|
|
64
|
-
segments:
|
|
67
|
+
segments: resolved.segments,
|
|
65
68
|
}, ...geometry);
|
|
66
69
|
return asEntity(result);
|
|
67
70
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { resolveDto } from "@bitbybit-dev/base";
|
|
2
|
+
import * as Inputs from "../inputs/jscad-inputs";
|
|
1
3
|
import { asKind, asRegion, oneOrMany } from "./entity-narrowing";
|
|
2
4
|
/**
|
|
3
5
|
* Turning flat JSCAD shapes into solids: straight extrusion along Z with an optional twist, a wall
|
|
@@ -28,11 +30,12 @@ export class JSCADExtrusions {
|
|
|
28
30
|
* ```
|
|
29
31
|
*/
|
|
30
32
|
extrudeLinear(inputs) {
|
|
31
|
-
const
|
|
33
|
+
const resolved = resolveDto(Inputs.JSCAD.ExtrudeLinearDto, inputs);
|
|
34
|
+
const geometry = asKind(oneOrMany(resolved.geometry));
|
|
32
35
|
const extrusions = this.jscad.extrusions.extrudeLinear({
|
|
33
|
-
height:
|
|
34
|
-
twistAngle: this.math.degToRad({ number:
|
|
35
|
-
twistSteps:
|
|
36
|
+
height: resolved.height,
|
|
37
|
+
twistAngle: this.math.degToRad({ number: resolved.twistAngle }),
|
|
38
|
+
twistSteps: resolved.twistSteps
|
|
36
39
|
}, ...geometry);
|
|
37
40
|
return extrusions;
|
|
38
41
|
}
|
|
@@ -54,8 +57,9 @@ export class JSCADExtrusions {
|
|
|
54
57
|
* ```
|
|
55
58
|
*/
|
|
56
59
|
extrudeRectangular(inputs) {
|
|
57
|
-
const
|
|
58
|
-
const
|
|
60
|
+
const resolved = resolveDto(Inputs.JSCAD.ExtrudeRectangularDto, inputs);
|
|
61
|
+
const geometry = asKind(oneOrMany(resolved.geometry));
|
|
62
|
+
const extrusions = this.jscad.extrusions.extrudeRectangular({ height: resolved.height, size: resolved.size }, ...geometry);
|
|
59
63
|
return extrusions;
|
|
60
64
|
}
|
|
61
65
|
/**
|
|
@@ -75,10 +79,11 @@ export class JSCADExtrusions {
|
|
|
75
79
|
* ```
|
|
76
80
|
*/
|
|
77
81
|
extrudeRectangularPoints(inputs) {
|
|
78
|
-
const
|
|
82
|
+
const resolved = resolveDto(Inputs.JSCAD.ExtrudeRectangularPointsDto, inputs);
|
|
83
|
+
const twoDimensionalPoints = resolved.points.map(pt => [pt[0], pt[1]]);
|
|
79
84
|
const duplicatePointsRemoved = this.geometryHelper.removeConsecutiveVectorDuplicates(twoDimensionalPoints);
|
|
80
85
|
const path = this.jscad.geometries.path2.fromPoints({}, duplicatePointsRemoved);
|
|
81
|
-
const extrusion = this.extrudeRectangular({ height:
|
|
86
|
+
const extrusion = this.extrudeRectangular({ height: resolved.height, size: resolved.size, geometry: path });
|
|
82
87
|
return extrusion;
|
|
83
88
|
}
|
|
84
89
|
/**
|
|
@@ -99,13 +104,14 @@ export class JSCADExtrusions {
|
|
|
99
104
|
* ```
|
|
100
105
|
*/
|
|
101
106
|
extrudeRotate(inputs) {
|
|
107
|
+
const resolved = resolveDto(Inputs.JSCAD.ExtrudeRotateDto, inputs);
|
|
102
108
|
const options = {
|
|
103
|
-
angle: this.math.degToRad({ number:
|
|
104
|
-
startAngle: this.math.degToRad({ number:
|
|
109
|
+
angle: this.math.degToRad({ number: resolved.angle }),
|
|
110
|
+
startAngle: this.math.degToRad({ number: resolved.startAngle }),
|
|
105
111
|
overflow: "cap",
|
|
106
|
-
segments:
|
|
112
|
+
segments: resolved.segments
|
|
107
113
|
};
|
|
108
|
-
const extrusion = this.jscad.extrusions.extrudeRotate(options, asRegion(
|
|
114
|
+
const extrusion = this.jscad.extrusions.extrudeRotate(options, asRegion(resolved.polygon, "extrudeRotate"));
|
|
109
115
|
return extrusion;
|
|
110
116
|
}
|
|
111
117
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { resolveDto } from "@bitbybit-dev/base";
|
|
2
|
+
import * as Inputs from "../inputs/jscad-inputs";
|
|
1
3
|
import { asPath } from "./entity-narrowing";
|
|
2
4
|
/**
|
|
3
5
|
* Building JSCAD paths, the 2D polylines that walls are extruded along, offsets follow and filled
|
|
@@ -27,8 +29,9 @@ export class JSCADPath {
|
|
|
27
29
|
* ```
|
|
28
30
|
*/
|
|
29
31
|
createFromPoints(inputs) {
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
+
const resolved = resolveDto(Inputs.JSCAD.PathFromPointsDto, inputs);
|
|
33
|
+
const twoDimensionalPoints = resolved.points.map(pt => [pt[0], pt[1]]);
|
|
34
|
+
return this.removeDuplicatesAndCreateFromPoints(twoDimensionalPoints, resolved.closed);
|
|
32
35
|
}
|
|
33
36
|
/**
|
|
34
37
|
* Builds one 2D path per list of points, in the same order; a list whose last point coincides
|
|
@@ -71,8 +74,9 @@ export class JSCADPath {
|
|
|
71
74
|
* ```
|
|
72
75
|
*/
|
|
73
76
|
createFromPolyline(inputs) {
|
|
74
|
-
const
|
|
75
|
-
|
|
77
|
+
const resolved = resolveDto(Inputs.JSCAD.PathFromPolylineDto, inputs, { polyline: Inputs.JSCAD.PolylinePropertiesDto });
|
|
78
|
+
const twoDimensionalPoints = resolved.polyline.points.map(pt => [pt[0], pt[1]]);
|
|
79
|
+
return this.removeDuplicatesAndCreateFromPoints(twoDimensionalPoints, resolved.closed);
|
|
76
80
|
}
|
|
77
81
|
/**
|
|
78
82
|
* Makes an empty open 2D path with no points, a starting point for `appendPoints`,
|
|
@@ -166,16 +170,17 @@ export class JSCADPath {
|
|
|
166
170
|
* ```
|
|
167
171
|
*/
|
|
168
172
|
appendArc(inputs) {
|
|
169
|
-
const
|
|
170
|
-
const
|
|
173
|
+
const resolved = resolveDto(Inputs.JSCAD.PathAppendArcDto, inputs);
|
|
174
|
+
const endpoint = [resolved.endPoint[0], resolved.endPoint[1]];
|
|
175
|
+
const radius = [resolved.radiusX, resolved.radiusY];
|
|
171
176
|
return this.jscad.geometries.path2.appendArc({
|
|
172
177
|
endpoint,
|
|
173
178
|
radius,
|
|
174
|
-
xaxisrotation: this.math.degToRad({ number:
|
|
175
|
-
clockwise:
|
|
176
|
-
large:
|
|
177
|
-
segments:
|
|
178
|
-
}, asPath(
|
|
179
|
+
xaxisrotation: this.math.degToRad({ number: resolved.xAxisRotation }),
|
|
180
|
+
clockwise: resolved.clockwise,
|
|
181
|
+
large: resolved.large,
|
|
182
|
+
segments: resolved.segments,
|
|
183
|
+
}, asPath(resolved.path, "path operations"));
|
|
179
184
|
}
|
|
180
185
|
removeDuplicatesAndCreateFromPoints(twoDimensionalPoints, closed) {
|
|
181
186
|
const duplicatePointsRemoved = this.geometryHelper.removeConsecutiveVectorDuplicates(twoDimensionalPoints);
|
|
@@ -17,9 +17,9 @@ export declare class JSCADPolygon {
|
|
|
17
17
|
* Builds a filled 2D shape from the outline points, taken in order and closed back to the
|
|
18
18
|
* first.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
21
|
-
* three distinct points are needed. Counter-clockwise order gives a normal shape,
|
|
22
|
-
* gives a negative one.
|
|
20
|
+
* The points may be 2D or 3D; only X and Y are used. Repeated consecutive points are removed
|
|
21
|
+
* and at least three distinct points are needed. Counter-clockwise order gives a normal shape,
|
|
22
|
+
* clockwise gives a negative one.
|
|
23
23
|
* @param inputs - The outline points
|
|
24
24
|
* @returns The 2D shape
|
|
25
25
|
* @group from
|
|
@@ -30,7 +30,7 @@ export declare class JSCADPolygon {
|
|
|
30
30
|
* const triangle = await bitbybit.jscad.polygon.createFromPoints({ points: [[0, 0, 0], [10, 0, 0], [5, 8, 0]] });
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
|
-
createFromPoints(inputs: Inputs.
|
|
33
|
+
createFromPoints(inputs: Inputs.JSCAD.PointsDto): Inputs.JSCAD.JSCADEntity;
|
|
34
34
|
/**
|
|
35
35
|
* Builds a filled 2D shape from the points of a polyline, closed back to the first point
|
|
36
36
|
* whatever the polyline says.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { resolveDto } from "@bitbybit-dev/base";
|
|
2
|
+
import * as Inputs from "../inputs";
|
|
1
3
|
import { asPath } from "./entity-narrowing";
|
|
2
4
|
/**
|
|
3
5
|
* Building flat JSCAD shapes, the filled 2D regions that booleans combine and extrusions turn into
|
|
@@ -15,9 +17,9 @@ export class JSCADPolygon {
|
|
|
15
17
|
* Builds a filled 2D shape from the outline points, taken in order and closed back to the
|
|
16
18
|
* first.
|
|
17
19
|
*
|
|
18
|
-
*
|
|
19
|
-
* three distinct points are needed. Counter-clockwise order gives a normal shape,
|
|
20
|
-
* gives a negative one.
|
|
20
|
+
* The points may be 2D or 3D; only X and Y are used. Repeated consecutive points are removed
|
|
21
|
+
* and at least three distinct points are needed. Counter-clockwise order gives a normal shape,
|
|
22
|
+
* clockwise gives a negative one.
|
|
21
23
|
* @param inputs - The outline points
|
|
22
24
|
* @returns The 2D shape
|
|
23
25
|
* @group from
|
|
@@ -108,7 +110,8 @@ from points or from a polyline instead.
|
|
|
108
110
|
* ```
|
|
109
111
|
*/
|
|
110
112
|
circle(inputs) {
|
|
111
|
-
|
|
113
|
+
const resolved = resolveDto(Inputs.JSCAD.CircleDto, inputs);
|
|
114
|
+
return this.jscad.primitives.circle({ center: resolved.center, radius: resolved.radius, segments: resolved.segments });
|
|
112
115
|
}
|
|
113
116
|
/**
|
|
114
117
|
* Builds a filled ellipse around a 2D `center`, with `radius` holding the X and Y half-sizes;
|
|
@@ -124,10 +127,11 @@ from points or from a polyline instead.
|
|
|
124
127
|
* ```
|
|
125
128
|
*/
|
|
126
129
|
ellipse(inputs) {
|
|
130
|
+
const resolved = resolveDto(Inputs.JSCAD.EllipseDto, inputs);
|
|
127
131
|
return this.jscad.primitives.ellipse({
|
|
128
|
-
center:
|
|
129
|
-
radius: [
|
|
130
|
-
segments:
|
|
132
|
+
center: resolved.center,
|
|
133
|
+
radius: [resolved.radius[0], resolved.radius[1]],
|
|
134
|
+
segments: resolved.segments
|
|
131
135
|
});
|
|
132
136
|
}
|
|
133
137
|
/**
|
|
@@ -143,9 +147,10 @@ from points or from a polyline instead.
|
|
|
143
147
|
* ```
|
|
144
148
|
*/
|
|
145
149
|
rectangle(inputs) {
|
|
150
|
+
const resolved = resolveDto(Inputs.JSCAD.RectangleDto, inputs);
|
|
146
151
|
return this.jscad.primitives.rectangle({
|
|
147
|
-
center: [
|
|
148
|
-
size: [
|
|
152
|
+
center: [resolved.center[0], resolved.center[1]],
|
|
153
|
+
size: [resolved.width, resolved.length]
|
|
149
154
|
});
|
|
150
155
|
}
|
|
151
156
|
/**
|
|
@@ -165,11 +170,12 @@ from points or from a polyline instead.
|
|
|
165
170
|
* ```
|
|
166
171
|
*/
|
|
167
172
|
roundedRectangle(inputs) {
|
|
173
|
+
const resolved = resolveDto(Inputs.JSCAD.RoundedRectangleDto, inputs);
|
|
168
174
|
return this.jscad.primitives.roundedRectangle({
|
|
169
|
-
center: [
|
|
170
|
-
size: [
|
|
171
|
-
roundRadius:
|
|
172
|
-
segments:
|
|
175
|
+
center: [resolved.center[0], resolved.center[1]],
|
|
176
|
+
size: [resolved.width, resolved.length],
|
|
177
|
+
roundRadius: resolved.roundRadius,
|
|
178
|
+
segments: resolved.segments,
|
|
173
179
|
});
|
|
174
180
|
}
|
|
175
181
|
/**
|
|
@@ -186,7 +192,8 @@ from points or from a polyline instead.
|
|
|
186
192
|
* ```
|
|
187
193
|
*/
|
|
188
194
|
square(inputs) {
|
|
189
|
-
|
|
195
|
+
const resolved = resolveDto(Inputs.JSCAD.SquareDto, inputs);
|
|
196
|
+
return this.jscad.primitives.square({ center: [resolved.center[0], resolved.center[1]], size: resolved.size });
|
|
190
197
|
}
|
|
191
198
|
/**
|
|
192
199
|
* Builds a filled star with `vertices` tips around a 2D `center`, the tips at `outerRadius` and
|
|
@@ -206,13 +213,14 @@ from points or from a polyline instead.
|
|
|
206
213
|
* ```
|
|
207
214
|
*/
|
|
208
215
|
star(inputs) {
|
|
216
|
+
const resolved = resolveDto(Inputs.JSCAD.StarDto, inputs);
|
|
209
217
|
return this.jscad.primitives.star({
|
|
210
|
-
center: [
|
|
211
|
-
vertices:
|
|
212
|
-
density:
|
|
213
|
-
outerRadius:
|
|
214
|
-
innerRadius:
|
|
215
|
-
startAngle: this.math.degToRad({ number:
|
|
218
|
+
center: [resolved.center[0], resolved.center[1]],
|
|
219
|
+
vertices: resolved.vertices,
|
|
220
|
+
density: resolved.density,
|
|
221
|
+
outerRadius: resolved.outerRadius,
|
|
222
|
+
innerRadius: resolved.innerRadius,
|
|
223
|
+
startAngle: this.math.degToRad({ number: resolved.startAngle }),
|
|
216
224
|
});
|
|
217
225
|
}
|
|
218
226
|
removeDuplicatesAndCreateFromPoints(twoDimensionalPoints) {
|