@bitbybit-dev/manifold 1.2.0 → 1.3.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 (35) hide show
  1. package/lib/api/inputs/manifold-inputs.d.ts +521 -224
  2. package/lib/api/inputs/manifold-inputs.js +380 -135
  3. package/lib/api/manifold-service.d.ts +37 -11
  4. package/lib/api/manifold-service.js +37 -11
  5. package/lib/api/services/cross-section/cross-section-booleans.d.ts +66 -29
  6. package/lib/api/services/cross-section/cross-section-booleans.js +66 -29
  7. package/lib/api/services/cross-section/cross-section-evaluate.d.ts +38 -17
  8. package/lib/api/services/cross-section/cross-section-evaluate.js +38 -17
  9. package/lib/api/services/cross-section/cross-section-operations.d.ts +73 -33
  10. package/lib/api/services/cross-section/cross-section-operations.js +73 -33
  11. package/lib/api/services/cross-section/cross-section-shapes.d.ts +38 -17
  12. package/lib/api/services/cross-section/cross-section-shapes.js +38 -17
  13. package/lib/api/services/cross-section/cross-section-transforms.d.ts +64 -29
  14. package/lib/api/services/cross-section/cross-section-transforms.js +64 -29
  15. package/lib/api/services/cross-section/cross-section.d.ts +81 -20
  16. package/lib/api/services/cross-section/cross-section.js +81 -20
  17. package/lib/api/services/manifold/manifold-booleans.d.ts +139 -43
  18. package/lib/api/services/manifold/manifold-booleans.js +143 -43
  19. package/lib/api/services/manifold/manifold-evaluate.d.ts +134 -59
  20. package/lib/api/services/manifold/manifold-evaluate.js +141 -59
  21. package/lib/api/services/manifold/manifold-operations.d.ts +195 -108
  22. package/lib/api/services/manifold/manifold-operations.js +197 -110
  23. package/lib/api/services/manifold/manifold-shapes.d.ts +64 -26
  24. package/lib/api/services/manifold/manifold-shapes.js +66 -28
  25. package/lib/api/services/manifold/manifold-transforms.d.ts +100 -38
  26. package/lib/api/services/manifold/manifold-transforms.js +100 -38
  27. package/lib/api/services/manifold/manifold.d.ts +25 -8
  28. package/lib/api/services/manifold/manifold.js +25 -8
  29. package/lib/api/services/mesh/mesh-evaluate.d.ts +103 -32
  30. package/lib/api/services/mesh/mesh-evaluate.js +108 -33
  31. package/lib/api/services/mesh/mesh-operations.d.ts +12 -15
  32. package/lib/api/services/mesh/mesh-operations.js +12 -15
  33. package/lib/api/services/mesh/mesh.d.ts +4 -2
  34. package/lib/api/services/mesh/mesh.js +4 -2
  35. package/package.json +3 -3
@@ -1,84 +1,119 @@
1
1
  import * as Inputs from "../../inputs/manifold-inputs";
2
2
  import * as Manifold3D from "manifold-3d";
3
3
  /**
4
- * Contains various functions for transforming cross section from Manifold library
5
- * https://github.com/elalish/manifold Thanks Manifold community for developing this kernel
4
+ * Moving, turning, scaling, mirroring and warping Manifold cross-sections in the XY plane. Angles
5
+ * are in degrees and rotations turn about the origin; every method returns a new cross-section.
6
6
  */
