@bitbybit-dev/base 1.7.0 → 1.8.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/NOTICE +24 -0
- package/README.md +3 -1
- package/lib/api/GlobalCDNProvider.js +1 -1
- package/lib/api/inputs/base-inputs.d.ts +20 -0
- package/lib/api/inputs/base-inputs.js +22 -0
- package/lib/api/inputs/io-inputs.d.ts +408 -8
- package/lib/api/inputs/io-inputs.js +344 -7
- package/lib/api/inputs/mesh-inputs.d.ts +20 -1
- package/lib/api/inputs/mesh-inputs.js +23 -0
- package/lib/api/inputs/recipes-inputs.d.ts +13 -5
- package/lib/api/inputs/recipes-inputs.js +10 -5
- package/lib/api/kernel-calls/index.d.ts +1 -0
- package/lib/api/kernel-calls/index.js +1 -0
- package/lib/api/kernel-calls/resolve-dto.d.ts +3 -1
- package/lib/api/kernel-calls/resolve-dto.js +7 -2
- package/lib/api/kernel-calls/settings.d.ts +19 -0
- package/lib/api/kernel-calls/up-axis-aliases.d.ts +25 -0
- package/lib/api/kernel-calls/up-axis-aliases.js +70 -0
- package/lib/api/models/simplex.d.ts +2 -0
- package/lib/api/models/simplex.js +10 -1
- package/lib/api/resolved-inputs/index.d.ts +11 -2
- package/lib/api/services/helpers/curves/conic-arcs.d.ts +3 -1
- package/lib/api/services/helpers/curves/conic-arcs.js +4 -2
- package/lib/api/services/helpers/files/drawing/drawing-budget.js +16 -6
- package/lib/api/services/helpers/files/drawing/drawing-dimension.constants.d.ts +14 -0
- package/lib/api/services/helpers/files/drawing/drawing-dimension.constants.js +14 -0
- package/lib/api/services/helpers/files/drawing/drawing-dimension.d.ts +4 -0
- package/lib/api/services/helpers/files/drawing/drawing-dimension.js +271 -0
- package/lib/api/services/helpers/files/drawing/drawing-geometry.d.ts +3 -0
- package/lib/api/services/helpers/files/drawing/drawing-geometry.js +28 -11
- package/lib/api/services/helpers/files/drawing/drawing-hatch.d.ts +10 -0
- package/lib/api/services/helpers/files/drawing/drawing-hatch.js +123 -0
- package/lib/api/services/helpers/files/drawing/drawing-loops.d.ts +3 -0
- package/lib/api/services/helpers/files/drawing/drawing-loops.js +91 -0
- package/lib/api/services/helpers/files/drawing/drawing-model.d.ts +6 -1
- package/lib/api/services/helpers/files/drawing/drawing-model.js +97 -13
- package/lib/api/services/helpers/files/drawing/drawing-scale.d.ts +2 -0
- package/lib/api/services/helpers/files/drawing/drawing-scale.js +47 -0
- package/lib/api/services/helpers/files/drawing/drawing-text.d.ts +9 -0
- package/lib/api/services/helpers/files/drawing/drawing-text.js +25 -0
- package/lib/api/services/helpers/files/drawing/drawing-types.d.ts +57 -0
- package/lib/api/services/helpers/files/drawing/drawing.constants.d.ts +13 -0
- package/lib/api/services/helpers/files/drawing/drawing.constants.js +17 -0
- package/lib/api/services/helpers/files/dxf/dxf-annotations.d.ts +5 -0
- package/lib/api/services/helpers/files/dxf/dxf-annotations.js +96 -0
- package/lib/api/services/helpers/files/dxf/dxf-entities.d.ts +5 -1
- package/lib/api/services/helpers/files/dxf/dxf-entities.js +5 -2
- package/lib/api/services/helpers/files/dxf/dxf-generator.js +26 -10
- package/lib/api/services/helpers/files/dxf/dxf-reader-annotations.d.ts +9 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-annotations.js +312 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-dtos.js +37 -3
- package/lib/api/services/helpers/files/dxf/dxf-reader-segments.d.ts +9 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-segments.js +151 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader-types.d.ts +27 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.constants.d.ts +63 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.constants.js +17 -0
- package/lib/api/services/helpers/files/dxf/dxf-reader.d.ts +1 -1
- package/lib/api/services/helpers/files/dxf/dxf-reader.js +71 -181
- package/lib/api/services/helpers/files/dxf/dxf-tables.d.ts +2 -0
- package/lib/api/services/helpers/files/dxf/dxf-tables.js +5 -4
- package/lib/api/services/helpers/files/dxf/dxf-tokens.d.ts +2 -0
- package/lib/api/services/helpers/files/dxf/dxf-tokens.js +25 -1
- package/lib/api/services/helpers/files/dxf/dxf.constants.d.ts +11 -0
- package/lib/api/services/helpers/files/dxf/dxf.constants.js +13 -0
- package/lib/api/services/helpers/files/svg/svg-strokes.d.ts +1 -1
- package/lib/api/services/helpers/files/svg/svg-strokes.js +47 -23
- package/lib/api/services/helpers/files/svg/svg-writer.d.ts +2 -0
- package/lib/api/services/helpers/files/svg/svg-writer.js +100 -23
- package/lib/api/services/helpers/files/svg/svg.constants.d.ts +2 -1
- package/lib/api/services/helpers/files/svg/svg.constants.js +2 -1
- package/lib/api/services/helpers/geometry/loop-fill.d.ts +2 -0
- package/lib/api/services/helpers/geometry/loop-fill.js +37 -0
- package/lib/api/services/helpers/helper-types.d.ts +33 -0
- package/lib/api/services/helpers/text/stroke-font.d.ts +6 -0
- package/lib/api/services/helpers/text/stroke-font.js +177 -0
- package/lib/api/services/helpers/text/stroke-letters.constants.d.ts +2 -0
- package/lib/api/services/helpers/text/stroke-letters.constants.js +18 -0
- package/lib/api/services/helpers/text/stroke-marks.constants.d.ts +14 -0
- package/lib/api/services/helpers/text/stroke-marks.constants.js +34 -0
- package/lib/api/services/io/drawing.d.ts +198 -0
- package/lib/api/services/io/drawing.js +242 -0
- package/lib/api/services/io/dxf.d.ts +3 -3
- package/lib/api/services/io/dxf.js +4 -4
- package/lib/api/services/io/svg.d.ts +13 -11
- package/lib/api/services/io/svg.js +15 -12
- package/lib/api/services/mesh.d.ts +19 -0
- package/lib/api/services/mesh.js +40 -0
- package/lib/api/services/recipes.js +3 -2
- package/lib/api/services/text.d.ts +3 -3
- package/lib/api/services/text.js +7 -25
- package/package.json +1 -1
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import * as Inputs from "../../inputs";
|
|
2
2
|
import { resolveDto } from "../../kernel-calls";
|
|
3
|
+
import { simplex } from "../../models/simplex";
|
|
4
|
+
import { clippedHatchLinesOf, hatchLinesOf, hatchOutlinesOf } from "../helpers/files/drawing/drawing-hatch";
|
|
5
|
+
import { drawingHatchOf, drawingTextOf, positiveNumber } from "../helpers/files/drawing/drawing-model";
|
|
6
|
+
import { scaledDrawingParts } from "../helpers/files/drawing/drawing-scale";
|
|
7
|
+
import { textStrokesOf } from "../helpers/files/drawing/drawing-text";
|
|
8
|
+
import { dimensionExtentOf, dimensionPictureOf } from "../helpers/files/drawing/drawing-dimension";
|
|
9
|
+
import { strokeFontInk } from "../helpers/text/stroke-font";
|
|
10
|
+
const HATCH_BOUNDS_TOLERANCE = 0.01;
|
|
11
|
+
const MEASURED_AT = [0, 0];
|
|
3
12
|
/**
|
|
4
13
|
* Builds drawings as data, for any file format: segments of every kind, paths joined from segments,
|
|
5
14
|
* and parts that put paths on a layer with a color and a line type. `io.dxf.dxfCreate` writes the
|
|
@@ -149,6 +158,239 @@ export class Drawing {
|
|
|
149
158
|
const resolved = resolveDto(Inputs.IO.DrawingPartDto, inputs);
|
|
150
159
|
return resolved;
|
|
151
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Scales drawing parts about the origin, returning new parts and leaving the given ones unchanged.
|
|
163
|
+
*
|
|
164
|
+
* Points, radii, axes, text heights, hatch spacings and line weights are multiplied by `factor`;
|
|
165
|
+
* angles, bulges, knots and weights stay. Scale before writing with `io.dxf.dxfCreate` or
|
|
166
|
+
* `io.svg.svgCreate`: their `unit` labels the drawing and never scales it. A factor not above 0
|
|
167
|
+
* throws.
|
|
168
|
+
* @param inputs - The parts and the factor
|
|
169
|
+
* @returns New parts, scaled
|
|
170
|
+
* @group drawing
|
|
171
|
+
* @shortname scale parts
|
|
172
|
+
* @drawable false
|
|
173
|
+
* @beta
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* const plate = bitbybit.io.drawing.part({ layer: "cut", paths: [{ segments: [{ center: [0, 0], radius: 25.4 }] }], lineWeight: 0.5 });
|
|
177
|
+
* const inches = bitbybit.io.drawing.scaleParts({ parts: [plate], factor: 1 / 25.4 });
|
|
178
|
+
* const dxf = bitbybit.io.dxf.dxfCreate({ dxfPathsParts: inches, unit: Bit.Inputs.Base.unitOfLengthEnum.inch });
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
scaleParts(inputs) {
|
|
182
|
+
const resolved = resolveDto(Inputs.IO.DrawingScalePartsDto, inputs);
|
|
183
|
+
return scaledDrawingParts(resolved.parts, resolved.factor, "parts");
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Makes a line of text for a drawing part's `texts`, in the single-line stroke font.
|
|
187
|
+
*
|
|
188
|
+
* The text is placed by a point on its baseline; `anchor` says whether that point is its start,
|
|
189
|
+
* middle or end, `rotation` turns it and `widthFactor` narrows or widens its letters.
|
|
190
|
+
* @param inputs - The text, its position and height, its anchor, its angle and its width factor
|
|
191
|
+
* @returns The text
|
|
192
|
+
* @group drawing
|
|
193
|
+
* @shortname text
|
|
194
|
+
* @drawable false
|
|
195
|
+
* @beta
|
|
196
|
+
* @example
|
|
197
|
+
* ```typescript
|
|
198
|
+
* const title = bitbybit.io.drawing.text({ text: "BRACKET", position: [20, 10], height: 5 });
|
|
199
|
+
* const notes = bitbybit.io.drawing.part({ layer: "text", paths: [], texts: [title], lineWeight: 0.35 });
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
text(inputs) {
|
|
203
|
+
const resolved = resolveDto(Inputs.IO.DrawingTextDto, inputs);
|
|
204
|
+
return resolved;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Makes a hatched region for a drawing part's `hatches`: what the boundaries enclose, filled with
|
|
208
|
+
* a pattern of lines or with solid ink.
|
|
209
|
+
*
|
|
210
|
+
* A boundary inside another cuts a hole, and a boundary whose ends do not meet is closed by a
|
|
211
|
+
* straight line.
|
|
212
|
+
* @param inputs - The boundary paths, the pattern, and the angle and spacing of its lines
|
|
213
|
+
* @returns The hatch
|
|
214
|
+
* @group drawing
|
|
215
|
+
* @shortname hatch
|
|
216
|
+
* @drawable false
|
|
217
|
+
* @beta
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* const outline = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [40, 0], [40, 30], [0, 30]], closed: true });
|
|
221
|
+
* const bore = bitbybit.io.drawing.circleSegment({ center: [20, 15], radius: 6 });
|
|
222
|
+
* const cut = bitbybit.io.drawing.hatch({ boundaries: [{ segments: [outline] }, { segments: [bore] }], angle: 45, spacing: 3 });
|
|
223
|
+
* const section = bitbybit.io.drawing.part({ layer: "hatch", paths: [], hatches: [cut], lineWeight: 0.18 });
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
hatch(inputs) {
|
|
227
|
+
const resolved = resolveDto(Inputs.IO.DrawingHatchDto, inputs);
|
|
228
|
+
return resolved;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Gives the lines of a hatch's pattern, each from side to side of the box around its
|
|
232
|
+
* boundaries, for a renderer that draws them itself and clips them to the region.
|
|
233
|
+
*
|
|
234
|
+
* The lines stand where `io.svg.svgCreate` and `io.dxf.dxfCreate` put them, each whole. `solid`
|
|
235
|
+
* gives none, and a spacing too fine for the region throws.
|
|
236
|
+
* @param inputs - The boundary paths, the pattern, and the angle and spacing of its lines
|
|
237
|
+
* @returns The lines, each a start and an end point
|
|
238
|
+
* @group drawing
|
|
239
|
+
* @shortname hatch lines
|
|
240
|
+
* @drawable false
|
|
241
|
+
* @beta
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* const outline = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [40, 0], [40, 30], [0, 30]], closed: true });
|
|
245
|
+
* const lines = bitbybit.io.drawing.hatchLines({ boundaries: [{ segments: [outline] }], angle: 45, spacing: 3 });
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
hatchLines(inputs) {
|
|
249
|
+
const resolved = resolveDto(Inputs.IO.DrawingHatchDto, inputs);
|
|
250
|
+
return hatchLinesOf(drawingHatchOf(resolved, ""), HATCH_BOUNDS_TOLERANCE, "spacing");
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Gives the lines of a hatch's pattern clipped to its region, for a renderer that draws them
|
|
254
|
+
* itself.
|
|
255
|
+
*
|
|
256
|
+
* Inside follows the even-odd rule over every boundary, as `io.svg.svgCreate` fills a hatch, and
|
|
257
|
+
* curves are followed within `tolerance`. The lines stand where `hatchLines` puts them. `solid`
|
|
258
|
+
* gives none; a spacing too fine for the region throws.
|
|
259
|
+
* @param inputs - The boundary paths, the pattern, the angle and spacing of its lines, and the tolerance for curves
|
|
260
|
+
* @returns The pieces of the lines inside the region, each a start and an end point
|
|
261
|
+
* @group drawing
|
|
262
|
+
* @shortname clipped hatch lines
|
|
263
|
+
* @drawable false
|
|
264
|
+
* @beta
|
|
265
|
+
* @example
|
|
266
|
+
* ```typescript
|
|
267
|
+
* const outline = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [40, 0], [40, 30], [0, 30]], closed: true });
|
|
268
|
+
* const bore = bitbybit.io.drawing.circleSegment({ center: [20, 15], radius: 6 });
|
|
269
|
+
* const lines = bitbybit.io.drawing.clippedHatchLines({ boundaries: [{ segments: [outline] }, { segments: [bore] }], angle: 45, spacing: 3, tolerance: 0.01 });
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
clippedHatchLines(inputs) {
|
|
273
|
+
const resolved = resolveDto(Inputs.IO.DrawingHatchRegionDto, inputs);
|
|
274
|
+
const tolerance = positiveNumber(resolved.tolerance, "tolerance");
|
|
275
|
+
return clippedHatchLinesOf(drawingHatchOf(resolved, ""), tolerance, "spacing");
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Gives the outlines of a hatch's region as closed loops of points, curves followed within
|
|
279
|
+
* `tolerance`, for a renderer that fills the region itself.
|
|
280
|
+
*
|
|
281
|
+
* Each loop lists every corner once. Fill them under the even-odd rule, as
|
|
282
|
+
* `mesh.triangulateLoops` does, to keep the holes open.
|
|
283
|
+
* Example: a circle of radius 5 at tolerance 0.01 -> one loop of 50 points
|
|
284
|
+
* @param inputs - The boundary paths and the tolerance for curves; the pattern, angle and spacing play no part
|
|
285
|
+
* @returns The loops, each a list of points
|
|
286
|
+
* @group drawing
|
|
287
|
+
* @shortname hatch outlines
|
|
288
|
+
* @drawable false
|
|
289
|
+
* @beta
|
|
290
|
+
* @example
|
|
291
|
+
* ```typescript
|
|
292
|
+
* const outline = bitbybit.io.drawing.polylineSegment({ points: [[0, 0], [40, 0], [40, 30], [0, 30]], closed: true });
|
|
293
|
+
* const bore = bitbybit.io.drawing.circleSegment({ center: [20, 15], radius: 6 });
|
|
294
|
+
* const loops = bitbybit.io.drawing.hatchOutlines({ boundaries: [{ segments: [outline] }, { segments: [bore] }], tolerance: 0.01 });
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
hatchOutlines(inputs) {
|
|
298
|
+
const resolved = resolveDto(Inputs.IO.DrawingHatchRegionDto, inputs);
|
|
299
|
+
const tolerance = positiveNumber(resolved.tolerance, "tolerance");
|
|
300
|
+
return hatchOutlinesOf(drawingHatchOf(resolved, ""), tolerance);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Measures a drawing text: its length along the baseline, and how far the font's ink reaches
|
|
304
|
+
* above and below it.
|
|
305
|
+
*
|
|
306
|
+
* The width is what `io.svg.svgCreate` draws and `io.dxf.dxfCreate` fits the text to; the
|
|
307
|
+
* position is not needed to measure it. A text that is not one line throws.
|
|
308
|
+
* Example: 'I' at height 21 -> width 8, above 25, below 7
|
|
309
|
+
* @param inputs - The text with its height and width factor
|
|
310
|
+
* @returns The width, and the reach of the font's ink above and below the baseline
|
|
311
|
+
* @group drawing
|
|
312
|
+
* @shortname text size
|
|
313
|
+
* @drawable false
|
|
314
|
+
* @beta
|
|
315
|
+
* @example
|
|
316
|
+
* ```typescript
|
|
317
|
+
* const size = bitbybit.io.drawing.textSize({ text: "SECTION A-A", position: [0, 0], height: 3.5 });
|
|
318
|
+
* const cellWidth = size.width + 2;
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
textSize(inputs) {
|
|
322
|
+
var _a;
|
|
323
|
+
const resolved = resolveDto(Inputs.IO.DrawingTextDto, inputs);
|
|
324
|
+
const text = drawingTextOf(Object.assign(Object.assign({}, resolved), { position: (_a = resolved.position) !== null && _a !== void 0 ? _a : MEASURED_AT }), "");
|
|
325
|
+
const ink = strokeFontInk(simplex);
|
|
326
|
+
return { width: text.width, above: ink.highest * text.height, below: -ink.lowest * text.height };
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Draws a drawing text as the strokes of its letters, each a list of points in the drawing's
|
|
330
|
+
* coordinates, placed, turned and narrowed as the text says.
|
|
331
|
+
*
|
|
332
|
+
* These are the strokes `io.svg.svgCreate` writes. A text that is not one line throws.
|
|
333
|
+
* Example: 'I' at height 21 from [10, 20] -> one stroke, [[14, 41, 0], [14, 20, 0]]
|
|
334
|
+
* @param inputs - The text, its position and height, its anchor, its angle and its width factor
|
|
335
|
+
* @returns The strokes, each a list of points
|
|
336
|
+
* @group drawing
|
|
337
|
+
* @shortname text strokes
|
|
338
|
+
* @drawable false
|
|
339
|
+
* @beta
|
|
340
|
+
* @example
|
|
341
|
+
* ```typescript
|
|
342
|
+
* const strokes = bitbybit.io.drawing.textStrokes({ text: "A-A", position: [0, 0], height: 5, anchor: "middle" });
|
|
343
|
+
* ```
|
|
344
|
+
*/
|
|
345
|
+
textStrokes(inputs) {
|
|
346
|
+
const resolved = resolveDto(Inputs.IO.DrawingTextDto, inputs);
|
|
347
|
+
return textStrokesOf(drawingTextOf(resolved, ""));
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Draws a dimension in the drawing's plane: its dimension line or arc, its extension lines, filled
|
|
351
|
+
* arrowheads touching them, and its value in the stroke font.
|
|
352
|
+
*
|
|
353
|
+
* The text reads from left to right or from bottom to top, past the line's end when the line is
|
|
354
|
+
* too short for it; arrows go outside a span too short for them.
|
|
355
|
+
* @param inputs - What the dimension measures, its points, its tolerance and the size of its text and arrows
|
|
356
|
+
* @returns The lines, the arrowheads to fill, the text as strokes and as a drawing text, and the box they fill
|
|
357
|
+
* @group drawing
|
|
358
|
+
* @shortname dimension picture
|
|
359
|
+
* @drawable false
|
|
360
|
+
* @beta
|
|
361
|
+
* @example
|
|
362
|
+
* ```typescript
|
|
363
|
+
* const picture = bitbybit.io.drawing.dimensionPicture({ kind: Bit.Inputs.IO.dimensionKindEnum.linear, start: [0, 0], end: [60, 0], offset: 12, upperTolerance: 0.1, lowerTolerance: 0.1 });
|
|
364
|
+
* const edges = bitbybit.io.drawing.part({ layer: "dimensions", paths: [...picture.lines, ...picture.textStrokes].map(points => ({ segments: [{ points }] })) });
|
|
365
|
+
* ```
|
|
366
|
+
*/
|
|
367
|
+
dimensionPicture(inputs) {
|
|
368
|
+
const resolved = resolveDto(Inputs.IO.DrawingDimensionDto, inputs);
|
|
369
|
+
return dimensionPictureOf(resolved);
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Measures the box a dimension's picture fills, the box `dimensionPicture` gives, without drawing
|
|
373
|
+
* the letters.
|
|
374
|
+
*
|
|
375
|
+
* The box holds the whole height the stroke font's letters may reach, so a layout can make room
|
|
376
|
+
* before drawing.
|
|
377
|
+
* Example: a linear dimension from [0, 0] to [60, 0] at offset 12 -> min [0, 0.875], max [60, 17.04]
|
|
378
|
+
* @param inputs - What the dimension measures, its points, its tolerance and the size of its text and arrows
|
|
379
|
+
* @returns The lowest and highest corners of the box
|
|
380
|
+
* @group drawing
|
|
381
|
+
* @shortname dimension extent
|
|
382
|
+
* @drawable false
|
|
383
|
+
* @beta
|
|
384
|
+
* @example
|
|
385
|
+
* ```typescript
|
|
386
|
+
* const box = bitbybit.io.drawing.dimensionExtent({ kind: Bit.Inputs.IO.dimensionKindEnum.diameter, start: [0, 0], end: [5, 0] });
|
|
387
|
+
* const width = box.max[0] - box.min[0];
|
|
388
|
+
* ```
|
|
389
|
+
*/
|
|
390
|
+
dimensionExtent(inputs) {
|
|
391
|
+
const resolved = resolveDto(Inputs.IO.DrawingDimensionDto, inputs);
|
|
392
|
+
return dimensionExtentOf(resolved);
|
|
393
|
+
}
|
|
152
394
|
/**
|
|
153
395
|
* Converts an SVG file into a DXF file, reading it as `io.svg.svgRead` does and writing it as
|
|
154
396
|
* `io.dxf.dxfCreate` does.
|
|
@@ -116,9 +116,9 @@ export declare class Dxf {
|
|
|
116
116
|
/**
|
|
117
117
|
* Reads a DXF file into path parts by layer, color and line type, the model `dxfCreate` writes.
|
|
118
118
|
*
|
|
119
|
-
* Lines, arcs, circles, ellipses, polylines and splines are read exactly
|
|
120
|
-
*
|
|
121
|
-
* `warnings`; splines given only by fit points
|
|
119
|
+
* Lines, arcs, circles, ellipses, polylines and splines are read exactly, block inserts
|
|
120
|
+
* expanded, with single-line texts and hatches. Multi-line text and dimensions are named in
|
|
121
|
+
* `warnings`; `occt.io.loadDxf` reads splines given only by fit points.
|
|
122
122
|
* @param inputs - The DXF file, as text or bytes, and whether hidden layers are read
|
|
123
123
|
* @returns The drawing's parts, unit, version and warnings
|
|
124
124
|
* @group dxf
|
|
@@ -146,9 +146,9 @@ export class Dxf {
|
|
|
146
146
|
/**
|
|
147
147
|
* Reads a DXF file into path parts by layer, color and line type, the model `dxfCreate` writes.
|
|
148
148
|
*
|
|
149
|
-
* Lines, arcs, circles, ellipses, polylines and splines are read exactly
|
|
150
|
-
*
|
|
151
|
-
* `warnings`; splines given only by fit points
|
|
149
|
+
* Lines, arcs, circles, ellipses, polylines and splines are read exactly, block inserts
|
|
150
|
+
* expanded, with single-line texts and hatches. Multi-line text and dimensions are named in
|
|
151
|
+
* `warnings`; `occt.io.loadDxf` reads splines given only by fit points.
|
|
152
152
|
* @param inputs - The DXF file, as text or bytes, and whether hidden layers are read
|
|
153
153
|
* @returns The drawing's parts, unit, version and warnings
|
|
154
154
|
* @group dxf
|
|
@@ -162,6 +162,6 @@ export class Dxf {
|
|
|
162
162
|
*/
|
|
163
163
|
dxfRead(inputs) {
|
|
164
164
|
const resolved = resolveDto(Inputs.IO.DxfReadDto, inputs);
|
|
165
|
-
return drawingDtoOf(readDxfDrawing(dxfTextOf(resolved.dxf, "dxf"), resolved.includeHiddenLayers));
|
|
165
|
+
return drawingDtoOf(readDxfDrawing(dxfTextOf(resolved.dxf, "dxf"), resolved.includeHiddenLayers, true));
|
|
166
166
|
}
|
|
167
167
|
}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import * as Inputs from "../../inputs";
|
|
2
2
|
/**
|
|
3
3
|
* Writes SVG drawings from the same path parts DXF files are made of: lines, arcs, circles, bulged
|
|
4
|
-
* polylines, splines and ellipses, kept exact wherever SVG can draw them
|
|
5
|
-
*
|
|
4
|
+
* polylines, splines and ellipses, kept exact wherever SVG can draw them, with texts drawn as the
|
|
5
|
+
* strokes of their letters and hatches filled with patterns. Reads SVG files back into those parts,
|
|
6
|
+
* by layer, color and line type.
|
|
6
7
|
*/
|
|
7
8
|
export declare class Svg {
|
|
8
9
|
/**
|
|
9
10
|
* Writes an SVG file from path parts, each layer an Inkscape layer.
|
|
10
11
|
*
|
|
11
12
|
* Arcs, circles, ellipses and bulges stay exact arcs, unweighted splines up to degree 3 exact
|
|
12
|
-
* Beziers, others cubics within `tolerance
|
|
13
|
-
* is dropped and `unit` gives the true size. A drawing too large to
|
|
14
|
-
*
|
|
13
|
+
* Beziers, others cubics within `tolerance`. Texts become letter strokes, hatches patterned
|
|
14
|
+
* regions. Y points up, Z is dropped and `unit` gives the true size. A drawing too large to
|
|
15
|
+
* write throws.
|
|
16
|
+
* @param inputs - The path parts with their texts, hatches and line weights, the unit, the line width, the border, the dash scale and the curve tolerance
|
|
15
17
|
* @returns The SVG file as text
|
|
16
18
|
* @group svg
|
|
17
19
|
* @shortname svg create
|
|
@@ -29,9 +31,9 @@ export declare class Svg {
|
|
|
29
31
|
* Writes one drawing path as SVG path data, the text of a `path` element's `d` attribute.
|
|
30
32
|
*
|
|
31
33
|
* Segments that meet are drawn as one stroke, reversed where a segment ends where the stroke is,
|
|
32
|
-
* and a stroke that returns to its start is closed. Curves
|
|
33
|
-
*
|
|
34
|
-
* @param inputs - The path, whether Y is negated,
|
|
34
|
+
* and a stroke that returns to its start is closed. Curves stay exact as in `svgCreate`, or with
|
|
35
|
+
* `cubicsOnly` become cubic Beziers within `tolerance`.
|
|
36
|
+
* @param inputs - The path, whether Y is negated, the curve tolerance and whether only cubics are written
|
|
35
37
|
* @returns SVG path data
|
|
36
38
|
* @group svg
|
|
37
39
|
* @shortname path data
|
|
@@ -44,11 +46,11 @@ export declare class Svg {
|
|
|
44
46
|
*/
|
|
45
47
|
pathData(inputs: Inputs.IO.SvgPathDataDto): string;
|
|
46
48
|
/**
|
|
47
|
-
* Reads an SVG file into path parts by layer, color and line type
|
|
49
|
+
* Reads an SVG file into path parts by layer, color and line type.
|
|
48
50
|
*
|
|
49
|
-
* Lines, arcs and Bezier curves are read exactly, transforms applied
|
|
51
|
+
* Lines, arcs and Bezier curves are read exactly, transforms applied, Y up. Inkscape
|
|
50
52
|
* layers are layers, each stroke color (else fill) a color, each dash pattern a line type. Text
|
|
51
|
-
* and images are left out
|
|
53
|
+
* and images are left out, named in `warnings`; `svgCreate`'s texts and hatches return as paths.
|
|
52
54
|
* @param inputs - The SVG text, the unit to read it in and whether hidden elements are read
|
|
53
55
|
* @returns The drawing's parts, unit, view box and warnings
|
|
54
56
|
* @group svg
|
|
@@ -15,17 +15,19 @@ const marginOf = (value) => {
|
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
17
|
* Writes SVG drawings from the same path parts DXF files are made of: lines, arcs, circles, bulged
|
|
18
|
-
* polylines, splines and ellipses, kept exact wherever SVG can draw them
|
|
19
|
-
*
|
|
18
|
+
* polylines, splines and ellipses, kept exact wherever SVG can draw them, with texts drawn as the
|
|
19
|
+
* strokes of their letters and hatches filled with patterns. Reads SVG files back into those parts,
|
|
20
|
+
* by layer, color and line type.
|
|
20
21
|
*/
|
|
21
22
|
export class Svg {
|
|
22
23
|
/**
|
|
23
24
|
* Writes an SVG file from path parts, each layer an Inkscape layer.
|
|
24
25
|
*
|
|
25
26
|
* Arcs, circles, ellipses and bulges stay exact arcs, unweighted splines up to degree 3 exact
|
|
26
|
-
* Beziers, others cubics within `tolerance
|
|
27
|
-
* is dropped and `unit` gives the true size. A drawing too large to
|
|
28
|
-
*
|
|
27
|
+
* Beziers, others cubics within `tolerance`. Texts become letter strokes, hatches patterned
|
|
28
|
+
* regions. Y points up, Z is dropped and `unit` gives the true size. A drawing too large to
|
|
29
|
+
* write throws.
|
|
30
|
+
* @param inputs - The path parts with their texts, hatches and line weights, the unit, the line width, the border, the dash scale and the curve tolerance
|
|
29
31
|
* @returns The SVG file as text
|
|
30
32
|
* @group svg
|
|
31
33
|
* @shortname svg create
|
|
@@ -46,6 +48,7 @@ export class Svg {
|
|
|
46
48
|
unit,
|
|
47
49
|
strokeWidth: resolved.strokeWidth === undefined ? undefined : positiveNumber(resolved.strokeWidth, "strokeWidth"),
|
|
48
50
|
margin: marginOf(resolved.margin),
|
|
51
|
+
lineTypeScale: resolved.lineTypeScale === undefined ? undefined : positiveNumber(resolved.lineTypeScale, "lineTypeScale"),
|
|
49
52
|
tolerance,
|
|
50
53
|
property: "parts",
|
|
51
54
|
});
|
|
@@ -54,9 +57,9 @@ export class Svg {
|
|
|
54
57
|
* Writes one drawing path as SVG path data, the text of a `path` element's `d` attribute.
|
|
55
58
|
*
|
|
56
59
|
* Segments that meet are drawn as one stroke, reversed where a segment ends where the stroke is,
|
|
57
|
-
* and a stroke that returns to its start is closed. Curves
|
|
58
|
-
*
|
|
59
|
-
* @param inputs - The path, whether Y is negated,
|
|
60
|
+
* and a stroke that returns to its start is closed. Curves stay exact as in `svgCreate`, or with
|
|
61
|
+
* `cubicsOnly` become cubic Beziers within `tolerance`.
|
|
62
|
+
* @param inputs - The path, whether Y is negated, the curve tolerance and whether only cubics are written
|
|
60
63
|
* @returns SVG path data
|
|
61
64
|
* @group svg
|
|
62
65
|
* @shortname path data
|
|
@@ -70,14 +73,14 @@ export class Svg {
|
|
|
70
73
|
pathData(inputs) {
|
|
71
74
|
const resolved = resolveDto(Inputs.IO.SvgPathDataDto, inputs);
|
|
72
75
|
const tolerance = positiveNumber(resolved.tolerance, "tolerance");
|
|
73
|
-
return pathDataOf(drawingPathOf(resolved.path, "path"), { flipY: resolved.flipY, tolerance, property: "path" });
|
|
76
|
+
return pathDataOf(drawingPathOf(resolved.path, "path"), { flipY: resolved.flipY, cubicsOnly: resolved.cubicsOnly, tolerance, property: "path" });
|
|
74
77
|
}
|
|
75
78
|
/**
|
|
76
|
-
* Reads an SVG file into path parts by layer, color and line type
|
|
79
|
+
* Reads an SVG file into path parts by layer, color and line type.
|
|
77
80
|
*
|
|
78
|
-
* Lines, arcs and Bezier curves are read exactly, transforms applied
|
|
81
|
+
* Lines, arcs and Bezier curves are read exactly, transforms applied, Y up. Inkscape
|
|
79
82
|
* layers are layers, each stroke color (else fill) a color, each dash pattern a line type. Text
|
|
80
|
-
* and images are left out
|
|
83
|
+
* and images are left out, named in `warnings`; `svgCreate`'s texts and hatches return as paths.
|
|
81
84
|
* @param inputs - The SVG text, the unit to read it in and whether hidden elements are read
|
|
82
85
|
* @returns The drawing's parts, unit, view box and warnings
|
|
83
86
|
* @group svg
|
|
@@ -154,6 +154,25 @@ export declare class MeshBitByBit {
|
|
|
154
154
|
* ```
|
|
155
155
|
*/
|
|
156
156
|
triangulatePolygon(inputs: Inputs.Mesh.PolygonWithHolesDto): Inputs.Base.Mesh3;
|
|
157
|
+
/**
|
|
158
|
+
* Fills closed loops lying in one plane with triangles, as letters are filled.
|
|
159
|
+
*
|
|
160
|
+
* Outlines and holes come from how the loops nest, in any order or direction; under the default
|
|
161
|
+
* even-odd rule the middle of an `O` stays open.
|
|
162
|
+
* Example: a 4 by 4 square around a 2 by 2 square -> a ring of area 12
|
|
163
|
+
* @param inputs - The loops and the fill rule
|
|
164
|
+
* @returns The triangles, each three points
|
|
165
|
+
* @group polygon
|
|
166
|
+
* @shortname triangulate loops
|
|
167
|
+
* @drawable false
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* const outer = [[-2, -2, 0], [2, -2, 0], [2, 2, 0], [-2, 2, 0]];
|
|
171
|
+
* const inner = [[-1, -1, 0], [1, -1, 0], [1, 1, 0], [-1, 1, 0]];
|
|
172
|
+
* const ring = bitbybit.mesh.triangulateLoops({ loops: [outer, inner], fillRule: Bit.Inputs.Base.loopFillRuleEnum.evenOdd });
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
triangulateLoops(inputs: Inputs.Mesh.TriangulateLoopsDto): Inputs.Base.Mesh3;
|
|
157
176
|
/**
|
|
158
177
|
* Measures the volume a closed triangle mesh encloses, with a sign: positive when its triangles
|
|
159
178
|
* face outwards by the right-hand rule, negative when they all face inwards.
|
package/lib/api/services/mesh.js
CHANGED
|
@@ -3,6 +3,7 @@ import { InputError, resolveDto } from "../kernel-calls";
|
|
|
3
3
|
import { signedVolumeOf } from "./helpers/mesh/mesh-measures";
|
|
4
4
|
import { closestOnTriangle, pointInTree, treesNested, treesWithin, triangleTree } from "./helpers/mesh/mesh-proximity";
|
|
5
5
|
import { triangulateFace } from "./helpers/geometry/triangulation";
|
|
6
|
+
import { filledLoopTriangles } from "./helpers/geometry/loop-fill";
|
|
6
7
|
import { frustum, icosphere } from "./helpers/mesh/mesh-primitives";
|
|
7
8
|
import { axesAlong, isTriple, pointToWorld } from "./helpers/geometry/frame-axes";
|
|
8
9
|
import { add3, scale3 } from "./helpers/geometry/vectors";
|
|
@@ -10,6 +11,10 @@ import { computeVertexNormals, creasedVertices } from "./helpers/mesh/mesh-norma
|
|
|
10
11
|
import { windingComponents, windingRepairs } from "./helpers/mesh/mesh-orientation";
|
|
11
12
|
import { uniqueVectors } from "./helpers/geometry/vector-grid";
|
|
12
13
|
const TRIANGLE_CORNERS = 3;
|
|
14
|
+
const LOOP_FILL_RULES = {
|
|
15
|
+
[Inputs.Base.loopFillRuleEnum.evenOdd]: "evenOdd",
|
|
16
|
+
[Inputs.Base.loopFillRuleEnum.nonZero]: "nonzero",
|
|
17
|
+
};
|
|
13
18
|
const MAX_ICOSPHERE_DETAIL = 6;
|
|
14
19
|
const MIN_FRUSTUM_SIDES = 3;
|
|
15
20
|
const POINT_SIZE = 3;
|
|
@@ -385,6 +390,41 @@ export class MeshBitByBit {
|
|
|
385
390
|
}
|
|
386
391
|
return mesh;
|
|
387
392
|
}
|
|
393
|
+
/**
|
|
394
|
+
* Fills closed loops lying in one plane with triangles, as letters are filled.
|
|
395
|
+
*
|
|
396
|
+
* Outlines and holes come from how the loops nest, in any order or direction; under the default
|
|
397
|
+
* even-odd rule the middle of an `O` stays open.
|
|
398
|
+
* Example: a 4 by 4 square around a 2 by 2 square -> a ring of area 12
|
|
399
|
+
* @param inputs - The loops and the fill rule
|
|
400
|
+
* @returns The triangles, each three points
|
|
401
|
+
* @group polygon
|
|
402
|
+
* @shortname triangulate loops
|
|
403
|
+
* @drawable false
|
|
404
|
+
* @example
|
|
405
|
+
* ```typescript
|
|
406
|
+
* const outer = [[-2, -2, 0], [2, -2, 0], [2, 2, 0], [-2, 2, 0]];
|
|
407
|
+
* const inner = [[-1, -1, 0], [1, -1, 0], [1, 1, 0], [-1, 1, 0]];
|
|
408
|
+
* const ring = bitbybit.mesh.triangulateLoops({ loops: [outer, inner], fillRule: Bit.Inputs.Base.loopFillRuleEnum.evenOdd });
|
|
409
|
+
* ```
|
|
410
|
+
*/
|
|
411
|
+
triangulateLoops(inputs) {
|
|
412
|
+
const resolved = resolveDto(Inputs.Mesh.TriangulateLoopsDto, inputs);
|
|
413
|
+
const corners = resolved.loops.flat();
|
|
414
|
+
const positions = corners.flat();
|
|
415
|
+
let next = 0;
|
|
416
|
+
const loops = resolved.loops.map((loop) => loop.map(() => next++));
|
|
417
|
+
const rule = LOOP_FILL_RULES[resolved.fillRule];
|
|
418
|
+
if (rule === undefined) {
|
|
419
|
+
throw new InputError(`\`fillRule\` is ${String(resolved.fillRule)}, which is none of ${Object.keys(LOOP_FILL_RULES).join(", ")}.`, "fillRule");
|
|
420
|
+
}
|
|
421
|
+
const triangles = filledLoopTriangles(positions, loops, rule);
|
|
422
|
+
const mesh = [];
|
|
423
|
+
for (let at = 0; at + 2 < triangles.length; at += TRIANGLE_CORNERS) {
|
|
424
|
+
mesh.push([[...corners[triangles[at]]], [...corners[triangles[at + 1]]], [...corners[triangles[at + 2]]]]);
|
|
425
|
+
}
|
|
426
|
+
return mesh;
|
|
427
|
+
}
|
|
388
428
|
/**
|
|
389
429
|
* Measures the volume a closed triangle mesh encloses, with a sign: positive when its triangles
|
|
390
430
|
* face outwards by the right-hand rule, negative when they all face inwards.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Inputs from "../inputs";
|
|
2
|
-
import { InputError, resolveDto } from "../kernel-calls";
|
|
2
|
+
import { InputError, checkedUpAxis, resolveDto } from "../kernel-calls";
|
|
3
3
|
import { checkRecipe, toRecipe } from "../recipes/validate";
|
|
4
4
|
import { recipeSurfaceMeshes } from "../recipes/surface-mesh";
|
|
5
5
|
import { recipeSourceOf } from "../recipes/sources";
|
|
@@ -74,7 +74,8 @@ export class Recipes {
|
|
|
74
74
|
*/
|
|
75
75
|
surfaceMeshes(inputs) {
|
|
76
76
|
const resolved = resolveDto(Inputs.Recipes.RecipeSurfaceMeshesDto, inputs);
|
|
77
|
-
|
|
77
|
+
const upAxis = checkedUpAxis(resolved.upAxis, [Inputs.Base.upAxisConversionEnum.keep, Inputs.Base.upAxisConversionEnum.zUpToYUp]);
|
|
78
|
+
return recipeSurfaceMeshes(resolved.recipe, resolved.roots, upAxis === Inputs.Base.upAxisConversionEnum.zUpToYUp, this.settings().coordinateSystem);
|
|
78
79
|
}
|
|
79
80
|
/**
|
|
80
81
|
* Follows a node through the transforms that only turn and move to the step it places, folding
|
|
@@ -486,9 +486,9 @@ export declare class TextBitByBit {
|
|
|
486
486
|
/**
|
|
487
487
|
* Draws one character as line paths with a simple stroke font.
|
|
488
488
|
*
|
|
489
|
-
* The paths lie flat on the XZ plane,
|
|
490
|
-
*
|
|
491
|
-
* mark.
|
|
489
|
+
* The paths lie flat on the XZ plane, the character `height` tall, and come with its width and
|
|
490
|
+
* height. Accented Latin letters are drawn with their marks, other unknown characters as a
|
|
491
|
+
* question mark.
|
|
492
492
|
* Example: 'A' at height 10 -> the strokes of an A, 10 units tall
|
|
493
493
|
* @param inputs - The character, its height and its offsets
|
|
494
494
|
* @returns The character's width, height and stroke paths as lists of points
|
package/lib/api/services/text.js
CHANGED
|
@@ -2,6 +2,7 @@ import * as Inputs from "../inputs";
|
|
|
2
2
|
import { defaultsVectorParams } from "../models/simplex";
|
|
3
3
|
import { resolveDto } from "../kernel-calls";
|
|
4
4
|
import { pointOnGround } from "./helpers/files/ground-axes";
|
|
5
|
+
import { strokeGlyph } from "./helpers/text/stroke-font";
|
|
5
6
|
/**
|
|
6
7
|
* Working with text: splitting, joining, searching, trimming, padding, changing case, regular
|
|
7
8
|
* expressions and formatting with placeholders. `vectorChar` and `vectorText` turn text into line
|
|
@@ -601,9 +602,9 @@ export class TextBitByBit {
|
|
|
601
602
|
/**
|
|
602
603
|
* Draws one character as line paths with a simple stroke font.
|
|
603
604
|
*
|
|
604
|
-
* The paths lie flat on the XZ plane,
|
|
605
|
-
*
|
|
606
|
-
* mark.
|
|
605
|
+
* The paths lie flat on the XZ plane, the character `height` tall, and come with its width and
|
|
606
|
+
* height. Accented Latin letters are drawn with their marks, other unknown characters as a
|
|
607
|
+
* question mark.
|
|
607
608
|
* Example: 'A' at height 10 -> the strokes of an A, 10 units tall
|
|
608
609
|
* @param inputs - The character, its height and its offsets
|
|
609
610
|
* @returns The character's width, height and stroke paths as lists of points
|
|
@@ -618,30 +619,11 @@ export class TextBitByBit {
|
|
|
618
619
|
vectorChar(inputs) {
|
|
619
620
|
const resolved = resolveDto(Inputs.Text.VectorCharDto, inputs);
|
|
620
621
|
const { xOffset, yOffset, font, input, height, extrudeOffset } = this.vectorParamsChar(resolved);
|
|
621
|
-
|
|
622
|
-
if (!code || !font[code]) {
|
|
623
|
-
code = 63;
|
|
624
|
-
}
|
|
625
|
-
const glyph = [].concat(font[code]);
|
|
622
|
+
const glyph = strokeGlyph(font, input.charCodeAt(0));
|
|
626
623
|
const ratio = (height - extrudeOffset) / font.height;
|
|
627
624
|
const extrudeYOffset = (extrudeOffset / 2);
|
|
628
|
-
const width = glyph.
|
|
629
|
-
const paths = [];
|
|
630
|
-
let polyline = [];
|
|
631
|
-
for (let i = 0, il = glyph.length; i < il; i += 2) {
|
|
632
|
-
const gx = ratio * glyph[i] + xOffset;
|
|
633
|
-
const gy = ratio * glyph[i + 1] + yOffset + extrudeYOffset;
|
|
634
|
-
if (glyph[i] !== undefined) {
|
|
635
|
-
polyline.push(this.onGround(gx, gy));
|
|
636
|
-
continue;
|
|
637
|
-
}
|
|
638
|
-
paths.push(polyline);
|
|
639
|
-
polyline = [];
|
|
640
|
-
i--;
|
|
641
|
-
}
|
|
642
|
-
if (polyline.length) {
|
|
643
|
-
paths.push(polyline);
|
|
644
|
-
}
|
|
625
|
+
const width = glyph.advance * ratio;
|
|
626
|
+
const paths = glyph.strokes.map(stroke => stroke.map(([x, y]) => this.onGround(ratio * x + xOffset, ratio * y + yOffset + extrudeYOffset)));
|
|
645
627
|
return { width, height, paths };
|
|
646
628
|
}
|
|
647
629
|
/**
|