@js-draw/math 1.24.1 → 1.24.2

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/dist/cjs/Mat33.js CHANGED
@@ -507,8 +507,8 @@ class Mat33 {
507
507
  },
508
508
  };
509
509
  // A command (\w+)
510
- // followed by a set of arguments ([ \t\n0-9eE.,\-%]+)
511
- const partRegex = /(\w+)\s?\(([^)]*)\)/gi;
510
+ // followed by a set of arguments ([^)]*)
511
+ const partRegex = /(?:^|\W)(\w+)\s?\(([^)]*)\)/gi;
512
512
  let match;
513
513
  let matrix = null;
514
514
  while ((match = partRegex.exec(cssString)) !== null) {
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Rect2 = void 0;
7
7
  const LineSegment2_1 = __importDefault(require("./LineSegment2"));
8
+ const Mat33_1 = __importDefault(require("../Mat33"));
8
9
  const Vec2_1 = require("../Vec2");
9
10
  const Abstract2DShape_1 = __importDefault(require("./Abstract2DShape"));
10
11
  /**
@@ -244,6 +245,10 @@ class Rect2 extends Abstract2DShape_1.default {
244
245
  // [affineTransform] is a transformation matrix that both scales and **translates**.
245
246
  // the bounding box of this' four corners after transformed by the given affine transformation.
246
247
  transformedBoundingBox(affineTransform) {
248
+ // Optimize transforming by the identity matrix (a common case).
249
+ if (affineTransform === Mat33_1.default.identity) {
250
+ return this;
251
+ }
247
252
  return Rect2.bboxOf(this.corners.map((corner) => affineTransform.transformVec2(corner)));
248
253
  }
249
254
  /** @return true iff this is equal to `other ± tolerance` */
@@ -501,8 +501,8 @@ export class Mat33 {
501
501
  },
502
502
  };
503
503
  // A command (\w+)
504
- // followed by a set of arguments ([ \t\n0-9eE.,\-%]+)
505
- const partRegex = /(\w+)\s?\(([^)]*)\)/gi;
504
+ // followed by a set of arguments ([^)]*)
505
+ const partRegex = /(?:^|\W)(\w+)\s?\(([^)]*)\)/gi;
506
506
  let match;
507
507
  let matrix = null;
508
508
  while ((match = partRegex.exec(cssString)) !== null) {
@@ -1,4 +1,5 @@
1
1
  import LineSegment2 from './LineSegment2.mjs';
2
+ import Mat33 from '../Mat33.mjs';
2
3
  import { Vec2 } from '../Vec2.mjs';
3
4
  import Abstract2DShape from './Abstract2DShape.mjs';
4
5
  /**
@@ -238,6 +239,10 @@ export class Rect2 extends Abstract2DShape {
238
239
  // [affineTransform] is a transformation matrix that both scales and **translates**.
239
240
  // the bounding box of this' four corners after transformed by the given affine transformation.
240
241
  transformedBoundingBox(affineTransform) {
242
+ // Optimize transforming by the identity matrix (a common case).
243
+ if (affineTransform === Mat33.identity) {
244
+ return this;
245
+ }
241
246
  return Rect2.bboxOf(this.corners.map((corner) => affineTransform.transformVec2(corner)));
242
247
  }
243
248
  /** @return true iff this is equal to `other ± tolerance` */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@js-draw/math",
3
- "version": "1.24.1",
3
+ "version": "1.24.2",
4
4
  "description": "A math library for js-draw. ",
5
5
  "types": "./dist/mjs/lib.d.ts",
6
6
  "main": "./dist/cjs/lib.js",
@@ -27,7 +27,7 @@
27
27
  "bezier-js": "6.1.3"
28
28
  },
29
29
  "devDependencies": {
30
- "@js-draw/build-tool": "^1.24.1",
30
+ "@js-draw/build-tool": "^1.24.2",
31
31
  "@types/bezier-js": "4.1.0",
32
32
  "@types/jest": "29.5.5",
33
33
  "@types/jsdom": "21.1.3"
@@ -44,5 +44,5 @@
44
44
  "svg",
45
45
  "math"
46
46
  ],
47
- "gitHead": "ef847374748e32d6d96d993a2236a99d9109a32c"
47
+ "gitHead": "32c8db56fc8996c8d485118d1ee37077428344a3"
48
48
  }
package/src/Mat33.ts CHANGED
@@ -610,8 +610,8 @@ export class Mat33 {
610
610
  };
611
611
 
612
612
  // A command (\w+)
613
- // followed by a set of arguments ([ \t\n0-9eE.,\-%]+)
614
- const partRegex = /(\w+)\s?\(([^)]*)\)/gi;
613
+ // followed by a set of arguments ([^)]*)
614
+ const partRegex = /(?:^|\W)(\w+)\s?\(([^)]*)\)/gi;
615
615
  let match;
616
616
  let matrix: Mat33 | null = null;
617
617
 
@@ -114,6 +114,10 @@ describe('Rect2', () => {
114
114
  });
115
115
 
116
116
  it('A transformed bounding box', () => {
117
+ expect(Rect2.unitSquare.transformedBoundingBox(Mat33.scaling2D(2))).objEq(
118
+ new Rect2(0, 0, 2, 2),
119
+ );
120
+
117
121
  const rotationMat = Mat33.zRotation(Math.PI / 4);
118
122
  const rect = Rect2.unitSquare.translatedBy(Vec2.of(-0.5, -0.5));
119
123
  const transformedBBox = rect.transformedBoundingBox(rotationMat);
@@ -310,6 +310,11 @@ export class Rect2 extends Abstract2DShape {
310
310
  // [affineTransform] is a transformation matrix that both scales and **translates**.
311
311
  // the bounding box of this' four corners after transformed by the given affine transformation.
312
312
  public transformedBoundingBox(affineTransform: Mat33): Rect2 {
313
+ // Optimize transforming by the identity matrix (a common case).
314
+ if (affineTransform === Mat33.identity) {
315
+ return this;
316
+ }
317
+
313
318
  return Rect2.bboxOf(this.corners.map((corner) => affineTransform.transformVec2(corner)));
314
319
  }
315
320