7
7
  export declare class CrossSectionTransforms {
8
8
  constructor(_wasm: Manifold3D.ManifoldToplevel);
9
9
  /**
10
- * Scales a cross section shape with 2D vector
11
- * @param inputs cross section and scale vector
12
- * @returns Scaled cross section shape
10
+ * Scales a cross-section by a separate factor along X and Y, about the origin.
11
+ * @param inputs - The cross-section and the two factors
12
+ * @returns The scaled cross-section
13
13
  * @group transforms
14
14
  * @shortname scale 2d
15
15
  * @drawable true
16
+ * @example
17
+ * ```typescript
18
+ * const stretched = await bitbybit.manifold.crossSection.transforms.scale2D({ crossSection: square, vector: [2, 1] });
19
+ * ```
16
20
  */
17
21
  scale2D(inputs: Inputs.Manifold.Scale2DCrossSectionDto<Manifold3D.CrossSection>): Manifold3D.CrossSection;
18
22
  /**
19
- * Scales a cross section shape with single factor
20
- * @param inputs cross section and scale factor
21
- * @returns Scaled cross section shape
23
+ * Scales a cross-section uniformly about the origin by a factor.
24
+ * @param inputs - The cross-section and the factor
25
+ * @returns The scaled cross-section
22
26
  * @group transforms
23
27
  * @shortname scale uniform
24
28
  * @drawable true
29
+ * @example
30
+ * ```typescript
31
+ * const bigger = await bitbybit.manifold.crossSection.transforms.scale({ crossSection: square, factor: 2 });
32
+ * ```
25
33
  */
26
34
  scale(inputs: Inputs.Manifold.ScaleCrossSectionDto<Manifold3D.CrossSection>): Manifold3D.CrossSection;
27
35
  /**
28
- * Mirrors a cross section shape over a plane defined by a normal vector
29
- * @param inputs cross section and normal vector
30
- * @returns Mirrored cross section shape
36
+ * Mirrors a cross-section across the line through the origin that is perpendicular to the given
37
+ * normal.
38
+ * @param inputs - The cross-section and the normal of the mirror line
39
+ * @returns The mirrored cross-section
31
40
  * @group transforms
32
41
  * @shortname mirror
33
42
  * @drawable true
43
+ * @example
44
+ * ```typescript
45
+ * const other = await bitbybit.manifold.crossSection.transforms.mirror({ crossSection: outline, normal: [1, 0] });
46
+ * ```
34
47
  */
35
48
  mirror(inputs: Inputs.Manifold.MirrorCrossSectionDto<Manifold3D.CrossSection>): Manifold3D.CrossSection;
36
49
  /**
37
- * Translates a cross section shape along the vector
38
- * @param inputs cross section and trnaslation vector
39
- * @returns Translated cross section shape
50
+ * Moves a cross-section by a 2D vector, in model units.
51
+ * @param inputs - The cross-section and the vector to move it by
52
+ * @returns The moved cross-section
40
53
  * @group transforms
41
54
  * @shortname translate
42
55
  * @drawable true
56
+ * @example
57
+ * ```typescript
58
+ * const moved = await bitbybit.manifold.crossSection.transforms.translate({ crossSection: square, vector: [10, 0] });
59
+ * ```
43
60
  */
44
61
  translate(inputs: Inputs.Manifold.TranslateCrossSectionDto<Manifold3D.CrossSection>): Manifold3D.CrossSection;
45
62
  /**
46
- * Translates a cross section shape along x, y
47
- * @param inputs cross section and trnaslation coordinates
48
- * @returns Translated cross section shape
63
+ * Moves a cross-section by separate distances along X and Y, in model units.
64
+ * @param inputs - The cross-section and the two distances
65
+ * @returns The moved cross-section
49
66
  * @group transforms
50
67
  * @shortname translate xy
51
68
  * @drawable true
69
+ * @example
70
+ * ```typescript
71
+ * const moved = await bitbybit.manifold.crossSection.transforms.translateXY({ crossSection: square, x: 10, y: 5 });
72
+ * ```
52
73
  */
53
74
  translateXY(inputs: Inputs.Manifold.TranslateXYCrossSectionDto<Manifold3D.CrossSection>): Manifold3D.CrossSection;
54
75
  /**
55
- * Rotates a cross section shape along the containing degrees
56
- * @param inputs cross section and rotation degrees
57
- * @returns Rotated cross section shape
76
+ * Rotates a cross-section about the origin by an angle in degrees, counterclockwise.
77
+ * @param inputs - The cross-section and the angle in degrees
78
+ * @returns The rotated cross-section
58
79
  * @group transforms
59
80
  * @shortname rotate
60
81
  * @drawable true
82
+ * @example
83
+ * ```typescript
84
+ * const turned = await bitbybit.manifold.crossSection.transforms.rotate({ crossSection: square, degrees: 45 });
85
+ * ```
61
86
  */
62
87
  rotate(inputs: Inputs.Manifold.RotateCrossSectionDto<Manifold3D.CrossSection>): Manifold3D.CrossSection;
63
88
  /**
64
- * Transforms a cross section shape by using the 3x3 transformation matrix
65
- * @param inputs cross section and transformation matrix
66
- * @returns Transformed cross section shape
89
+ * Applies a 3x3 matrix to a cross-section, for any combination of move, turn, scale and shear
90
+ * in the plane.
91
+ * @param inputs - The cross-section and the 3x3 matrix
92
+ * @returns The transformed cross-section
67
93
  * @group matrix
68
94
  * @shortname transform
69
95
  * @drawable true
96
+ * @example
97
+ * ```typescript
98
+ * const moved = await bitbybit.manifold.crossSection.transforms.transform({ crossSection: square, transform: matrix });
99
+ * ```
70
100
  */
71
101
  transform(inputs: Inputs.Manifold.TransformCrossSectionDto<Manifold3D.CrossSection>): Manifold3D.CrossSection;
72
102
  /**
73
- * Move the vertices of this CrossSection (creating a new one) according to
74
- * any arbitrary input function, followed by a union operation (with a
75
- * Positive fill rule) that ensures any introduced intersections are not
76
- * included in the result.
77
- * @param inputs cross section and warp function
78
- * @returns Warped cross section shape
103
+ * Moves every point of a cross-section with a function of your own that changes the point in
104
+ * place, then fuses the result so any crossings the move introduced are cleaned up.
105
+ * @param inputs - The cross-section and the function that moves each point
106
+ * @returns The warped cross-section
79
107
  * @group transforms
80
108
  * @shortname warp
81
109
  * @drawable true
110
+ * @example
111
+ * ```typescript
112
+ * const wavy = await bitbybit.manifold.crossSection.transforms.warp({
113
+ * crossSection: square,
114
+ * warpFunc: (vert) => { vert[1] += Math.sin(vert[0]) * 0.5; },
115
+ * });
116
+ * ```
82
117
  */
83
118
  warp(inputs: Inputs.Manifold.CrossSectionWarpDto<Manifold3D.CrossSection>): Manifold3D.CrossSection;
84
119
  }
