Skip to content
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

Point type fix #8434

Merged
merged 9 commits into from
Dec 10, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 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 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
20 changes: 10 additions & 10 deletions src/util/misc/vectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export const rotateVector = (vector: Point, radians: TRadian) =>
/**
* Creates a vector from points represented as a point
*
* @param {Point} from
* @param {Point} to
* @param {IPoint} from
* @param {IPoint} to
* @returns {Point} vector
*/
export const createVector = (from: IPoint, to: IPoint): Point =>
Expand All @@ -34,7 +34,7 @@ export const magnitude = (point: Point) => point.distanceFrom(new Point());
* @param {Point} b
* @returns the angle in radians from `a` to `b`
*/
export const calcAngleBetweenVectors = (a: Point, b: Point): TRadian => {
export const calcAngleBetweenVectors = (a: IPoint, b: IPoint): TRadian => {
const dot = a.x * b.x + a.y * b.y,
det = a.x * b.y - a.y * b.x;
return Math.atan2(det, dot) as TRadian;
Expand All @@ -45,7 +45,7 @@ export const calcAngleBetweenVectors = (a: Point, b: Point): TRadian => {
* @param {Point} v
* @returns the angle in radians of `v`
*/
export const calcVectorRotation = (v: Point) =>
export const calcVectorRotation = (v: IPoint) =>
calcAngleBetweenVectors(unitVectorX, v);

/**
Expand All @@ -55,12 +55,12 @@ export const calcVectorRotation = (v: Point) =>
export const getUnitVector = (v: Point): Point => v.scalarDivide(magnitude(v));

/**
* @param {Point} A
* @param {Point} B
* @param {Point} C
* @param {IPoint} A
* @param {IPoint} B
* @param {IPoint} C
* @returns {{ vector: Point, angle: TRadian}} vector representing the bisector of A and A's angle
*/
export const getBisector = (A: Point, B: Point, C: Point) => {
export const getBisector = (A: IPoint, B: IPoint, C: IPoint) => {
const AB = createVector(A, B),
AC = createVector(A, C),
alpha = calcAngleBetweenVectors(AB, AC);
Expand All @@ -71,12 +71,12 @@ export const getBisector = (A: Point, B: Point, C: Point) => {
};

/**
* @param {Point} v
* @param {IPoint} v
* @param {Boolean} [counterClockwise] the direction of the orthogonal vector, defaults to `true`
* @returns {Point} the unit orthogonal vector
*/
export const getOrthonormalVector = (
v: Point,
v: IPoint,
counterClockwise = true
): Point =>
getUnitVector(new Point(-v.y, v.x).scalarMultiply(counterClockwise ? 1 : -1));