@bitbybit-dev/manifold 1.2.0 → 1.3.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.
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,61 +1,82 @@
1
1
  /**
2
- * Contains various functions for Solid meshes from Manifold library https://github.com/elalish/manifold
3
- * Thanks Manifold community for developing this kernel
2
+ * Measuring Manifold cross-sections: area, emptiness, vertex and contour counts and the bounding
3
+ * rectangle. Nothing here changes the cross-section.
4
4
  */
5
5
  export class CrossSectionEvaluate {
6
6
  constructor(_wasm) {
7
7
  }
8
8
  /**
9
- * Get area of cross section
10
- * @param inputs cross section
11
- * @returns area of cross section
9
+ * Measures the area of a cross-section, in square model units, holes excluded.
10
+ * @param inputs - The cross-section
11
+ * @returns The area
12
12
  * @group basic
13
13
  * @shortname area
14
14
  * @drawable false
15
+ * @example
16
+ * ```typescript
17
+ * const area = await bitbybit.manifold.crossSection.evaluate.area({ crossSection: outline });
18
+ * ```
15
19
  */
16
20
  area(inputs) {
17
21
  return inputs.crossSection.area();
18
22
  }
19
23
  /**
20
- * Check if cross section is empty
21
- * @param inputs cross section
22
- * @returns boolean indicating emptyness
24
+ * Tells whether a cross-section has no contours at all.
25
+ * @param inputs - The cross-section
26
+ * @returns True when the cross-section is empty
23
27
  * @group basic
24
28
  * @shortname is empty
25
29
  * @drawable false
30
+ * @example
31
+ * ```typescript
32
+ * const empty = await bitbybit.manifold.crossSection.evaluate.isEmpty({ crossSection: outline });
33
+ * ```
26
34
  */
27
35
  isEmpty(inputs) {
28
36
  return inputs.crossSection.isEmpty();
29
37
  }
30
38
  /**
31
- * Get number of vertices in cross section
32
- * @param inputs cross section
33
- * @returns number of vertices of cross section
39
+ * Counts the vertices of a cross-section over all its contours.
40
+ * @param inputs - The cross-section
41
+ * @returns The number of vertices
34
42
  * @group basic
35
43
  * @shortname num vert
36
44
  * @drawable false
45
+ * @example
46
+ * ```typescript
47
+ * const vertices = await bitbybit.manifold.crossSection.evaluate.numVert({ crossSection: outline });
48
+ * ```
37
49
  */
38
50
  numVert(inputs) {
39
51
  return inputs.crossSection.numVert();
40
52
  }
41
53
  /**
42
- * Get number of contours in cross section
43
- * @param inputs cross section
44
- * @returns number of contour of cross section
54
+ * Counts the contours of a cross-section: its outer outlines and its holes.
55
+ * @param inputs - The cross-section
56
+ * @returns The number of contours
45
57
  * @group basic
46
58
  * @shortname num contour
47
59
  * @drawable false
60
+ * @example
61
+ * ```typescript
62
+ * const contours = await bitbybit.manifold.crossSection.evaluate.numContour({ crossSection: plate });
63
+ * ```
48
64
  */
49
65
  numContour(inputs) {
50
66
  return inputs.crossSection.numContour();
51
67
  }
52
68
  /**
53
- * Get the bounds of the contour as a rectangle. Output is given in two vec2 points in the array. First array is the min point and second array is the max point.
54
- * @param inputs cross section
55
- * @returns bounds of cross section
69
+ * Finds the rectangle around a cross-section as two 2D points: the minimum corner, then the
70
+ * maximum corner.
71
+ * @param inputs - The cross-section
72
+ * @returns The minimum corner and the maximum corner
56
73
  * @group basic
57
74
  * @shortname bounds
58
75
  * @drawable false
76
+ * @example
77
+ * ```typescript
78
+ * const [min, max] = await bitbybit.manifold.crossSection.evaluate.bounds({ crossSection: outline });
79
+ * ```
59
80
  */
60
81
  bounds(inputs) {
61
82
  const bounds = inputs.crossSection.bounds();
@@ -1,84 +1,124 @@
1
1
  import * as Inputs from "../../inputs/manifold-inputs";
2
2
  import * as Manifold3D from "manifold-3d";
3
3
  /**
4
- * Contains various functions for Solid meshes from Manifold library https://github.com/elalish/manifold
5
- * Thanks Manifold community for developing this kernel
4
+ * Working with Manifold cross-sections beyond booleans: turning them into solids by extruding along
5
+ * Z or revolving, offsetting their outlines, wrapping them in a convex hull, simplifying them, and
6
+ * composing and decomposing them. Every method returns a new shape.
6
7
  */
7
8
  export declare class CrossSectionOperations {
8
9
  private manifold;
9
10
  constructor(wasm: Manifold3D.ManifoldToplevel);
10
11
  /**
11
- * Compute convex hull for the cross section
12
- * @param inputs cross section
13
- * @returns hulled cross section
12
+ * Wraps a cross-section in its convex hull, the smallest outline without dents that contains
13
+ * it, like a rubber band stretched around it.
14
+ * @param inputs - The cross-section
15
+ * @returns The convex hull
14
16
  * @group basic
15
17
  * @shortname hull
16
18
  * @drawable true
19
+ * @example
20
+ * ```typescript
21
+ * const wrapped = await bitbybit.manifold.crossSection.operations.hull({ crossSection: outline });
22
+ * ```
17
23
  */
18
24
  hull(inputs: Inputs.Manifold.CrossSectionDto<Manifold3D.CrossSection>): Manifold3D.CrossSection;
19
25
  /**
20
- * Extrude the cross section to create a 3D shape
21
- * @param inputs cross section and extrusion parameters
22
- * @returns extruded manifold shape
26
+ * Sweeps a cross-section along Z into a solid of the given height.
27
+ *
28
+ * `twistDegrees` turns the top against the bottom, `scaleTopX` and `scaleTopY` shrink or grow
29
+ * it, and `nDivisions` adds sections in between so twists and tapers stay smooth; 0 for both
30
+ * top scales makes a cone. `center` centers the solid on the XY plane instead of standing it on
31
+ * it.
32
+ * @param inputs - The cross-section, the height, the divisions, the twist in degrees, the top scale and whether to center it
33
+ * @returns The extruded solid
23
34
  * @group basic
24
35
  * @shortname extrude
25
36
  * @drawable true
37
+ * @example
38
+ * ```typescript
39
+ * const twisted = await bitbybit.manifold.crossSection.operations.extrude({ crossSection: square, height: 20, nDivisions: 20, twistDegrees: 90, scaleTopX: 0.5, scaleTopY: 0.5, center: false });
40
+ * ```
26
41
  */
27
42
  extrude(inputs: Inputs.Manifold.ExtrudeDto<Manifold3D.CrossSection>): Manifold3D.Manifold;
28
43
  /**
29
- * Revolve the cross section to create a 3D shape
30
- * @param inputs cross section and extrusion parameters
31
- * @returns extruded manifold shape
44
+ * Spins a cross-section around the Y axis into a solid, like a lathe; only the part of the
45
+ * outline on the positive X side is used.
46
+ *
47
+ * `revolveDegrees` below 360 gives a partial turn and `circularSegments` sets how round the
48
+ * result is. The kernel stands the result along Z; `matchProfile`, true by default, turns it
49
+ * back to match the profile.
50
+ * @param inputs - The cross-section, the angle in degrees, the number of segments and whether to match the profile
51
+ * @returns The revolved solid
32
52
  * @group basic
33
53
  * @shortname revolve
34
54
  * @drawable true
55
+ * @example
56
+ * ```typescript
57
+ * const vase = await bitbybit.manifold.crossSection.operations.revolve({ crossSection: profile, revolveDegrees: 360, circularSegments: 64, matchProfile: true });
58
+ * ```
35
59
  */
36
60
  revolve(inputs: Inputs.Manifold.RevolveDto<Manifold3D.CrossSection>): Manifold3D.Manifold;
37
61
  /**
38
- * Offsets the cross section to create a new cross section with a given delta (uses Clipper2 algorithm behind).
39
- * @param inputs cross section and offset parameters
40
- * @returns offset cross section
62
+ * Moves the outline of a cross-section outward by `delta`, or inward for a negative delta, so
63
+ * an outer contour grows and a hole shrinks.
64
+ *
65
+ * `joinType` says how corners are treated: rounded, squared off, mitered or beveled;
66
+ * `miterLimit` caps how far a miter may reach and `circularSegments` how round a rounded corner
67
+ * is. `simplify` afterwards cleans up tiny segments.
68
+ * @param inputs - The cross-section, the distance, the corner treatment and its settings
69
+ * @returns The offset cross-section
41
70
  * @group basic
42
71
  * @shortname offset
43
72
  * @drawable true
73
+ * @example
74
+ * ```typescript
75
+ * const bigger = await bitbybit.manifold.crossSection.operations.offset({ crossSection: outline, delta: 1, joinType: Bit.Inputs.Manifold.manifoldJoinTypeEnum.round, miterLimit: 2, circularSegments: 32 });
76
+ * ```
44
77
  */
45
78
  offset(inputs: Inputs.Manifold.OffsetDto<Manifold3D.CrossSection>): Manifold3D.CrossSection;
46
79
  /**
47
- * Remove vertices from the contours in this CrossSection that are less than
48
- * the specified distance epsilon from an imaginary line that passes through
49
- * its two adjacent vertices. Near duplicate vertices and collinear points
50
- * will be removed at lower epsilons, with elimination of line segments
51
- * becoming increasingly aggressive with larger epsilons.
80
+ * Removes points of a cross-section that lie within `epsilon` of the line between their
81
+ * neighbors, dropping near-duplicates and collinear points.
52
82
  *
53
- * It is recommended to apply this function following Offset, in order to
54
- * clean up any spurious tiny line segments introduced that do not improve
55
- * quality in any meaningful way. This is particularly important if further
56
- * offseting operations are to be performed, which would compound the issue.
57
- * @param inputs cross section and epsilon parameters
58
- * @returns simplified cross section
83
+ * A larger epsilon removes more; run it after `offset` to clean up the tiny segments offsetting
84
+ * leaves behind.
85
+ * @param inputs - The cross-section and the distance below which a point is dropped
86
+ * @returns The simplified cross-section
59
87
  * @group basic
60
88
  * @shortname simplify
61
89
  * @drawable true
90
+ * @example
91
+ * ```typescript
92
+ * const cleaner = await bitbybit.manifold.crossSection.operations.simplify({ crossSection: offsetOutline, epsilon: 1e-4 });
93
+ * ```
62
94
  */
63
95
  simplify(inputs: Inputs.Manifold.SimplifyDto<Manifold3D.CrossSection>): Manifold3D.CrossSection;
64
96
  /**
65
- * Composes multiple cross sections or polygons into a single cross section
66
- * @param inputs cross sections or polygons
67
- * @returns composed cross section
97
+ * Packs several cross-sections or polygons into one cross-section without fusing them, the
98
+ * inverse of `decompose`.
99
+ * @param inputs - The cross-sections or polygons to pack together
100
+ * @returns One cross-section holding all of them
68
101
  * @group composition
69
102
  * @shortname compose
70
103
  * @drawable true
104
+ * @example
105
+ * ```typescript
106
+ * const packed = await bitbybit.manifold.crossSection.operations.compose({ polygons: [square, disc] });
107
+ * ```
71
108
  */
72
109
  compose(inputs: Inputs.Manifold.ComposeDto<(Manifold3D.CrossSection | Manifold3D.Polygons)[]>): Manifold3D.CrossSection;
73
110
  /**
74
- * Decompose cross sections that are topologically
75
- * disconnected, each containing one outline contour with zero or more
76
- * holes.
77
- * @param inputs cross section
78
- * @returns decomposed cross sections
111
+ * Splits a cross-section into its separate, unconnected outlines, each with its own holes, the
112
+ * inverse of `compose`.
113
+ * @param inputs - The cross-section
114
+ * @returns The separate outlines
79
115
  * @group composition
80
116
  * @shortname decompose
81
117
  * @drawable true
118
+ * @example
119
+ * ```typescript
120
+ * const pieces = await bitbybit.manifold.crossSection.operations.decompose({ crossSection: packed });
121
+ * ```
82
122
  */
83
123
  decompose(inputs: Inputs.Manifold.CrossSectionDto<Manifold3D.CrossSection>): Manifold3D.CrossSection[];
84
124
  }
@@ -1,40 +1,64 @@
1
1
  /**
2
- * Contains various functions for Solid meshes from Manifold library https://github.com/elalish/manifold
3
- * Thanks Manifold community for developing this kernel
2
+ * Working with Manifold cross-sections beyond booleans: turning them into solids by extruding along
3
+ * Z or revolving, offsetting their outlines, wrapping them in a convex hull, simplifying them, and
4
+ * composing and decomposing them. Every method returns a new shape.
4
5
  */
5
6
  export class CrossSectionOperations {
6
7
  constructor(wasm) {
7
8
  this.manifold = wasm;
8
9
  }
9
10
  /**
10
- * Compute convex hull for the cross section
11
- * @param inputs cross section
12
- * @returns hulled cross section
11
+ * Wraps a cross-section in its convex hull, the smallest outline without dents that contains
12
+ * it, like a rubber band stretched around it.
13
+ * @param inputs - The cross-section
14
+ * @returns The convex hull
13
15
  * @group basic
14
16
  * @shortname hull
15
17
  * @drawable true
18
+ * @example
19
+ * ```typescript
20
+ * const wrapped = await bitbybit.manifold.crossSection.operations.hull({ crossSection: outline });
21
+ * ```
16
22
  */
17
23
  hull(inputs) {
18
24
  return inputs.crossSection.hull();
19
25
  }
20
26
  /**
21
- * Extrude the cross section to create a 3D shape
22
- * @param inputs cross section and extrusion parameters
23
- * @returns extruded manifold shape
27
+ * Sweeps a cross-section along Z into a solid of the given height.
28
+ *
29
+ * `twistDegrees` turns the top against the bottom, `scaleTopX` and `scaleTopY` shrink or grow
30
+ * it, and `nDivisions` adds sections in between so twists and tapers stay smooth; 0 for both
31
+ * top scales makes a cone. `center` centers the solid on the XY plane instead of standing it on
32
+ * it.
33
+ * @param inputs - The cross-section, the height, the divisions, the twist in degrees, the top scale and whether to center it
34
+ * @returns The extruded solid
24
35
  * @group basic
25
36
  * @shortname extrude
26
37
  * @drawable true
38
+ * @example
39
+ * ```typescript
40
+ * const twisted = await bitbybit.manifold.crossSection.operations.extrude({ crossSection: square, height: 20, nDivisions: 20, twistDegrees: 90, scaleTopX: 0.5, scaleTopY: 0.5, center: false });
41
+ * ```
27
42
  */
28
43
  extrude(inputs) {
29
44
  return inputs.crossSection.extrude(inputs.height, inputs.nDivisions, inputs.twistDegrees, [inputs.scaleTopX, inputs.scaleTopY], inputs.center);
30
45
  }
31
46
  /**
32
- * Revolve the cross section to create a 3D shape
33
- * @param inputs cross section and extrusion parameters
34
- * @returns extruded manifold shape
47
+ * Spins a cross-section around the Y axis into a solid, like a lathe; only the part of the
48
+ * outline on the positive X side is used.
49
+ *
50
+ * `revolveDegrees` below 360 gives a partial turn and `circularSegments` sets how round the
51
+ * result is. The kernel stands the result along Z; `matchProfile`, true by default, turns it
52
+ * back to match the profile.
53
+ * @param inputs - The cross-section, the angle in degrees, the number of segments and whether to match the profile
54
+ * @returns The revolved solid
35
55
  * @group basic
36
56
  * @shortname revolve
37
57
  * @drawable true
58
+ * @example
59
+ * ```typescript
60
+ * const vase = await bitbybit.manifold.crossSection.operations.revolve({ crossSection: profile, revolveDegrees: 360, circularSegments: 64, matchProfile: true });
61
+ * ```
38
62
  */
39
63
  revolve(inputs) {
40
64
  const res = inputs.crossSection.revolve(inputs.circularSegments, inputs.revolveDegrees);
@@ -46,43 +70,56 @@ export class CrossSectionOperations {
46
70
  }
47
71
  }
48
72
  /**
49
- * Offsets the cross section to create a new cross section with a given delta (uses Clipper2 algorithm behind).
50
- * @param inputs cross section and offset parameters
51
- * @returns offset cross section
73
+ * Moves the outline of a cross-section outward by `delta`, or inward for a negative delta, so
74
+ * an outer contour grows and a hole shrinks.
75
+ *
76
+ * `joinType` says how corners are treated: rounded, squared off, mitered or beveled;
77
+ * `miterLimit` caps how far a miter may reach and `circularSegments` how round a rounded corner
78
+ * is. `simplify` afterwards cleans up tiny segments.
79
+ * @param inputs - The cross-section, the distance, the corner treatment and its settings
80
+ * @returns The offset cross-section
52
81
  * @group basic
53
82
  * @shortname offset
54
83
  * @drawable true
84
+ * @example
85
+ * ```typescript
86
+ * const bigger = await bitbybit.manifold.crossSection.operations.offset({ crossSection: outline, delta: 1, joinType: Bit.Inputs.Manifold.manifoldJoinTypeEnum.round, miterLimit: 2, circularSegments: 32 });
87
+ * ```
55
88
  */
56
89
  offset(inputs) {
57
90
  return inputs.crossSection.offset(inputs.delta, inputs.joinType, inputs.miterLimit, inputs.circularSegments);
58
91
  }
59
92
  /**
60
- * Remove vertices from the contours in this CrossSection that are less than
61
- * the specified distance epsilon from an imaginary line that passes through
62
- * its two adjacent vertices. Near duplicate vertices and collinear points
63
- * will be removed at lower epsilons, with elimination of line segments
64
- * becoming increasingly aggressive with larger epsilons.
93
+ * Removes points of a cross-section that lie within `epsilon` of the line between their
94
+ * neighbors, dropping near-duplicates and collinear points.
65
95
  *
66
- * It is recommended to apply this function following Offset, in order to
67
- * clean up any spurious tiny line segments introduced that do not improve
68
- * quality in any meaningful way. This is particularly important if further
69
- * offseting operations are to be performed, which would compound the issue.
70
- * @param inputs cross section and epsilon parameters
71
- * @returns simplified cross section
96
+ * A larger epsilon removes more; run it after `offset` to clean up the tiny segments offsetting
97
+ * leaves behind.
98
+ * @param inputs - The cross-section and the distance below which a point is dropped
99
+ * @returns The simplified cross-section
72
100
  * @group basic
73
101
  * @shortname simplify
74
102
  * @drawable true
103
+ * @example
104
+ * ```typescript
105
+ * const cleaner = await bitbybit.manifold.crossSection.operations.simplify({ crossSection: offsetOutline, epsilon: 1e-4 });
106
+ * ```
75
107
  */
76
108
  simplify(inputs) {
77
109
  return inputs.crossSection.simplify(inputs.epsilon);
78
110
  }
79
111
  /**
80
- * Composes multiple cross sections or polygons into a single cross section
81
- * @param inputs cross sections or polygons
82
- * @returns composed cross section
112
+ * Packs several cross-sections or polygons into one cross-section without fusing them, the
113
+ * inverse of `decompose`.
114
+ * @param inputs - The cross-sections or polygons to pack together
115
+ * @returns One cross-section holding all of them
83
116
  * @group composition
84
117
  * @shortname compose
85
118
  * @drawable true
119
+ * @example
120
+ * ```typescript
121
+ * const packed = await bitbybit.manifold.crossSection.operations.compose({ polygons: [square, disc] });
122
+ * ```
86
123
  */
87
124
  compose(inputs) {
88
125
  const { CrossSection } = this.manifold;
@@ -90,14 +127,17 @@ export class CrossSectionOperations {
90
127
  return compose(inputs.polygons);
91
128
  }
92
129
  /**
93
- * Decompose cross sections that are topologically
94
- * disconnected, each containing one outline contour with zero or more
95
- * holes.
96
- * @param inputs cross section
97
- * @returns decomposed cross sections
130
+ * Splits a cross-section into its separate, unconnected outlines, each with its own holes, the
131
+ * inverse of `compose`.
132
+ * @param inputs - The cross-section
133
+ * @returns The separate outlines
98
134
  * @group composition
99
135
  * @shortname decompose
100
136
  * @drawable true
137
+ * @example
138
+ * ```typescript
139
+ * const pieces = await bitbybit.manifold.crossSection.operations.decompose({ crossSection: packed });
140
+ * ```
101
141
  */
102
142
  decompose(inputs) {
103
143
  return inputs.crossSection.decompose();
@@ -1,49 +1,70 @@
1
1
  import * as Inputs from "../../inputs/manifold-inputs";
2
2
  import * as Manifold3D from "manifold-3d";
3
3
  /**
4
- * Contains various functions for making shapes Manifold library https://github.com/elalish/manifold
5
- * Thanks Manifold community for developing this kernel
4
+ * Building Manifold cross-sections, the flat outlines that become solids: squares, rectangles,
5
+ * circles and outlines from raw polygons. They lie in the XY plane; `center` places a shape on the
6
+ * origin, otherwise its corner sits there.
6
7
  */
7
8
  export declare class CrossSectionShapes {
8
9
  private manifold;
9
10
  constructor(wasm: Manifold3D.ManifoldToplevel);
10
11
  /**
11
- * Create a 2d cross-section from a set of contours (complex polygons). A
12
- * boolean union operation (with Positive filling rule by default) is
13
- * performed to combine overlapping polygons and ensure the resulting
14
- * CrossSection is free of intersections.
15
- * @param inputs polygons and fill rule
16
- * @returns cross section
12
+ * Builds a cross-section from polygons given as 2D points, fusing overlapping ones so the
13
+ * result has no crossings.
14
+ *
15
+ * `fillRule` decides which regions count as inside where polygons overlap or a polygon crosses
16
+ * itself.
17
+ * @param inputs - The polygons as 2D point lists and the fill rule
18
+ * @returns The cross-section
17
19
  * @group base
18
20
  * @shortname create
19
21
  * @drawable true
22
+ * @example
23
+ * ```typescript
24
+ * const outline = await bitbybit.manifold.crossSection.shapes.create({ polygons: [[[0, 0], [10, 0], [10, 10], [0, 10]]], fillRule: Bit.Inputs.Manifold.fillRuleEnum.evenOdd });
25
+ * ```
20
26
  */
21
27
  create(inputs: Inputs.Manifold.CreateContourSectionDto): Manifold3D.CrossSection;
22
28
  /**
23
- * Create a 2D square cross section
24
- * @param inputs Square parameters
25
- * @returns square cross section
29
+ * Creates a square cross-section of the given side; with `center` true it is centered on the
30
+ * origin, otherwise its corner sits there.
31
+ * @param inputs - The side length and whether to center it
32
+ * @returns The square cross-section
26
33
  * @group primitives
27
34
  * @shortname square
28
35
  * @drawable true
36
+ * @example
37
+ * ```typescript
38
+ * const square = await bitbybit.manifold.crossSection.shapes.square({ size: 10, center: true });
39
+ * ```
29
40
  */
30
41
  square(inputs: Inputs.Manifold.SquareDto): Manifold3D.CrossSection;
31
42
  /**
32
- * Create a 2D circle cross section
33
- * @param inputs Circle parameters
34
- * @returns circle cross section
43
+ * Creates a circular cross-section of the given radius, centered on the origin and drawn with
44
+ * `circularSegments` straight sides.
45
+ * @param inputs - The radius and the number of sides
46
+ * @returns The circle cross-section
35
47
  * @group primitives
36
48
  * @shortname circle
37
49
  * @drawable true
50
+ * @example
51
+ * ```typescript
52
+ * const disc = await bitbybit.manifold.crossSection.shapes.circle({ radius: 5, circularSegments: 64 });
53
+ * ```
38
54
  */
39
55
  circle(inputs: Inputs.Manifold.CircleDto): Manifold3D.CrossSection;
40
56
  /**
41
- * Create a 2D rectangle cross section
42
- * @param inputs Rectangle parameters
43
- * @returns rectangle cross section
57
+ * Creates a rectangular cross-section with `length` along X and `height` along Y; with `center`
58
+ * true it is centered on the origin, otherwise its corner sits there.
59
+ * @param inputs - The length, the height and whether to center it
60
+ * @returns The rectangle cross-section
44
61
  * @group primitives
45
62
  * @shortname rectangle
46
63
  * @drawable true
64
+ * @example
65
+ * ```typescript
66
+ * const rectangle = await bitbybit.manifold.crossSection.shapes.rectangle({ length: 20, height: 10, center: true });
67
+ * ```
47
68
  */
48
69
  rectangle(inputs: Inputs.Manifold.RectangleDto): Manifold3D.CrossSection;
49
70
  }
@@ -1,33 +1,44 @@
1
1
  /**
2
- * Contains various functions for making shapes Manifold library https://github.com/elalish/manifold
3
- * Thanks Manifold community for developing this kernel
2
+ * Building Manifold cross-sections, the flat outlines that become solids: squares, rectangles,
3
+ * circles and outlines from raw polygons. They lie in the XY plane; `center` places a shape on the
4
+ * origin, otherwise its corner sits there.
4
5
  */
5
6
  export class CrossSectionShapes {
6
7
  constructor(wasm) {
7
8
  this.manifold = wasm;
8
9
  }
9
10
  /**
10
- * Create a 2d cross-section from a set of contours (complex polygons). A
11
- * boolean union operation (with Positive filling rule by default) is
12
- * performed to combine overlapping polygons and ensure the resulting
13
- * CrossSection is free of intersections.
14
- * @param inputs polygons and fill rule
15
- * @returns cross section
11
+ * Builds a cross-section from polygons given as 2D points, fusing overlapping ones so the
12
+ * result has no crossings.
13
+ *
14
+ * `fillRule` decides which regions count as inside where polygons overlap or a polygon crosses
15
+ * itself.
16
+ * @param inputs - The polygons as 2D point lists and the fill rule
17
+ * @returns The cross-section
16
18
  * @group base
17
19
  * @shortname create
18
20
  * @drawable true
21
+ * @example
22
+ * ```typescript
23
+ * const outline = await bitbybit.manifold.crossSection.shapes.create({ polygons: [[[0, 0], [10, 0], [10, 10], [0, 10]]], fillRule: Bit.Inputs.Manifold.fillRuleEnum.evenOdd });
24
+ * ```
19
25
  */
20
26
  create(inputs) {
21
27
  const { CrossSection } = this.manifold;
22
28
  return new CrossSection(inputs.polygons, inputs.fillRule);
23
29
  }
24
30
  /**
25
- * Create a 2D square cross section
26
- * @param inputs Square parameters
27
- * @returns square cross section
31
+ * Creates a square cross-section of the given side; with `center` true it is centered on the
32
+ * origin, otherwise its corner sits there.
33
+ * @param inputs - The side length and whether to center it
34
+ * @returns The square cross-section
28
35
  * @group primitives
29
36
  * @shortname square
30
37
  * @drawable true
38
+ * @example
39
+ * ```typescript
40
+ * const square = await bitbybit.manifold.crossSection.shapes.square({ size: 10, center: true });
41
+ * ```
31
42
  */
32
43
  square(inputs) {
33
44
  const { CrossSection } = this.manifold;
@@ -35,12 +46,17 @@ export class CrossSectionShapes {
35
46
  return square(inputs.size, inputs.center);
36
47
  }
37
48
  /**
38
- * Create a 2D circle cross section
39
- * @param inputs Circle parameters
40
- * @returns circle cross section
49
+ * Creates a circular cross-section of the given radius, centered on the origin and drawn with
50
+ * `circularSegments` straight sides.
51
+ * @param inputs - The radius and the number of sides
52
+ * @returns The circle cross-section
41
53
  * @group primitives
42
54
  * @shortname circle
43
55
  * @drawable true
56
+ * @example
57
+ * ```typescript
58
+ * const disc = await bitbybit.manifold.crossSection.shapes.circle({ radius: 5, circularSegments: 64 });
59
+ * ```
44
60
  */
45
61
  circle(inputs) {
46
62
  const { CrossSection } = this.manifold;
@@ -48,12 +64,17 @@ export class CrossSectionShapes {
48
64
  return circle(inputs.radius, inputs.circularSegments);
49
65
  }
50
66
  /**
51
- * Create a 2D rectangle cross section
52
- * @param inputs Rectangle parameters
53
- * @returns rectangle cross section
67
+ * Creates a rectangular cross-section with `length` along X and `height` along Y; with `center`
68
+ * true it is centered on the origin, otherwise its corner sits there.
69
+ * @param inputs - The length, the height and whether to center it
70
+ * @returns The rectangle cross-section
54
71
  * @group primitives
55
72
  * @shortname rectangle
56
73
  * @drawable true
74
+ * @example
75
+ * ```typescript
76
+ * const rectangle = await bitbybit.manifold.crossSection.shapes.rectangle({ length: 20, height: 10, center: true });
77
+ * ```
57
78
  */
58
79
  rectangle(inputs) {
59
80
  const { CrossSection } = this.manifold;