@bitbybit-dev/base 1.1.0 → 1.2.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 (63) hide show
  1. package/README.md +14 -4
  2. package/index.js +0 -3
  3. package/lib/api/GlobalCDNProvider.js +1 -1
  4. package/lib/api/inputs/base-inputs.d.ts +114 -0
  5. package/lib/api/inputs/base-inputs.js +15 -0
  6. package/lib/api/inputs/color-inputs.d.ts +4 -0
  7. package/lib/api/inputs/color-inputs.js +4 -0
  8. package/lib/api/inputs/dates-inputs.d.ts +4 -0
  9. package/lib/api/inputs/dates-inputs.js +4 -0
  10. package/lib/api/inputs/io-inputs.d.ts +10 -6
  11. package/lib/api/inputs/io-inputs.js +4 -0
  12. package/lib/api/inputs/line-inputs.d.ts +36 -31
  13. package/lib/api/inputs/line-inputs.js +13 -0
  14. package/lib/api/inputs/lists-inputs.d.ts +28 -20
  15. package/lib/api/inputs/lists-inputs.js +16 -0
  16. package/lib/api/inputs/logic-inputs.d.ts +15 -4
  17. package/lib/api/inputs/logic-inputs.js +65 -0
  18. package/lib/api/inputs/math-inputs.d.ts +25 -0
  19. package/lib/api/inputs/math-inputs.js +40 -0
  20. package/lib/api/inputs/mesh-inputs.d.ts +16 -11
  21. package/lib/api/inputs/mesh-inputs.js +5 -0
  22. package/lib/api/inputs/point-inputs.d.ts +33 -27
  23. package/lib/api/inputs/point-inputs.js +14 -0
  24. package/lib/api/inputs/polyline-inputs.d.ts +33 -28
  25. package/lib/api/inputs/polyline-inputs.js +5 -0
  26. package/lib/api/inputs/text-inputs.d.ts +27 -14
  27. package/lib/api/inputs/text-inputs.js +13 -0
  28. package/lib/api/inputs/transforms-inputs.d.ts +9 -3
  29. package/lib/api/inputs/transforms-inputs.js +6 -0
  30. package/lib/api/inputs/vector-inputs.d.ts +5 -0
  31. package/lib/api/inputs/vector-inputs.js +69 -0
  32. package/lib/api/models/point/hex-grid-data.d.ts +8 -3
  33. package/lib/api/models/point/hex-grid-data.js +5 -0
  34. package/lib/api/models/simplex.d.ts +19 -250
  35. package/lib/api/models/simplex.js +7 -35
  36. package/lib/api/models/text/vector-char-data.d.ts +3 -3
  37. package/lib/api/models/text/vector-text-data.d.ts +3 -3
  38. package/lib/api/services/color.js +5 -4
  39. package/lib/api/services/geometry-helper.d.ts +5 -5
  40. package/lib/api/services/geometry-helper.js +101 -2
  41. package/lib/api/services/helpers/dxf/dxf-generator.js +20 -69
  42. package/lib/api/services/helpers/mesh-normals.d.ts +9 -0
  43. package/lib/api/services/helpers/mesh-normals.js +56 -0
  44. package/lib/api/services/io.d.ts +4 -0
  45. package/lib/api/services/io.js +4 -0
  46. package/lib/api/services/line.d.ts +2 -2
  47. package/lib/api/services/line.js +18 -51
  48. package/lib/api/services/lists.js +1 -6
  49. package/lib/api/services/mesh.d.ts +2 -1
  50. package/lib/api/services/mesh.js +14 -32
  51. package/lib/api/services/point.d.ts +3 -3
  52. package/lib/api/services/point.js +26 -82
  53. package/lib/api/services/polyline.d.ts +2 -2
  54. package/lib/api/services/polyline.js +13 -43
  55. package/lib/api/services/text.js +1 -9
  56. package/lib/api/services/transforms.js +10 -16
  57. package/lib/api/services/vector.d.ts +4 -4
  58. package/lib/api/services/vector.js +3 -3
  59. package/package.json +53 -91
  60. package/babel.config.cjs +0 -14
  61. package/babel.config.d.cts +0 -5
  62. package/lib/api/unit-test-helper.d.ts +0 -20
  63. package/lib/api/unit-test-helper.js +0 -130
@@ -4,8 +4,8 @@ import { Point } from "./point";
4
4
  import { Vector } from "./vector";
