From 4293b844414aabc1cf3ed8f874774094fcb93cb2 Mon Sep 17 00:00:00 2001 From: ShaMan123 Date: Sun, 24 Sep 2023 15:19:15 +0530 Subject: [PATCH] restore test --- src/shapes/Object/Object.spec.ts | 90 ++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/src/shapes/Object/Object.spec.ts b/src/shapes/Object/Object.spec.ts index 72e6c6e3ba0..4175f0e91e2 100644 --- a/src/shapes/Object/Object.spec.ts +++ b/src/shapes/Object/Object.spec.ts @@ -1,5 +1,7 @@ import { Intersection } from '../../Intersection'; import { Point } from '../../Point'; +import { iMatrix } from '../../constants'; +import type { TMat2D } from '../../typedefs'; import { cornerPointContainsPoint } from '../../util/intersection/findCrossPoint'; import { FabricObject } from './Object'; @@ -127,4 +129,92 @@ describe('Object', () => { expect(benchmark2).toBeLessThan(benchmark1); }); + + describe('geometry', () => { + test.each( + ( + [ + [ + {}, + [ + new Point(40, 30), + new Point(52, 30), + new Point(52, 47), + new Point(40, 47), + ], + ], + [ + { angle: 20 }, + [ + new Point(40, 30), + new Point(51.2763114494309, 34.104241719908025), + new Point(45.46196901289453, 50.079016273268465), + new Point(34.18565756346363, 45.97477455336044), + ], + ], + [ + { skewX: 45 }, + [ + new Point(40, 30), + new Point(69, 30), + new Point(69, 47), + new Point(40, 47), + ], + ], + [ + { skewY: 45 }, + [ + new Point(40, 30), + new Point(52, 30), + new Point(52, 59), + new Point(40, 59), + ], + ], + [ + { skewY: 45, skewX: 30, angle: 90 }, + [ + new Point(40, 30), + new Point(40, 58.74315780649914), + new Point(11, 58.74315780649914), + new Point(11, 30), + ], + ], + ] as const + ) + .map( + ([options, expected]) => + [ + [options, undefined, expected], + [options, [2, 0, 0, 2, 35, 35] as TMat2D, expected], + ] as const + ) + .flat() + )( + 'getCoords %p and viewportTransform of %p', + (options, viewportTransform = iMatrix, expected) => { + const object = new FabricObject({ + width: 10, + height: 15, + strokeWidth: 2, + top: 30, + left: 40, + ...options, + }); + jest + .spyOn(object, 'getViewportTransform') + .mockReturnValue(viewportTransform); + + const coords = object.getCoords(); + expect(coords).toEqual(expected); + + object.left += 5; + expect(object.getCoords()).toEqual(coords); + + object.setCoords(); + expect(object.getCoords()).toEqual( + expected.map((point) => point.add(new Point(5, 0))) + ); + } + ); + }); });