@js-draw/math 1.21.2 → 1.22.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/build-config.json +1 -1
  2. package/dist/cjs/Color4.js +2 -2
  3. package/dist/cjs/Mat33.d.ts +1 -11
  4. package/dist/cjs/Mat33.js +8 -24
  5. package/dist/cjs/Vec3.js +9 -7
  6. package/dist/cjs/shapes/BezierJSWrapper.js +20 -13
  7. package/dist/cjs/shapes/LineSegment2.js +13 -17
  8. package/dist/cjs/shapes/Parameterized2DShape.js +1 -1
  9. package/dist/cjs/shapes/Path.js +49 -47
  10. package/dist/cjs/shapes/Rect2.js +13 -15
  11. package/dist/cjs/shapes/Triangle.js +4 -5
  12. package/dist/cjs/utils/convexHull2Of.js +3 -3
  13. package/dist/mjs/Color4.mjs +2 -2
  14. package/dist/mjs/Mat33.d.ts +1 -11
  15. package/dist/mjs/Mat33.mjs +8 -24
  16. package/dist/mjs/Vec3.mjs +9 -7
  17. package/dist/mjs/shapes/BezierJSWrapper.mjs +20 -13
  18. package/dist/mjs/shapes/LineSegment2.mjs +13 -17
  19. package/dist/mjs/shapes/Parameterized2DShape.mjs +1 -1
  20. package/dist/mjs/shapes/Path.mjs +49 -47
  21. package/dist/mjs/shapes/Rect2.mjs +13 -15
  22. package/dist/mjs/shapes/Triangle.mjs +4 -5
  23. package/dist/mjs/utils/convexHull2Of.mjs +3 -3
  24. package/dist-test/test_imports/test-require.cjs +1 -1
  25. package/package.json +3 -3
  26. package/src/Color4.test.ts +16 -21
  27. package/src/Color4.ts +22 -17
  28. package/src/Mat33.fromCSSMatrix.test.ts +31 -45
  29. package/src/Mat33.test.ts +58 -96
  30. package/src/Mat33.ts +61 -104
  31. package/src/Vec2.test.ts +3 -3
  32. package/src/Vec3.test.ts +2 -3
  33. package/src/Vec3.ts +34 -58
  34. package/src/lib.ts +0 -2
  35. package/src/polynomial/solveQuadratic.test.ts +39 -13
  36. package/src/polynomial/solveQuadratic.ts +5 -6
  37. package/src/rounding/cleanUpNumber.test.ts +1 -1
  38. package/src/rounding/constants.ts +1 -3
  39. package/src/rounding/getLenAfterDecimal.ts +1 -2
  40. package/src/rounding/lib.ts +1 -2
  41. package/src/rounding/toRoundedString.test.ts +1 -1
  42. package/src/rounding/toStringOfSamePrecision.test.ts +1 -2
  43. package/src/rounding/toStringOfSamePrecision.ts +1 -1
  44. package/src/shapes/BezierJSWrapper.ts +54 -37
  45. package/src/shapes/CubicBezier.ts +3 -3
  46. package/src/shapes/LineSegment2.test.ts +24 -17
  47. package/src/shapes/LineSegment2.ts +26 -29
  48. package/src/shapes/Parameterized2DShape.ts +5 -4
  49. package/src/shapes/Path.fromString.test.ts +5 -5
  50. package/src/shapes/Path.test.ts +122 -120
  51. package/src/shapes/Path.toString.test.ts +7 -7
  52. package/src/shapes/Path.ts +378 -352
  53. package/src/shapes/PointShape2D.ts +3 -3
  54. package/src/shapes/QuadraticBezier.test.ts +27 -21
  55. package/src/shapes/QuadraticBezier.ts +4 -9
  56. package/src/shapes/Rect2.test.ts +44 -75
  57. package/src/shapes/Rect2.ts +30 -35
  58. package/src/shapes/Triangle.test.ts +31 -29
  59. package/src/shapes/Triangle.ts +17 -18
  60. package/src/utils/convexHull2Of.test.ts +54 -15
  61. package/src/utils/convexHull2Of.ts +9 -7
  62. package/tsconfig.json +1 -3
  63. package/typedoc.json +2 -2
@@ -4,40 +4,79 @@ import convexHull2Of from './convexHull2Of';
4
4
 