5
5
  import { Line } from "./line";
6
6
  /**
7
- * Contains various methods for polyline. Polyline in bitbybit is a simple object that has points property containing an array of points.
8
- * { points: number[][] }
7
+ * Contains various methods for polyline. Polyline in bitbybit is a simple object that has points property
8
+ * containing an array of points. { points: number[][] }
9
9
  */
10
10
  export declare class Polyline {
11
11
  private readonly vector;
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Contains various methods for polyline. Polyline in bitbybit is a simple object that has points property containing an array of points.
3
- * { points: number[][] }
2
+ * Contains various methods for polyline. Polyline in bitbybit is a simple object that has points property
3
+ * containing an array of points. { points: number[][] }
4
4
  */
5
5
  export class Polyline {
6
6
  constructor(vector, point, line, geometryHelper) {
@@ -129,11 +129,9 @@ export class Polyline {
129
129
  if (numPoints < 2) {
130
130
  return segments;
131
131
  }
132
- // Create segments between consecutive points
133
132
  for (let i = 0; i < numPoints - 1; i++) {
134
133
  segments.push([points[i], points[i + 1]]);
135
134
  }
136
- // Add closing segment if the polyline is closed and has enough points
137
135
  if (polyline.isClosed && numPoints >= 2) {
138
136
  if (!this.point.twoPointsAlmostEqual({ point1: points[numPoints - 1], point2: points[0], tolerance: 1e-9 })) {
139
137
  segments.push([points[numPoints - 1], points[0]]);
@@ -251,7 +249,7 @@ export class Polyline {
251
249
  */
252
250
  sortSegmentsIntoPolylines(inputs) {
253
251
  var _a;
254
- const tolerance = (_a = inputs.tolerance) !== null && _a !== void 0 ? _a : 1e-5; // Default tolerance
252
+ const tolerance = (_a = inputs.tolerance) !== null && _a !== void 0 ? _a : 1e-5;
255
253
  const segments = inputs.segments;
256
254
  if (!segments || segments.length === 0) {
257
255
  return [];
@@ -268,11 +266,10 @@ export class Polyline {
268
266
  const iz = Math.round(p[2] * invTolerance);
269
267
  return `${ix},${iy},${iz}`;
270
268
  };
271
- // 1. Build the spatial map
272
269
  for (let i = 0; i < numSegments; i++) {
273
270
  const segment = segments[i];
274
271
  if (this.point.twoPointsAlmostEqual({ point1: segment[0], point2: segment[1], tolerance: tolerance })) {
275
- used[i] = true; // Mark degenerate as used
272
+ used[i] = true;
276
273
  continue;
277
274
  }
278
275
  const key0 = getGridKey(segment[0]);
@@ -281,20 +278,16 @@ export class Polyline {
281
278
  const info1 = { segmentIndex: i, endpointIndex: 1, coords: segment[1] };
282
279
  if (!endpointMap.has(key0))
283
280
  endpointMap.set(key0, []);
284
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
285
281
  endpointMap.get(key0).push(info0);
286
282
  if (key1 !== key0) {
287
283
  if (!endpointMap.has(key1))
288
284
  endpointMap.set(key1, []);
289
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
290
285
  endpointMap.get(key1).push(info1);
291
286
  }
292
287
  else {
293
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
294
- endpointMap.get(key0).push(info1); // Add both endpoints if same key
288
+ endpointMap.get(key0).push(info1);
295
289
  }
296
290
  }
297
- // --- Helper to find connecting segment ---
298
291
  const findConnection = (pointToMatch) => {
299
292
  const searchKeys = [];
300
293
  const px = Math.round(pointToMatch[0] * invTolerance);
@@ -314,93 +307,74 @@ export class Polyline {
314
307
  if (!candidates)
315
308
  continue;
316
309
  for (const candidate of candidates) {
317
- // Only consider segments not already used in *any* polyline
318
310
  if (!used[candidate.segmentIndex]) {
319
311
  const diffVector = this.vector.sub({ first: candidate.coords, second: pointToMatch });
320
312
  const distSq = this.vector.lengthSq({ vector: diffVector });
321
313
  if (distSq < minDistanceSq) {
322
- // Check with precise method if it's a potential best match
323
314
  if (this.point.twoPointsAlmostEqual({ point1: candidate.coords, point2: pointToMatch, tolerance: tolerance })) {
324
315
  bestMatch = candidate;
325
- minDistanceSq = distSq; // Update min distance found
316
+ minDistanceSq = distSq;
326
317
  }
327
318
  }
328
319
  }
329
320
  }
330
321
  }
331
- // No need for final check here, already done inside the loop
332
- if (bestMatch && !used[bestMatch.segmentIndex]) { // Double check used status
322
+ if (bestMatch && !used[bestMatch.segmentIndex]) {
333
323
  return bestMatch;
334
324
  }
335
325
  return undefined;
336
326
  };
337
- // 2. Iterate and chain segments
338
327
  for (let i = 0; i < numSegments; i++) {
339
328
  if (used[i])
340
- continue; // Skip if already part of a polyline
341
- // Start a new polyline
342
- used[i] = true; // Mark the starting segment as used
329
+ continue;
330
+ used[i] = true;
343
331
  const startSegment = segments[i];
344
332
  const currentPoints = [startSegment[0], startSegment[1]];
345
333
  let currentHead = startSegment[0];
346
334
  let currentTail = startSegment[1];
347
335
  let isClosed = false;
348
336
  let iterations = 0;
349
- // Extend forward (tail)
350
337
  while (iterations++ < numSegments) {
351
338
  const nextMatch = findConnection(currentTail);
352
339
  if (!nextMatch)
353
- break; // No unused segment connects to the tail
354
- // We found a potential next segment
340
+ break;
355
341
  const nextSegment = segments[nextMatch.segmentIndex];
356
342
  const pointToAdd = (nextMatch.endpointIndex === 0) ? nextSegment[1] : nextSegment[0];
357
- // Check for closure *before* adding the point
358
343
  if (this.point.twoPointsAlmostEqual({ point1: pointToAdd, point2: currentHead, tolerance: tolerance })) {
359
344
  isClosed = true;
360
- // Mark the closing segment as used
361
345
  used[nextMatch.segmentIndex] = true;
362
- break; // Closed loop found
346
+ break;
363
347
  }
364
- // Not closing, so add the point and mark the segment used
365
348
  used[nextMatch.segmentIndex] = true;
366
349
  currentPoints.push(pointToAdd);
367
350
  currentTail = pointToAdd;
368
351
  }
369
- // Extend backward (head) - only if not already closed
370
352
  iterations = 0;
371
353
  if (!isClosed) {
372
354
  while (iterations++ < numSegments) {
373
355
  const prevMatch = findConnection(currentHead);
374
356
  if (!prevMatch)
375
- break; // No unused segment connects to the head
357
+ break;
376
358
  const prevSegment = segments[prevMatch.segmentIndex];
377
359
  const pointToAdd = (prevMatch.endpointIndex === 0) ? prevSegment[1] : prevSegment[0];
378
- // Check for closure against the current tail *before* adding
379
360
  if (this.point.twoPointsAlmostEqual({ point1: pointToAdd, point2: currentTail, tolerance: tolerance })) {
380
361
  isClosed = true;
381
- // Mark the closing segment as used
382
362
  used[prevMatch.segmentIndex] = true;
383
- break; // Closed loop found
363
+ break;
384
364
  }
385
- // Not closing, add point to beginning and mark segment used
386
365
  used[prevMatch.segmentIndex] = true;
387
366
  currentPoints.unshift(pointToAdd);
388
367
  currentHead = pointToAdd;
389
368
  }
390
369
  }
391
- // Final closure check (might be redundant now, but harmless)
392
- // This catches cases like A->B, B->A which form a 2-point closed loop
393
370
  if (!isClosed && currentPoints.length >= 2) {
394
371
  isClosed = this.point.twoPointsAlmostEqual({ point1: currentHead, point2: currentTail, tolerance: tolerance });
395
372
  }
396
- // Remove duplicate point for closed loops with more than 2 points
397
373
  if (isClosed && currentPoints.length > 2) {
398
- // Check if the first and last points are indeed the ones needing merging
399
374
  if (this.point.twoPointsAlmostEqual({ point1: currentPoints[currentPoints.length - 1], point2: currentPoints[0], tolerance: tolerance })) {
400
375
  currentPoints.pop();
401
376
  }
402
377
  }
403
- // Add the completed polyline (even if it's just the starting segment)
404
378
  results.push({
405
379
  points: currentPoints,
406
380
  isClosed: isClosed,
@@ -450,13 +424,9 @@ export class Polyline {
450
424
  safestFilletRadius(inputs) {
451
425
  const allMaxRadii = this.maxFilletsHalfLine(inputs);
452
426
  if (allMaxRadii.length === 0) {
453
- // No corners, or fewer than 3 points. No fillet possible.
454
427
  return 0;
455
428
  }
456
- // Find the minimum radius among all calculated maximums.
457
- // If any corner calculation resulted in 0, the safest radius is 0.
458
429
  const safestRadius = Math.min(...allMaxRadii);
459
- // Ensure we don't return a negative radius if Math.min had weird input (shouldn't happen here)
460
430
  return Math.max(0, safestRadius);
461
431
  }
462
432
  }
@@ -478,10 +478,8 @@ export class TextBitByBit {
478
478
  const text = inputs.text;
479
479
  if (typeof text !== "string")
480
480
  throw new Error("text must be a string");
481
- // NOTE: Just like CSS letter-spacing, the spacing could be positive or negative
482
481
  const extraLetterSpacing = (height * letterSpacing);
483
- // manage the list of lines
484
- let maxWidth = 0; // keep track of max width for final alignment
482
+ let maxWidth = 0;
485
483
  let line = { width: 0, height: 0, chars: [] };
486
484
  let lines = [];
487
485
  const pushLine = () => {
@@ -490,7 +488,6 @@ export class TextBitByBit {
490
488
  lines.push(line);
491
489
  line = { width: 0, height: 0, chars: [] };
492
490
  };
493
- // convert the text into a list of vector lines
494
491
  let x = xOffset;
495
492
  let y = yOffset;
496
493
  let vchar;
@@ -499,16 +496,13 @@ export class TextBitByBit {
499
496
  const character = text[i];
500
497
  if (character === "\n") {
501
498
  pushLine();
502
- // reset x and y for a new line
503
499
  x = xOffset;
504
500
  y -= height * lineSpacing;
505
501
  continue;
506
502
  }
507
- // convert the character
508
503
  vchar = this.vectorChar({ xOffset: x, yOffset: y, height, extrudeOffset, char: character });
509
504
  const width = vchar.width + extraLetterSpacing;
510
505
  x += width;
511
- // update current line
512
506
  line.width += width;
513
507
  line.height = Math.max(line.height, vchar.height);
514
508
  if (character !== " ") {
@@ -517,7 +511,6 @@ export class TextBitByBit {
517
511
  }
518
512
  if (line.chars.length)
519
513
  pushLine();
520
- // align all lines as requested
521
514
  lines = lines.map((line) => {
522
515
  const diff = maxWidth - line.width;
523
516
  if (align === Inputs.Base.horizontalAlignEnum.right) {
@@ -532,7 +525,6 @@ export class TextBitByBit {
532
525
  });
533
526
  if (inputs.centerOnOrigin) {
534
527
  const pointsFlat = [];
535
- // flatten the lines into a single array of points
536
528
  lines.forEach((line) => {
537
529
  line.chars.forEach((vchar) => {
538
530
  vchar.paths.forEach((path) => {
@@ -129,10 +129,11 @@ export class Transforms {
129
129
  * @drawable false
130
130
  */
131
131
  stretchDirFromCenter(inputs) {
132
+ const { center = [0, 0, 0], direction = [0, 0, 1], scale = 2 } = inputs;
132
133
  return [
133
- this.translation(-inputs.center[0], -inputs.center[1], -inputs.center[2]),
134
- this.stretchDirection(inputs.direction, inputs.scale),
135
- this.translation(inputs.center[0], inputs.center[1], inputs.center[2]),
134
+ this.translation(-center[0], -center[1], -center[2]),
135
+ this.stretchDirection(direction, scale),
136
+ this.translation(center[0], center[1], center[2]),
136
137
  ];
137
138
  }
138
139
  /**
@@ -299,34 +300,27 @@ export class Transforms {
299
300
  */
300
301
  stretchDirection(direction, scale) {
301
302
  const d = this.vector.normalized({ vector: direction });
302
- const [dx, dy, dz] = d;
303
- // Handle potential zero vector after normalization (if input was zero)
304
- if (isNaN(dx) || (dx === 0 && dy === 0 && dz === 0)) {
303
+ if (!d || isNaN(d[0]) || (d[0] === 0 && d[1] === 0 && d[2] === 0)) {
305
304
  console.warn("Stretch direction vector is zero or invalid. Returning identity matrix.");
306
305
  return this.identity();
307
306
  }
307
+ const [dx, dy, dz] = d;
308
308
  const s = scale;
309
309
  const sMinus1 = s - 1.0;
310
- // Calculate elements of the 3x3 directional scaling part
311
310
  const m11 = 1.0 + sMinus1 * dx * dx;
312
311
  const m12 = sMinus1 * dx * dy;
313
312
  const m13 = sMinus1 * dx * dz;
314
- // m14 = 0
315
313
  const m21 = sMinus1 * dy * dx;
316
314
  const m22 = 1.0 + sMinus1 * dy * dy;
317
315
  const m23 = sMinus1 * dy * dz;
318
- // m24 = 0
319
316
  const m31 = sMinus1 * dz * dx;
320
317
  const m32 = sMinus1 * dz * dy;
321
318
  const m33 = 1.0 + sMinus1 * dz * dz;
322
- // m34 = 0
323
- // m41, m42, m43 = 0, m44 = 1
324
- // Assemble the 4x4 matrix in COLUMN-MAJOR order
325
319
  const m = [
326
- m11, m21, m31, 0.0, // Column 1
327
- m12, m22, m32, 0.0, // Column 2
328
- m13, m23, m33, 0.0, // Column 3
329
- 0.0, 0.0, 0.0, 1.0 // Column 4
320
+ m11, m21, m31, 0.0,
321
+ m12, m22, m32, 0.0,
322
+ m13, m23, m33, 0.0,
323
+ 0.0, 0.0, 0.0, 1.0
330
324
  ];
331
325
  return m;
332
326
  }
@@ -2,9 +2,9 @@ import * as Inputs from "../inputs";
2
2
  import { GeometryHelper } from "./geometry-helper";
3
3
  import { MathBitByBit } from "./math";
4
4
  /**
5
- * Contains various methods for vector mathematics. Vector in bitbybit is simply an array, usually containing numbers.
6
- * In 3D [x, y, z] form describes space, where y is the up vector.
7
- * Because of this form Vector can be interchanged with Point, which also is an array in [x, y, z] form.
5
+ * Contains various methods for vector mathematics. Vector in bitbybit is simply an array, usually
6
+ * containing numbers. In 3D [x, y, z] form describes space, where y is the up vector. Because of this form
7
+ * Vector can be interchanged with Point, which also is an array in [x, y, z] form.
8
8
  */
9
9
  export declare class Vector {
10
10
  private readonly math;
@@ -260,7 +260,7 @@ export declare class Vector {
260
260
  * @shortname normalized
261
261
  * @drawable false
262
262
  */
263
- normalized(inputs: Inputs.Vector.VectorDto): number[];
263
+ normalized(inputs: Inputs.Vector.VectorDto): number[] | undefined;
264
264
  /**
265
265
  * Finds a point on a ray at a given distance from the origin along the direction vector.
266
266
  * Example: Point [0,0,0] + direction [1,0,0] at distance 5 → [5,0,0]
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Contains various methods for vector mathematics. Vector in bitbybit is simply an array, usually containing numbers.
3
- * In 3D [x, y, z] form describes space, where y is the up vector.
4
- * Because of this form Vector can be interchanged with Point, which also is an array in [x, y, z] form.
2
+ * Contains various methods for vector mathematics. Vector in bitbybit is simply an array, usually
3
+ * containing numbers. In 3D [x, y, z] form describes space, where y is the up vector. Because of this form
4
+ * Vector can be interchanged with Point, which also is an array in [x, y, z] form.
5
5
  */
6
6
  export class Vector {
7
7
  constructor(math, geometryHelper) {
package/package.json CHANGED
@@ -1,95 +1,57 @@
1
1
  {
2
- "name": "@bitbybit-dev/base",
3
- "version": "1.1.0",
4
- "description": "Bit By Bit Developers Base CAD Library to Program Geometry",
5
- "main": "index.js",
6
- "repository": {
7
- "type": "git",
8
- "url": "https://github.com/bitbybit-dev/bitbybit"
9
- },
10
- "keywords": [
11
- "Bit By Bit Developers",
12
- "bitbybit",
13
- "bitbybit.dev",
14
- "Geometry",
15
- "CAD",
16
- "3D",
17
- "JSCAD",
18
- "OCCT",
19
- "OpenCascade",
20
- "Creative coding",
21
- "CSG",
22
- "Mesh",
23
- "Meshing",
24
- "Manifold",
25
- "Manifold-3D",
26
- "WebGL",
27
- "WebGPU",
28
- "Parametric",
29
- "Modeling",
30
- "Browser CAD",
31
- "3D algorithms",
32
- "3D modeling",
33
- "3D printing",
34
- "3D printing algorithms",
35
- "3D software",
36
- "OpenCascade Technology",
37
- "AEC",
38
- "Automotive",
39
- "Engineering",
40
- "CAE",
41
- "CAM"
42
- ],
43
- "directories": {
44
- "lib": "lib"
45
- },
46
- "scripts": {
47
- "build": "tsc -p tsconfig.bitbybit.json",
48
- "build-p": "npm run build && npm run copy-package && npm run copy-readme && npm run delete-coverage",
49
- "copy-package": "shx cp -R ./package.json ./dist",
50
- "copy-readme": "shx cp -R ./README.md ./dist && shx cp -R ./LICENSE ./dist",
51
- "delete-coverage": "shx rm -rf ./dist/coverage || true",
52
- "test": "set NODE_OPTIONS=--experimental-specifier-resolution=node && jest --watchAll=true",
53
- "test-c": "set NODE_OPTIONS=--experimental-specifier-resolution=node && jest --coverage --watchAll=false",
54
- "test-c-l": "set NODE_OPTIONS=--experimental-specifier-resolution=node && jest --coverage --watchAll=true"
55
- },
56
- "author": "Bit by bit developers",
57
- "license": "MIT",
58
- "funding": {
59
- "type": "corporate",
60
- "url": "https://bitbybit.dev/auth/pick-plan"
61
- },
62
- "types": "./index.d.ts",
63
- "type": "module",
64
- "dependencies": {},
65
- "devDependencies": {
66
- "shx":"0.4.0",
67
- "@testing-library/jest-dom": "6.9.1",
68
- "mvdir": "1.0.22",
69
- "jest": "30.4.2",
70
- "ts-node": "10.9.2",
71
- "ts-jest": "29.4.10",
72
- "typescript": "5.9.3",
73
- "@types/jest": "30.0.0",
74
- "babel-jest": "30.4.1",
75
- "@babel/core": "7.29.0",
76
- "@babel/preset-env": "7.29.5",
77
- "@babel/preset-typescript": "7.28.5",
78
- "jest-html-reporters": "3.1.7"
79
- },
80
- "jest": {
81
- "preset": "ts-jest",
82
- "transform": {
83
- "\\.[jt]sx?$": "babel-jest"
2
+ "name": "@bitbybit-dev/base",
3
+ "version": "1.2.0-rc.0",
4
+ "description": "Bit By Bit Developers Base CAD Library to Program Geometry",
5
+ "homepage": "https://docs.bitbybit.dev/modules/Bit",
6
+ "main": "index.js",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/bitbybit-dev/bitbybit.git",
10
+ "directory": "packages/dev/base"
84
11
  },
85
- "extensionsToTreatAsEsm": [
86
- ".ts"
12
+ "keywords": [
13
+ "Bit By Bit Developers",
14
+ "bitbybit",
15
+ "bitbybit.dev",
16
+ "Geometry",
17
+ "CAD",
18
+ "3D",
19
+ "JSCAD",
20
+ "OCCT",
21
+ "OpenCascade",
22
+ "Creative coding",
23
+ "CSG",
24
+ "Mesh",
25
+ "Meshing",
26
+ "Manifold",
27
+ "Manifold-3D",
28
+ "WebGL",
29
+ "WebGPU",
30
+ "Parametric",
31
+ "Modeling",
32
+ "Browser CAD",
33
+ "3D algorithms",
34
+ "3D modeling",
35
+ "3D printing",
36
+ "3D printing algorithms",
37
+ "3D software",
38
+ "OpenCascade Technology",
39
+ "AEC",
40
+ "Automotive",
41
+ "Engineering",
42
+ "CAE",
43
+ "CAM"
87
44
  ],
88
- "transformIgnorePatterns": [
89
- "node_modules/(?!@bitbybit-dev)/"
90
- ],
91
- "collectCoverageFrom": [
92
- "lib/api/services/**/*"
93
- ]
94
- }
45
+ "directories": {
46
+ "lib": "lib"
47
+ },
48
+ "author": "Bit by bit developers",
49
+ "license": "MIT",
50
+ "funding": {
51
+ "type": "corporate",
52
+ "url": "https://bitbybit.dev/auth/pick-plan"
53
+ },
54
+ "types": "./index.d.ts",
55
+ "type": "module",
56
+ "dependencies": {}
95
57
  }
package/babel.config.cjs DELETED
@@ -1,14 +0,0 @@
1
- "use strict";
2
- module.exports = {
3
- presets: [
4
- [
5
- '@babel/preset-env',
6
- {
7
- targets: {
8
- node: 'current',
9
- },
10
- },
11
- ],
12
- '@babel/preset-typescript'
13
- ],
14
- };
@@ -1,5 +0,0 @@
1
- export let presets: (string | (string | {
2
- targets: {
3
- node: string;
4
- };
5
- })[])[];
@@ -1,20 +0,0 @@
1
- import * as Inputs from "./inputs";
2
- import { Vector } from "./services";
3
- export declare const TOLERANCE = 1e-7;
4
- export declare class UnitTestHelper {
5
- vector: Vector;
6
- constructor();
7
- expectPointCloseTo(received: Inputs.Base.Point3 | Inputs.Base.Vector3 | undefined, expected: Inputs.Base.Point3 | Inputs.Base.Vector3): void;
8
- expectPointsCloseTo(received: Inputs.Base.Point3[] | Inputs.Base.Vector3[], expected: Inputs.Base.Point3[] | Inputs.Base.Vector3[]): void;
9
- expectLineCloseTo(received: Inputs.Base.Line3 | undefined, expected: Inputs.Base.Line3): void;
10
- expectLinesCloseTo(received: Inputs.Base.Line3[], expected: Inputs.Base.Line3[]): void;
11
- expectSegmentCloseTo(received: Inputs.Base.Segment3 | undefined, expected: Inputs.Base.Segment3, precision?: number): void;
12
- expectPlaneCloseTo(received: Inputs.Base.TrianglePlane3 | undefined, expected: Inputs.Base.TrianglePlane3, precision?: number): void;
13
- expectMatrixCloseTo(received: Inputs.Base.TransformMatrix | undefined, expected: Inputs.Base.TransformMatrix): void;
14
- expectMatrixesCloseTo(received: Inputs.Base.TransformMatrixes | undefined, expected: Inputs.Base.TransformMatrixes): void;
15
- /** Helper to compare two arrays of points for near-equality, ignoring order */
16
- expectPointArraysCloseTo(actual: Inputs.Base.Point3[] | undefined, expected: Inputs.Base.Point3[], tolerance?: number): void;
17
- sortPoints(points: Inputs.Base.Point3[]): Inputs.Base.Point3[];
18
- sortPolylinesForComparison(polylines: Inputs.Base.Polyline3[]): Inputs.Base.Polyline3[];
19
- expectFloatArraysClose(actual: number[], expected: number[], precision: number): void;
20
- }
@@ -1,130 +0,0 @@
1
- import { GeometryHelper, MathBitByBit, Vector } from "./services";
2
- export const TOLERANCE = 1e-7;
3
- export class UnitTestHelper {
4
- constructor() {
5
- const math = new MathBitByBit();
6
- const geometryHelper = new GeometryHelper();
7
- this.vector = new Vector(math, geometryHelper);
8
- }
9
- expectPointCloseTo(received, expected) {
10
- expect(received).toBeDefined();
11
- if (!received)
12
- return;
13
- expect(received.length).toEqual(expected.length);
14
- expect(received[0]).toBeCloseTo(expected[0], TOLERANCE);
15
- expect(received[1]).toBeCloseTo(expected[1], TOLERANCE);
16
- if (expected.length > 2 && received.length > 2) {
17
- expect(received[2]).toBeCloseTo(expected[2], TOLERANCE);
18
- }
19
- }
20
- expectPointsCloseTo(received, expected) {
21
- expect(received.length).toEqual(expected.length);
22
- received.forEach((p, i) => this.expectPointCloseTo(p, expected[i]));
23
- }
24
- expectLineCloseTo(received, expected) {
25
- expect(received).toBeDefined();
26
- if (!received)
27
- return;
28
- this.expectPointCloseTo(received.start, expected.start);
29
- this.expectPointCloseTo(received.end, expected.end);
30
- }
31
- expectLinesCloseTo(received, expected) {
32
- expect(received.length).toEqual(expected.length);
33
- received.forEach((l, i) => this.expectLineCloseTo(l, expected[i]));
34
- }
35
- expectSegmentCloseTo(received, expected, precision = TOLERANCE) {
36
- expect(received).toBeDefined();
37
- if (!received)
38
- return;
39
- expect(received).toHaveLength(2);
40
- const order1Matches = Math.abs(this.vector.dist({ first: received[0], second: expected[0] })) < precision &&
41
- Math.abs(this.vector.dist({ first: received[1], second: expected[1] })) < precision;
42
- const order2Matches = Math.abs(this.vector.dist({ first: received[0], second: expected[1] })) < precision &&
43
- Math.abs(this.vector.dist({ first: received[1], second: expected[0] })) < precision;
44
- expect(order1Matches || order2Matches).toBe(true);
45
- }
46
- expectPlaneCloseTo(received, expected, precision = TOLERANCE) {
47
- expect(received).toBeDefined();
48
- if (!received)
49
- return;
50
- const normalDir1 = this.vector.sub({ first: received.normal, second: expected.normal });
51
- const normalDir2 = this.vector.add({ first: received.normal, second: expected.normal });
52
- const dir1Match = this.vector.lengthSq({ vector: normalDir1 }) < precision * precision;
53
- const dir2Match = this.vector.lengthSq({ vector: normalDir2 }) < precision * precision;
54
- expect(dir1Match || dir2Match).toBe(true);
55
- expect(received.d).toBeCloseTo(dir1Match ? expected.d : -expected.d, precision);
56
- }
57
- expectMatrixCloseTo(received, expected) {
58
- expect(received).toBeDefined();
59
- if (!received)
60
- return;
61
- expect(received).toHaveLength(16);
62
- expect(expected).toHaveLength(16);
63
- for (let i = 0; i < 16; i++) {
64
- expect(received[i]).toBeCloseTo(expected[i], TOLERANCE);
65
- }
66
- }
67
- expectMatrixesCloseTo(received, expected) {
68
- expect(received).toBeDefined();
69
- if (!received)
70
- return;
71
- expect(received.length).toEqual(expected.length);
72
- received.forEach((matrix, i) => this.expectMatrixCloseTo(matrix, expected[i]));
73
- }
74
- /** Helper to compare two arrays of points for near-equality, ignoring order */
75
- expectPointArraysCloseTo(actual, expected, tolerance = 1e-6) {
76
- // Use expectPointsClose helper for individual point comparison if needed
77
- const expectPointsClose = (act, exp, tol = 1e-6) => {
78
- const precision = Math.max(0, Math.ceil(-Math.log10(tol)) - 1);
79
- if (exp === undefined) {
80
- expect(act).toBeUndefined();
81
- }
82
- else {
83
- expect(act).toBeDefined();
84
- if (act) {
85
- expect(act[0]).toBeCloseTo(exp[0], precision);
86
- expect(act[1]).toBeCloseTo(exp[1], precision);
87
- expect(act[2]).toBeCloseTo(exp[2], precision);
88
- }
89
- }
90
- };
91
- expect(actual).toBeDefined();
92
- // Proceed only if actual is defined
93
- if (actual) {
94
- expect(actual.length).toEqual(expected.length);
95
- // Sort both arrays to compare independent of order
96
- const sortedActual = this.sortPoints(actual);
97
- const sortedExpected = this.sortPoints(expected);
98
- for (let i = 0; i < sortedExpected.length; i++) {
99
- expectPointsClose(sortedActual[i], sortedExpected[i], tolerance);
100
- }
101
- }
102
- }
103
- sortPoints(points) {
104
- return [...points].sort((a, b) => {
105
- if (a[0] !== b[0])
106
- return a[0] - b[0];
107
- if (a[1] !== b[1])
108
- return a[1] - b[1];
109
- return a[2] - b[2];
110
- });
111
- }
112
- sortPolylinesForComparison(polylines) {
113
- return polylines.sort((a, b) => {
114
- const pA = a.points[0];
115
- const pB = b.points[0];
116
- if (pA[0] !== pB[0])
117
- return pA[0] - pB[0];
118
- if (pA[1] !== pB[1])
119
- return pA[1] - pB[1];
120
- return pA[2] - pB[2];
121
- });
122
- }
123
- expectFloatArraysClose(actual, expected, precision) {
124
- expect(actual.length).toBe(expected.length);
125
- actual.forEach((val, index) => {
126
- expect(val).toBeCloseTo(expected[index], precision);
127
- });
128
- }
129
- ;
130
- }