-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(): expose sendVectorToPlane
#9479
Conversation
Build Stats
|
…c.js into sendVectorToPlane
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is also a v6 PR but can be merged after 6.0
describe('Plane Change', () => { | ||
test('calcPlaneChangeMatrix', () => { | ||
const m1: TMat2D = [1, 2, 3, 4, 5, 6]; | ||
const s: TMat2D = [2, 0, 0, 0.5, 0, 0]; | ||
expect(calcPlaneChangeMatrix()).toEqual(iMatrix); | ||
expect(calcPlaneChangeMatrix(undefined, m1)).toEqual(invertTransform(m1)); | ||
expect(calcPlaneChangeMatrix(iMatrix, m1)).toEqual(invertTransform(m1)); | ||
expect(calcPlaneChangeMatrix(m1, undefined)).toEqual(m1); | ||
expect(calcPlaneChangeMatrix(m1, iMatrix)).toEqual(m1); | ||
expect(calcPlaneChangeMatrix(m1, m1)).toEqual(iMatrix); | ||
expect(calcPlaneChangeMatrix(m1, s)).toEqual( | ||
multiplyTransformMatrices(invertTransform(s), m1) | ||
); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
migrate from qunit
test('sendPointToPlane', () => { | ||
const s: TMat2D = [2, 0, 0, 0.5, 50, 50]; | ||
const point = new Point(1, 1); | ||
expect(sendPointToPlane(point, s)).toEqual({ x: 52, y: 50.5 }); | ||
expect(sendPointToPlane(point, undefined, s)).toEqual({ x: -24.5, y: -98 }); | ||
expect( | ||
sendPointToPlane(point, createRotateMatrix({ angle: 90 }), s) | ||
).toEqual({ x: -25.5, y: -98 }); | ||
expect(sendPointToPlane(point, s, s)).toEqual(point); | ||
expect(sendPointToPlane(point)).toEqual(point); | ||
}); | ||
|
||
test('sendVectorToPlane', () => { | ||
const s: TMat2D = [2, 0, 0, 0.5, 50, 50]; | ||
const point = new Point(1, 1); | ||
expect(sendVectorToPlane(point, s)).toEqual({ x: 2, y: 0.5 }); | ||
expect(sendVectorToPlane(point, undefined, s)).toEqual({ x: 0.5, y: 2 }); | ||
expect( | ||
sendVectorToPlane(point, createRotateMatrix({ angle: 90 }), s) | ||
).toEqual({ x: -0.5, y: 2 }); | ||
expect(sendVectorToPlane(point, s, s)).toEqual(point); | ||
expect(sendVectorToPlane(point)).toEqual(point); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new test
test('sendObjectToPlane', () => { | ||
const m: TMat2D = [6, Math.SQRT1_2, 0, 3, 2, 1]; | ||
const m1: TMat2D = [3, 0, 0, 2, 10, 4]; | ||
const m2: TMat2D = [1, Math.SQRT1_2, Math.SQRT1_2, 4, 5, 6]; | ||
const group = new Group(); | ||
const group2 = new Group(); | ||
const obj = new FabricObject(); | ||
|
||
jest.spyOn(group, 'isOnACache').mockReturnValue(false); | ||
|
||
applyTransformToObject(obj, m); | ||
applyTransformToObject(group, m1); | ||
applyTransformToObject(group2, m2); | ||
|
||
obj.group = group; | ||
const actual = sendObjectToPlane( | ||
obj, | ||
group.calcTransformMatrix(), | ||
group2.calcTransformMatrix() | ||
); | ||
expect(actual).toEqualRoundedMatrix( | ||
multiplyTransformMatrices( | ||
invertTransform(group2.calcTransformMatrix()), | ||
group.calcTransformMatrix() | ||
) | ||
); | ||
expect(obj.calcOwnMatrix()).toEqualRoundedMatrix( | ||
multiplyTransformMatrices(actual, m) | ||
); | ||
|
||
obj.group = group2; | ||
expect(obj.calcTransformMatrix()).toEqualRoundedMatrix( | ||
multiplyTransformMatrices( | ||
multiplyTransformMatrices(group2.calcTransformMatrix(), actual), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
migrated from qunit
Motivation
send plane utils are proving to be valuble
send a vector is also very common and completes the util
Description
expose
sendVectorToPlane
migrate send plane tests to jest, removing the
sendPointToPlane
old test that was unnecessaryChanges
Gist
In Action