Skip to content

Commit

Permalink
chore(TS): permissive Point typings (#8434)
Browse files Browse the repository at this point in the history
* better use of IPoint where applicable

Co-authored-by: kristpregracke <kpregracke@redfoundry.com>
Co-authored-by: ShaMan123 <shacharnen@gmail.com>
  • Loading branch information
3 people authored Dec 10, 2022
1 parent 2ffac9a commit 1aff23b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
50 changes: 25 additions & 25 deletions src/point.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -40,7 +40,7 @@ export class Point {

/**
* Adds another point to this one
* @param {Point} that
* @param {IPoint} that
* @return {Point} thisArg
* @chainable
* @deprecated
Expand Down Expand Up @@ -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 {
Expand All @@ -84,7 +84,7 @@ export class Point {

/**
* Subtracts another point from this point
* @param {Point} that
* @param {IPoint} that
* @return {Point} thisArg
* @chainable
* @deprecated
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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}
*/
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -282,7 +282,7 @@ export class Point {
* @return {String}
*/
toString(): string {
return this.x + ',' + this.y;
return `${this.x},${this.y}`;
}

/**
Expand Down Expand Up @@ -319,20 +319,20 @@ 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;
}

/**
* 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;
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/util/misc/matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 1aff23b

Please sign in to comment.