5
5
  describe('convexHull2Of', () => {
6
6
  it.each([
7
- [ [ Vec2.of(1, 1) ] , [ Vec2.of(1, 1) ] ],
7
+ [[Vec2.of(1, 1)], [Vec2.of(1, 1)]],
8
8
 
9
9
  // Line
10
- [ [ Vec2.of(1, 1), Vec2.of(2, 2) ] , [ Vec2.of(1, 1), Vec2.of(2, 2) ] ],
10
+ [
11
+ [Vec2.of(1, 1), Vec2.of(2, 2)],
12
+ [Vec2.of(1, 1), Vec2.of(2, 2)],
13
+ ],
11
14
 
12
15
  // Just a triangle
13
- [ [ Vec2.of(1, 1), Vec2.of(4, 2), Vec2.of(3, 3) ] , [ Vec2.of(1, 1), Vec2.of(4, 2), Vec2.of(3, 3) ]],
16
+ [
17
+ [Vec2.of(1, 1), Vec2.of(4, 2), Vec2.of(3, 3)],
18
+ [Vec2.of(1, 1), Vec2.of(4, 2), Vec2.of(3, 3)],
19
+ ],
14
20
 
15
21
  // Triangle with an extra point
16
- [ [ Vec2.of(1, 1), Vec2.of(2, 20), Vec2.of(3, 5), Vec2.of(4, 3) ] , [ Vec2.of(1, 1), Vec2.of(4, 3), Vec2.of(2, 20) ]],
22
+ [
23
+ [Vec2.of(1, 1), Vec2.of(2, 20), Vec2.of(3, 5), Vec2.of(4, 3)],
24
+ [Vec2.of(1, 1), Vec2.of(4, 3), Vec2.of(2, 20)],
25
+ ],
17
26
 
18
27
  // Points within a triangle
19
28
  [
20
- [ Vec2.of(28, 5), Vec2.of(4, 5), Vec2.of(-100, -100), Vec2.of(7, 120), Vec2.of(1, 8), Vec2.of(100, -100), Vec2.of(2, 4), Vec2.of(3, 4), Vec2.of(4, 5) ],
21
- [ Vec2.of(-100, -100), Vec2.of(100, -100), Vec2.of(7, 120) ],
29
+ [
30
+ Vec2.of(28, 5),
31
+ Vec2.of(4, 5),
32
+ Vec2.of(-100, -100),
33
+ Vec2.of(7, 120),
34
+ Vec2.of(1, 8),
35
+ Vec2.of(100, -100),
36
+ Vec2.of(2, 4),
37
+ Vec2.of(3, 4),
38
+ Vec2.of(4, 5),
39
+ ],
40
+ [Vec2.of(-100, -100), Vec2.of(100, -100), Vec2.of(7, 120)],
22
41
  ],
23
42
 
24
43
  // Points within a triangle (repeated vertex)
25
44
  [
26
- [ Vec2.of(28, 5), Vec2.of(4, 5), Vec2.of(-100, -100), Vec2.of(-100, -100), Vec2.of(7, 120), Vec2.of(1, 8), Vec2.of(100, -100), Vec2.of(2, 4), Vec2.of(3, 4), Vec2.of(4, 5) ],
27
- [ Vec2.of(-100, -100), Vec2.of(100, -100), Vec2.of(7, 120) ],
45
+ [
46
+ Vec2.of(28, 5),
47
+ Vec2.of(4, 5),
48
+ Vec2.of(-100, -100),
49
+ Vec2.of(-100, -100),
50
+ Vec2.of(7, 120),
51
+ Vec2.of(1, 8),
52
+ Vec2.of(100, -100),
53
+ Vec2.of(2, 4),
54
+ Vec2.of(3, 4),
55
+ Vec2.of(4, 5),
56
+ ],
57
+ [Vec2.of(-100, -100), Vec2.of(100, -100), Vec2.of(7, 120)],
28
58
  ],
29
59
 
30
60
  // Points within a square
31
61
  [
32
- [ Vec2.of(28, 5), Vec2.of(4, 5), Vec2.of(-100, -100), Vec2.of(100, 100), Vec2.of(7, 100), Vec2.of(1, 8), Vec2.of(-100, 100), Vec2.of(100, -100), Vec2.of(2, 4), Vec2.of(3, 4), Vec2.of(4, 5) ],
33
- [ Vec2.of(-100, -100), Vec2.of(100, -100), Vec2.of(100, 100), Vec2.of(-100, 100) ],
62
+ [
63
+ Vec2.of(28, 5),
64
+ Vec2.of(4, 5),
65
+ Vec2.of(-100, -100),
66
+ Vec2.of(100, 100),
67
+ Vec2.of(7, 100),
68
+ Vec2.of(1, 8),
69
+ Vec2.of(-100, 100),
70
+ Vec2.of(100, -100),
71
+ Vec2.of(2, 4),
72
+ Vec2.of(3, 4),
73
+ Vec2.of(4, 5),
74
+ ],
75
+ [Vec2.of(-100, -100), Vec2.of(100, -100), Vec2.of(100, 100), Vec2.of(-100, 100)],
34
76
  ],
35
77
 
36
- [
37
- Rect2.unitSquare.corners,
38
- [ Vec2.of(1, 0), Vec2.of(1, 1), Vec2.of(0, 1), Vec2.of(0, 0) ],
39
- ]
78
+ [Rect2.unitSquare.corners, [Vec2.of(1, 0), Vec2.of(1, 1), Vec2.of(0, 1), Vec2.of(0, 0)]],
40
79
  ])('should compute the convex hull of a set of points (%j)', (points, expected) => {
41
80
  expect(convexHull2Of(points)).toMatchObject(expected);
42
81
  });
43
- });
82
+ });
@@ -13,11 +13,11 @@ const convexHull2Of = (points: Point2[]) => {
13
13
 
14
14
  // 1. Start with a vertex on the hull
15
15
  const lowestPoint = points.reduce(
16
- (lowest, current) => current.y < lowest.y ? current : lowest,
17
- points[0]
16
+ (lowest, current) => (current.y < lowest.y ? current : lowest),
17
+ points[0],
18
18
  );
19
- const vertices = [ lowestPoint ];
20
- let toProcess = [...points.filter(p => !p.eq(lowestPoint))];
19
+ const vertices = [lowestPoint];
20
+ let toProcess = [...points.filter((p) => !p.eq(lowestPoint))];
21
21
  let lastBaseDirection = Vec2.of(-1, 0);
22
22
 
23
23
  // 2. Find the point with greatest angle from the vertex:
@@ -29,7 +29,9 @@ const convexHull2Of = (points: Point2[]) => {
29
29
  while (toProcess.length > 0) {
30
30
  const lastVertex = vertices[vertices.length - 1];
31
31
 
32
- let smallestDotProductSoFar: number = lastBaseDirection.dot(lowestPoint.minus(lastVertex).normalizedOrZero());
32
+ let smallestDotProductSoFar: number = lastBaseDirection.dot(
33
+ lowestPoint.minus(lastVertex).normalizedOrZero(),
34
+ );
33
35
  let furthestPointSoFar = lowestPoint;
34
36
  for (const point of toProcess) {
35
37
  // Maximizing the angle is the same as minimizing the dot product:
@@ -46,7 +48,7 @@ const convexHull2Of = (points: Point2[]) => {
46
48
  smallestDotProductSoFar = currentDotProduct;
47
49
  }
48
50
  }
49
- toProcess = toProcess.filter(p => !p.eq(furthestPointSoFar));
51
+ toProcess = toProcess.filter((p) => !p.eq(furthestPointSoFar));
50
52
 
51
53
  const newBaseDirection = furthestPointSoFar.minus(lastVertex).normalized();
52
54
 
@@ -68,4 +70,4 @@ const convexHull2Of = (points: Point2[]) => {
68
70
  return vertices;
69
71
  };
70
72
 
71
- export default convexHull2Of;
73
+ export default convexHull2Of;
package/tsconfig.json CHANGED
@@ -1,7 +1,5 @@
1
1
  {
2
2
  "extends": "../../tsconfig.json",
3
3
 
4
- "include": [
5
- "**/*.ts"
6
- ]
4
+ "include": ["**/*.ts"]
7
5
  }
package/typedoc.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "extends": ["../../typedoc.base.json"],
3
3
  "entryPoints": ["./src/lib.ts"],
4
- "readme": "./README.md",
5
- }
4
+ "readme": "./README.md"
5
+ }