From bfb5d4644641fe63b3c44d1811da3c098a4c3407 Mon Sep 17 00:00:00 2001 From: Lazauya Date: Sat, 10 Dec 2022 02:36:03 -0600 Subject: [PATCH] chore(TS): permissive `Point` typings (#8434) * better use of IPoint where applicable Co-authored-by: kristpregracke Co-authored-by: ShaMan123 --- CHANGELOG.md | 1 + src/point.class.ts | 50 ++++++++++++++++++++--------------------- src/util/misc/matrix.ts | 2 +- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbdd1205062..9033943daa4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## [next] +- chore(TS): permissive `Point` typings [#8434](https://github.com/fabricjs/fabric.js/pull/8434) - chore(TS): polish files [#8488](https://github.com/fabricjs/fabric.js/pull/8488) - fix(TS): `EventSpec` recognition [#8497](https://github.com/fabricjs/fabric.js/pull/8497) - chore(): rm dead code [#8493](https://github.com/fabricjs/fabric.js/pull/8493) diff --git a/src/point.class.ts b/src/point.class.ts index 5c201e80900..629a07639a8 100644 --- a/src/point.class.ts +++ b/src/point.class.ts @@ -11,7 +11,7 @@ export interface IPoint { /** * Adaptation of work of Kevin Lindsey(kevin@kevlindev.com) */ -export class Point { +export class Point implements IPoint { x: number; y: number; @@ -31,7 +31,7 @@ export class Point { /** * Adds another point to this one and returns another one - * @param {Point} that + * @param {IPoint} that * @return {Point} new Point instance with added values */ add(that: IPoint): Point { @@ -40,7 +40,7 @@ export class Point { /** * Adds another point to this one - * @param {Point} that + * @param {IPoint} that * @return {Point} thisArg * @chainable * @deprecated @@ -75,7 +75,7 @@ export class Point { /** * Subtracts another point from this point and returns a new one - * @param {Point} that + * @param {IPoint} that * @return {Point} new Point object with subtracted values */ subtract(that: IPoint): Point { @@ -84,7 +84,7 @@ export class Point { /** * Subtracts another point from this point - * @param {Point} that + * @param {IPoint} that * @return {Point} thisArg * @chainable * @deprecated @@ -119,10 +119,10 @@ export class Point { /** * Multiplies this point by another value and returns a new one - * @param {Point} that + * @param {IPoint} that * @return {Point} */ - multiply(that: Point): Point { + multiply(that: IPoint): Point { return new Point(this.x * that.x, this.y * that.y); } @@ -150,7 +150,7 @@ export class Point { /** * Divides this point by another and returns a new one - * @param {Point} that + * @param {IPoint} that * @return {Point} */ divide(that: IPoint): Point { @@ -181,7 +181,7 @@ export class Point { /** * Returns true if this point is equal to another one - * @param {Point} that + * @param {IPoint} that * @return {Boolean} */ eq(that: IPoint): boolean { @@ -190,7 +190,7 @@ export class Point { /** * Returns true if this point is less than another one - * @param {Point} that + * @param {IPoint} that * @return {Boolean} */ lt(that: IPoint): boolean { @@ -199,7 +199,7 @@ export class Point { /** * Returns true if this point is less than or equal to another one - * @param {Point} that + * @param {IPoint} that * @return {Boolean} */ lte(that: IPoint): boolean { @@ -209,7 +209,7 @@ export class Point { /** * Returns true if this point is greater another one - * @param {Point} that + * @param {IPoint} that * @return {Boolean} */ gt(that: IPoint): boolean { @@ -218,7 +218,7 @@ export class Point { /** * Returns true if this point is greater than or equal to another one - * @param {Point} that + * @param {IPoint} that * @return {Boolean} */ gte(that: IPoint): boolean { @@ -227,7 +227,7 @@ export class Point { /** * Returns new point which is the result of linear interpolation with this one and another one - * @param {Point} that + * @param {IPoint} that * @param {Number} t , position of interpolation, between 0 and 1 default 0.5 * @return {Point} */ @@ -241,7 +241,7 @@ export class Point { /** * Returns distance from this point and another one - * @param {Point} that + * @param {IPoint} that * @return {Number} */ distanceFrom(that: IPoint): number { @@ -252,7 +252,7 @@ export class Point { /** * Returns the point between this point and another one - * @param {Point} that + * @param {IPoint} that * @return {Point} */ midPointFrom(that: IPoint): Point { @@ -261,7 +261,7 @@ export class Point { /** * Returns a new point which is the min of this and another one - * @param {Point} that + * @param {IPoint} that * @return {Point} */ min(that: IPoint): Point { @@ -270,7 +270,7 @@ export class Point { /** * Returns a new point which is the max of this and another one - * @param {Point} that + * @param {IPoint} that * @return {Point} */ max(that: IPoint): Point { @@ -282,7 +282,7 @@ export class Point { * @return {String} */ toString(): string { - return this.x + ',' + this.y; + return `${this.x},${this.y}`; } /** @@ -319,10 +319,10 @@ export class Point { /** * Sets x/y of this point from another point - * @param {Point} that + * @param {IPoint} that * @chainable */ - setFromPoint(that: Point) { + setFromPoint(that: IPoint) { this.x = that.x; this.y = that.y; return this; @@ -330,9 +330,9 @@ export class Point { /** * Swaps x/y of this point and another point - * @param {Point} that + * @param {IPoint} that */ - swap(that: Point) { + swap(that: IPoint) { const x = this.x, y = this.y; this.x = that.x; @@ -353,11 +353,11 @@ export class Point { * Rotates `point` around `origin` with `radians` * @static * @memberOf fabric.util - * @param {Point} origin The origin of the rotation + * @param {IPoint} origin The origin of the rotation * @param {TRadian} radians The radians of the angle for the rotation * @return {Point} The new rotated point */ - rotate(radians: TRadian, origin: Point = originZero): Point { + rotate(radians: TRadian, origin: IPoint = originZero): Point { // TODO benchmark and verify the add and subtract how much cost // and then in case early return if no origin is passed const sinus = sin(radians), diff --git a/src/util/misc/matrix.ts b/src/util/misc/matrix.ts index a7fa611a577..2cee6c7aa0c 100644 --- a/src/util/misc/matrix.ts +++ b/src/util/misc/matrix.ts @@ -38,7 +38,7 @@ export type TQrDecomposeOut = Required< * @return {Point} The transformed point */ export const transformPoint = ( - p: Point | IPoint, + p: IPoint, t: TMat2D, ignoreOffset?: boolean ): Point => new Point(p).transform(t, ignoreOffset);