@@ -1,97 +1,132 @@
1
1
  /**
2
- * Contains various functions for transforming cross section from Manifold library
3
- * https://github.com/elalish/manifold Thanks Manifold community for developing this kernel
2
+ * Moving, turning, scaling, mirroring and warping Manifold cross-sections in the XY plane. Angles
3
+ * are in degrees and rotations turn about the origin; every method returns a new cross-section.
4
4
  */
5
5
  export class CrossSectionTransforms {
6
6
  constructor(_wasm) {
7
7
  }
8
8
  /**
9
- * Scales a cross section shape with 2D vector
10
- * @param inputs cross section and scale vector
11
- * @returns Scaled cross section shape
9
+ * Scales a cross-section by a separate factor along X and Y, about the origin.
10
+ * @param inputs - The cross-section and the two factors
11
+ * @returns The scaled cross-section
12
12
  * @group transforms
13
13
  * @shortname scale 2d
14
14
  * @drawable true
15
+ * @example
16
+ * ```typescript
17
+ * const stretched = await bitbybit.manifold.crossSection.transforms.scale2D({ crossSection: square, vector: [2, 1] });
18
+ * ```
15
19
  */
16
20
  scale2D(inputs) {
17
21
  return inputs.crossSection.scale(inputs.vector);
18
22
  }
19
23
  /**
20
- * Scales a cross section shape with single factor
21
- * @param inputs cross section and scale factor
22
- * @returns Scaled cross section shape
24
+ * Scales a cross-section uniformly about the origin by a factor.
25
+ * @param inputs - The cross-section and the factor
26
+ * @returns The scaled cross-section
23
27
  * @group transforms
24
28
  * @shortname scale uniform
25
29
  * @drawable true
30
+ * @example
31
+ * ```typescript
32
+ * const bigger = await bitbybit.manifold.crossSection.transforms.scale({ crossSection: square, factor: 2 });
33
+ * ```
26
34
  */
27
35
  scale(inputs) {
28
36
  return inputs.crossSection.scale(inputs.factor);
29
37
  }
30
38
  /**
31
- * Mirrors a cross section shape over a plane defined by a normal vector
32
- * @param inputs cross section and normal vector
33
- * @returns Mirrored cross section shape
39
+ * Mirrors a cross-section across the line through the origin that is perpendicular to the given
40
+ * normal.
41
+ * @param inputs - The cross-section and the normal of the mirror line
42
+ * @returns The mirrored cross-section
34
43
  * @group transforms
35
44
  * @shortname mirror
36
45
  * @drawable true
46
+ * @example
47
+ * ```typescript
48
+ * const other = await bitbybit.manifold.crossSection.transforms.mirror({ crossSection: outline, normal: [1, 0] });
49
+ * ```
37
50
  */
38
51
  mirror(inputs) {
39
52
  return inputs.crossSection.mirror(inputs.normal);
40
53
  }
41
54
  /**
42
- * Translates a cross section shape along the vector
43
- * @param inputs cross section and trnaslation vector
44
- * @returns Translated cross section shape
55
+ * Moves a cross-section by a 2D vector, in model units.
56
+ * @param inputs - The cross-section and the vector to move it by
57
+ * @returns The moved cross-section
45
58
  * @group transforms
46
59
  * @shortname translate
47
60
  * @drawable true
61
+ * @example
62
+ * ```typescript
63
+ * const moved = await bitbybit.manifold.crossSection.transforms.translate({ crossSection: square, vector: [10, 0] });
64
+ * ```
48
65
  */
49
66
  translate(inputs) {
50
67
  return inputs.crossSection.translate(inputs.vector);
51
68
  }
52
69
  /**
53
- * Translates a cross section shape along x, y
54
- * @param inputs cross section and trnaslation coordinates
55
- * @returns Translated cross section shape
70
+ * Moves a cross-section by separate distances along X and Y, in model units.
71
+ * @param inputs - The cross-section and the two distances
72
+ * @returns The moved cross-section
56
73
  * @group transforms
57
74
  * @shortname translate xy
58
75
  * @drawable true
76
+ * @example
77
+ * ```typescript
78
+ * const moved = await bitbybit.manifold.crossSection.transforms.translateXY({ crossSection: square, x: 10, y: 5 });
79
+ * ```
59
80
  */
60
81
  translateXY(inputs) {
61
82
  return inputs.crossSection.translate([inputs.x, inputs.y]);
62
83
  }
63
84
  /**
64
- * Rotates a cross section shape along the containing degrees
65
- * @param inputs cross section and rotation degrees
66
- * @returns Rotated cross section shape
85
+ * Rotates a cross-section about the origin by an angle in degrees, counterclockwise.
86
+ * @param inputs - The cross-section and the angle in degrees
87
+ * @returns The rotated cross-section
67
88
  * @group transforms
68
89
  * @shortname rotate
69
90
  * @drawable true
91
+ * @example
92
+ * ```typescript
93
+ * const turned = await bitbybit.manifold.crossSection.transforms.rotate({ crossSection: square, degrees: 45 });
94
+ * ```
70
95
  */
71
96
  rotate(inputs) {
72
97
  return inputs.crossSection.rotate(inputs.degrees);
73
98
  }
74
99
  /**
75
- * Transforms a cross section shape by using the 3x3 transformation matrix
76
- * @param inputs cross section and transformation matrix
77
- * @returns Transformed cross section shape
100
+ * Applies a 3x3 matrix to a cross-section, for any combination of move, turn, scale and shear
101
+ * in the plane.
102
+ * @param inputs - The cross-section and the 3x3 matrix
103
+ * @returns The transformed cross-section
78
104
  * @group matrix
79
105
  * @shortname transform
80
106
  * @drawable true
107
+ * @example
108
+ * ```typescript
109
+ * const moved = await bitbybit.manifold.crossSection.transforms.transform({ crossSection: square, transform: matrix });
110
+ * ```
81
111
  */
82
112
  transform(inputs) {
83
113
  return inputs.crossSection.transform(inputs.transform);
84
114
  }
85
115
  /**
86
- * Move the vertices of this CrossSection (creating a new one) according to
87
- * any arbitrary input function, followed by a union operation (with a
88
- * Positive fill rule) that ensures any introduced intersections are not
89
- * included in the result.
90
- * @param inputs cross section and warp function
91
- * @returns Warped cross section shape
116
+ * Moves every point of a cross-section with a function of your own that changes the point in
117
+ * place, then fuses the result so any crossings the move introduced are cleaned up.
118
+ * @param inputs - The cross-section and the function that moves each point
119
+ * @returns The warped cross-section
92
120
  * @group transforms
93
121
  * @shortname warp
94
122
  * @drawable true
123
+ * @example
124
+ * ```typescript
125
+ * const wavy = await bitbybit.manifold.crossSection.transforms.warp({
126
+ * crossSection: square,
127
+ * warpFunc: (vert) => { vert[1] += Math.sin(vert[0]) * 0.5; },
128
+ * });
129
+ * ```
95
130
  */
96
131
  warp(inputs) {
97
132
  return inputs.crossSection.warp(inputs.warpFunc);
@@ -7,8 +7,12 @@ import { CrossSectionBooleans } from "./cross-section-booleans";
7
7
  import { CrossSectionEvaluate } from "./cross-section-evaluate";
8
8
  import { BaseBitByBit } from "../../../base";
9
9
  /**
10
- * Contains various functions for Solid meshes from Manifold library https://github.com/elalish/manifold
11
- * Thanks Manifold community for developing this kernel
10
+ * Flat outlines in the Manifold kernel, the 2D shapes that `operations.extrude` and
11
+ * `operations.revolve` turn into solids and that `slice` and `project` cut out of them. A
12
+ * cross-section is one or more closed polygons in the XY plane, holes included; `shapes` builds
13
+ * them, `booleans` combines them, `operations` offsets, hulls and extrudes them, `transforms` moves
14
+ * them and `evaluate` measures them. The methods here convert between cross-sections and plain
15
+ * point lists, and free the memory a cross-section holds.
12
16
  */
13
17
  export declare class CrossSection {
14
18
  shapes: CrossSectionShapes;
@@ -20,59 +24,116 @@ export declare class CrossSection {
20
24
  private base;
21
25
  constructor(wasm: Manifold3D.ManifoldToplevel, base: BaseBitByBit);
22
26
  /**
23
- * Creates a cross section from a single polygon points
24
- * @param inputs polygon points
25
- * @returns cross section
27
+ * Builds a cross-section from one polygon given as points; only the X and Y of each point are
28
+ * used.
29
+ *
30
+ * `fillRule` decides which regions of a self-crossing polygon count as inside;
31
+ * `removeDuplicates` drops consecutive repeated points within `tolerance` first.
32
+ * @param inputs - The polygon points, the fill rule and the duplicate handling
33
+ * @returns The cross-section
26
34
  * @group create
27
35
  * @shortname cross section from points
28
36
  * @drawable true
37
+ * @example
38
+ * ```typescript
39
+ * const outline = await bitbybit.manifold.crossSection.crossSectionFromPoints({
40
+ * points: [[0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]],
41
+ * fillRule: Bit.Inputs.Manifold.fillRuleEnum.positive,
42
+ * removeDuplicates: false,
43
+ * tolerance: 1e-7,
44
+ * });
45
+ * ```
29
46
  */
30
47
  crossSectionFromPoints(inputs: Inputs.Manifold.CrossSectionFromPolygonPointsDto): Manifold3D.CrossSection;
31
48
  /**
32
- * Creates a cross section from multiple polygons points
33
- * @param inputs polygons points
34
- * @returns cross section
49
+ * Builds a cross-section from several polygons given as points, for instance an outline and its
50
+ * holes; only the X and Y of each point are used.
51
+ *
52
+ * `fillRule` decides which regions count as inside where polygons overlap; `removeDuplicates`
53
+ * drops consecutive repeated points within `tolerance` first.
54
+ * @param inputs - The polygons as point lists, the fill rule and the duplicate handling
55
+ * @returns The cross-section
35
56
  * @group create
36
57
  * @shortname cross section from polygons
37
58
  * @drawable true
59
+ * @example
60
+ * ```typescript
61
+ * const plate = await bitbybit.manifold.crossSection.crossSectionFromPolygons({
62
+ * polygonPoints: [outerPoints, holePoints],
63
+ * fillRule: Bit.Inputs.Manifold.fillRuleEnum.evenOdd,
64
+ * removeDuplicates: false,
65
+ * tolerance: 1e-7,
66
+ * });
67
+ * ```
38
68
  */
39
69
  crossSectionFromPolygons(inputs: Inputs.Manifold.CrossSectionFromPolygonsPointsDto): Manifold3D.CrossSection;
40
70
  /**
41
- * Turns cross section into polygons
42
- * @param inputs cross section
43
- * @returns polygons
71
+ * Reads a cross-section back as its polygons, each a list of 2D points.
72
+ * @param inputs - The cross-section
73
+ * @returns One list of 2D points per polygon
44
74
  * @group decompose
45
75
  * @shortname cross section to polygons
46
76
  * @drawable false
77
+ * @example
78
+ * ```typescript
79
+ * const polygons = await bitbybit.manifold.crossSection.crossSectionToPolygons({ crossSection: outline });
80
+ * ```
47
81
  */
48
82
  crossSectionToPolygons(inputs: Inputs.Manifold.CrossSectionDto<Manifold3D.CrossSection>): Manifold3D.SimplePolygon[];
49
83
  /**
50
- * Extracts points from a cross section
51
- * @param inputs cross section
52
- * @returns points
84
+ * Reads a cross-section back as its polygons with 3D points, Z set to 0, ready for drawing as
85
+ * polylines.
86
+ * @param inputs - The cross-section
87
+ * @returns One list of points per polygon
53
88
  * @group decompose
54
89
  * @shortname cross section to points
55
90
  * @drawable false
91
+ * @example
92
+ * ```typescript
93
+ * const polylines = await bitbybit.manifold.crossSection.crossSectionToPoints({ crossSection: outline });
94
+ * ```
56
95
  */
57
96
  crossSectionToPoints(inputs: Inputs.Manifold.CrossSectionDto<Manifold3D.CrossSection>): Inputs.Base.Point3[][];
58
97
  /**
59
- * Turns cross sections into polygons
60
- * @param inputs cross sections
61
- * @returns polygons
98
+ * Reads several cross-sections back as their polygons, as `crossSectionToPolygons` does for
99
+ * one.
100
+ * @param inputs - The cross-sections
101
+ * @returns One polygon list per cross-section, in the same order
62
102
  * @group decompose
63
103
  * @shortname cross sections to polygons
64
104
  * @drawable false
105
+ * @example
106
+ * ```typescript
107
+ * const polygons = await bitbybit.manifold.crossSection.crossSectionsToPolygons({ crossSections: [outline, hole] });
108
+ * ```
65
109
  */
66
110
  crossSectionsToPolygons(inputs: Inputs.Manifold.CrossSectionsDto<Manifold3D.CrossSection>): Manifold3D.SimplePolygon[][];
67
111
  /**
68
- * Extracts points from cross sections
69
- * @param inputs cross sections
70
- * @returns points
112
+ * Reads several cross-sections back as polygons with 3D points, as `crossSectionToPoints` does
113
+ * for one.
114
+ * @param inputs - The cross-sections
115
+ * @returns One list of point polygons per cross-section, in the same order
71
116
  * @group decompose
72
117
  * @shortname cross sections to points
73
118
  * @drawable false
119
+ * @example
120
+ * ```typescript
121
+ * const polylines = await bitbybit.manifold.crossSection.crossSectionsToPoints({ crossSections: [outline, hole] });
122
+ * ```
74
123
  */
75
124
  crossSectionsToPoints(inputs: Inputs.Manifold.CrossSectionsDto<Manifold3D.CrossSection>): number[][][][];
125
+ /**
126
+ * Frees the memory a cross-section holds inside the kernel; the cross-section cannot be used
127
+ * afterwards. The asynchronous API frees cross-sections through `deleteManifoldOrCrossSection`
128
+ * on the service instead.
129
+ * @param inputs - The cross-section to free
130
+ */
76
131
  deleteCrossSection(inputs: Inputs.Manifold.CrossSectionDto<Manifold3D.CrossSection>): void;
132
+ /**
133
+ * Frees the memory several cross-sections hold inside the kernel; they cannot be used
134
+ * afterwards. The asynchronous API frees cross-sections through
135
+ * `deleteManifoldsOrCrossSections` on the service instead.
136
+ * @param inputs - The cross-sections to free
137
+ */
77
138
  deleteCrossSections(inputs: Inputs.Manifold.CrossSectionsDto<Manifold3D.CrossSection>): void;
78
139
  }
@@ -4,8 +4,12 @@ import { CrossSectionTransforms } from "./cross-section-transforms";
4
4
  import { CrossSectionBooleans } from "./cross-section-booleans";
5
5
  import { CrossSectionEvaluate } from "./cross-section-evaluate";
6
6
  /**
7
- * Contains various functions for Solid meshes from Manifold library https://github.com/elalish/manifold
8
- * Thanks Manifold community for developing this kernel
7
+ * Flat outlines in the Manifold kernel, the 2D shapes that `operations.extrude` and
8
+ * `operations.revolve` turn into solids and that `slice` and `project` cut out of them. A
9
+ * cross-section is one or more closed polygons in the XY plane, holes included; `shapes` builds
10
+ * them, `booleans` combines them, `operations` offsets, hulls and extrudes them, `transforms` moves
11
+ * them and `evaluate` measures them. The methods here convert between cross-sections and plain
12
+ * point lists, and free the memory a cross-section holds.
9
13
  */
10
14
  export class CrossSection {
11
15
  constructor(wasm, base) {
@@ -18,12 +22,25 @@ export class CrossSection {
18
22
  this.evaluate = new CrossSectionEvaluate(wasm);
19
23
  }
20
24
  /**
21
- * Creates a cross section from a single polygon points
22
- * @param inputs polygon points
23
- * @returns cross section
25
+ * Builds a cross-section from one polygon given as points; only the X and Y of each point are
26
+ * used.
27
+ *
28
+ * `fillRule` decides which regions of a self-crossing polygon count as inside;
29
+ * `removeDuplicates` drops consecutive repeated points within `tolerance` first.
30
+ * @param inputs - The polygon points, the fill rule and the duplicate handling
31
+ * @returns The cross-section
24
32
  * @group create
25
33
  * @shortname cross section from points
26
34
  * @drawable true
35
+ * @example
36
+ * ```typescript
37
+ * const outline = await bitbybit.manifold.crossSection.crossSectionFromPoints({
38
+ * points: [[0, 0, 0], [10, 0, 0], [10, 10, 0], [0, 10, 0]],
39
+ * fillRule: Bit.Inputs.Manifold.fillRuleEnum.positive,
40
+ * removeDuplicates: false,
41
+ * tolerance: 1e-7,
42
+ * });
43
+ * ```
27
44
  */
28
45
  crossSectionFromPoints(inputs) {
29
46
  let points = inputs.points;
@@ -38,12 +55,25 @@ export class CrossSection {
38
55
  return this.manifold.CrossSection.ofPolygons([polygon], inputs.fillRule);
39
56
  }
40
57
  /**
41
- * Creates a cross section from multiple polygons points
42
- * @param inputs polygons points
43
- * @returns cross section
58
+ * Builds a cross-section from several polygons given as points, for instance an outline and its
59
+ * holes; only the X and Y of each point are used.
60
+ *
61
+ * `fillRule` decides which regions count as inside where polygons overlap; `removeDuplicates`
62
+ * drops consecutive repeated points within `tolerance` first.
63
+ * @param inputs - The polygons as point lists, the fill rule and the duplicate handling
64
+ * @returns The cross-section
44
65
  * @group create
45
66
  * @shortname cross section from polygons
46
67
  * @drawable true
68
+ * @example
69
+ * ```typescript
70
+ * const plate = await bitbybit.manifold.crossSection.crossSectionFromPolygons({
71
+ * polygonPoints: [outerPoints, holePoints],
72
+ * fillRule: Bit.Inputs.Manifold.fillRuleEnum.evenOdd,
73
+ * removeDuplicates: false,
74
+ * tolerance: 1e-7,
75
+ * });
76
+ * ```
47
77
  */
48
78
  crossSectionFromPolygons(inputs) {
49
79
  let polygonPoints = inputs.polygonPoints;
@@ -58,35 +88,49 @@ export class CrossSection {
58
88
  return this.manifold.CrossSection.ofPolygons(polygons, inputs.fillRule);
59
89
  }
60
90
  /**
61
- * Turns cross section into polygons
62
- * @param inputs cross section
63
- * @returns polygons
91
+ * Reads a cross-section back as its polygons, each a list of 2D points.
92
+ * @param inputs - The cross-section
93
+ * @returns One list of 2D points per polygon
64
94
  * @group decompose
65
95
  * @shortname cross section to polygons
66
96
  * @drawable false
97
+ * @example
98
+ * ```typescript
99
+ * const polygons = await bitbybit.manifold.crossSection.crossSectionToPolygons({ crossSection: outline });
100
+ * ```
67
101
  */
68
102
  crossSectionToPolygons(inputs) {
69
103
  return inputs.crossSection.toPolygons();
70
104
  }
71
105
  /**
72
- * Extracts points from a cross section
73
- * @param inputs cross section
74
- * @returns points
106
+ * Reads a cross-section back as its polygons with 3D points, Z set to 0, ready for drawing as
107
+ * polylines.
108
+ * @param inputs - The cross-section
109
+ * @returns One list of points per polygon
75
110
  * @group decompose
76
111
  * @shortname cross section to points
77
112
  * @drawable false
113
+ * @example
114
+ * ```typescript
115
+ * const polylines = await bitbybit.manifold.crossSection.crossSectionToPoints({ crossSection: outline });
116
+ * ```
78
117
  */
79
118
  crossSectionToPoints(inputs) {
80
119
  const polygons = inputs.crossSection.toPolygons();
81
120
  return polygons.map(polygon => polygon.map(point => [point[0], point[1], 0]));
82
121
  }
83
122
  /**
84
- * Turns cross sections into polygons
85
- * @param inputs cross sections
86
- * @returns polygons
123
+ * Reads several cross-sections back as their polygons, as `crossSectionToPolygons` does for
124
+ * one.
125
+ * @param inputs - The cross-sections
126
+ * @returns One polygon list per cross-section, in the same order
87
127
  * @group decompose
88
128
  * @shortname cross sections to polygons
89
129
  * @drawable false
130
+ * @example
131
+ * ```typescript
132
+ * const polygons = await bitbybit.manifold.crossSection.crossSectionsToPolygons({ crossSections: [outline, hole] });
133
+ * ```
90
134
  */
91
135
  crossSectionsToPolygons(inputs) {
92
136
  return inputs.crossSections.map((crossSection) => {
@@ -96,12 +140,17 @@ export class CrossSection {
96
140
  });
97
141
  }
98
142
  /**
99
- * Extracts points from cross sections
100
- * @param inputs cross sections
101
- * @returns points
143
+ * Reads several cross-sections back as polygons with 3D points, as `crossSectionToPoints` does
144
+ * for one.
145
+ * @param inputs - The cross-sections
146
+ * @returns One list of point polygons per cross-section, in the same order
102
147
  * @group decompose
103
148
  * @shortname cross sections to points
104
149
  * @drawable false
150
+ * @example
151
+ * ```typescript
152
+ * const polylines = await bitbybit.manifold.crossSection.crossSectionsToPoints({ crossSections: [outline, hole] });
153
+ * ```
105
154
  */
106
155
  crossSectionsToPoints(inputs) {
107
156
  return inputs.crossSections.map((crossSection) => {
@@ -110,9 +159,21 @@ export class CrossSection {
110
159
  });
111
160
  });
112
161
  }
162
+ /**
163
+ * Frees the memory a cross-section holds inside the kernel; the cross-section cannot be used
164
+ * afterwards. The asynchronous API frees cross-sections through `deleteManifoldOrCrossSection`
165
+ * on the service instead.
166
+ * @param inputs - The cross-section to free
167
+ */
113
168
  deleteCrossSection(inputs) {
114
169
  inputs.crossSection.delete();
115
170
  }
171
+ /**
172
+ * Frees the memory several cross-sections hold inside the kernel; they cannot be used
173
+ * afterwards. The asynchronous API frees cross-sections through
174
+ * `deleteManifoldsOrCrossSections` on the service instead.
175
+ * @param inputs - The cross-sections to free
176
+ */
116
177
  deleteCrossSections(inputs) {
117
178
  inputs.crossSections.forEach((crossSection) => {
118
179
  return this.deleteCrossSection({