Socket
Socket
Sign inDemoInstall

@pixi/math

Package Overview
Dependencies
Maintainers
2
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pixi/math - npm Package Compare versions

Comparing version 7.2.4 to 7.3.0-rc

19

lib/const.js

@@ -1,17 +0,4 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const PI_2 = Math.PI * 2;
const RAD_TO_DEG = 180 / Math.PI;
const DEG_TO_RAD = Math.PI / 180;
var SHAPES = /* @__PURE__ */ ((SHAPES2) => {
SHAPES2[SHAPES2["POLY"] = 0] = "POLY";
SHAPES2[SHAPES2["RECT"] = 1] = "RECT";
SHAPES2[SHAPES2["CIRC"] = 2] = "CIRC";
SHAPES2[SHAPES2["ELIP"] = 3] = "ELIP";
SHAPES2[SHAPES2["RREC"] = 4] = "RREC";
return SHAPES2;
})(SHAPES || {});
"use strict";
const PI_2 = Math.PI * 2, RAD_TO_DEG = 180 / Math.PI, DEG_TO_RAD = Math.PI / 180;
var SHAPES = /* @__PURE__ */ ((SHAPES2) => (SHAPES2[SHAPES2.POLY = 0] = "POLY", SHAPES2[SHAPES2.RECT = 1] = "RECT", SHAPES2[SHAPES2.CIRC = 2] = "CIRC", SHAPES2[SHAPES2.ELIP = 3] = "ELIP", SHAPES2[SHAPES2.RREC = 4] = "RREC", SHAPES2))(SHAPES || {});
exports.DEG_TO_RAD = DEG_TO_RAD;

@@ -18,0 +5,0 @@ exports.PI_2 = PI_2;

208

lib/groupD8.js

@@ -1,14 +0,4 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var Matrix = require('./Matrix.js');
const ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1];
const uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1];
const vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1];
const vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1];
const rotationCayley = [];
const rotationMatrices = [];
const signum = Math.sign;
"use strict";
var Matrix = require("./Matrix.js");
const ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1], uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1], vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1], vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1], rotationCayley = [], rotationMatrices = [], signum = Math.sign;
function init() {

@@ -19,7 +9,4 @@ for (let i = 0; i < 16; i++) {

for (let j = 0; j < 16; j++) {
const _ux = signum(ux[i] * ux[j] + vx[i] * uy[j]);
const _uy = signum(uy[i] * ux[j] + vy[i] * uy[j]);
const _vx = signum(ux[i] * vx[j] + vx[i] * vy[j]);
const _vy = signum(uy[i] * vx[j] + vy[i] * vy[j]);
for (let k = 0; k < 16; k++) {
const _ux = signum(ux[i] * ux[j] + vx[i] * uy[j]), _uy = signum(uy[i] * ux[j] + vy[i] * uy[j]), _vx = signum(ux[i] * vx[j] + vx[i] * vy[j]), _vy = signum(uy[i] * vx[j] + vy[i] * vy[j]);
for (let k = 0; k < 16; k++)
if (ux[k] === _ux && uy[k] === _uy && vx[k] === _vx && vy[k] === _vy) {

@@ -29,3 +16,2 @@ row.push(k);

}
}
}

@@ -35,4 +21,3 @@ }

const mat = new Matrix.Matrix();
mat.set(ux[i], uy[i], vx[i], vy[i], 0, 0);
rotationMatrices.push(mat);
mat.set(ux[i], uy[i], vx[i], vy[i], 0, 0), rotationMatrices.push(mat);
}

@@ -42,58 +27,177 @@ }

const groupD8 = {
/**
* | Rotation | Direction |
* |----------|-----------|
* | 0° | East |
* @readonly
*/
E: 0,
/**
* | Rotation | Direction |
* |----------|-----------|
* | 45°↻ | Southeast |
* @readonly
*/
SE: 1,
/**
* | Rotation | Direction |
* |----------|-----------|
* | 90°↻ | South |
* @readonly
*/
S: 2,
/**
* | Rotation | Direction |
* |----------|-----------|
* | 135°↻ | Southwest |
* @readonly
*/
SW: 3,
/**
* | Rotation | Direction |
* |----------|-----------|
* | 180° | West |
* @readonly
*/
W: 4,
/**
* | Rotation | Direction |
* |-------------|--------------|
* | -135°/225°↻ | Northwest |
* @readonly
*/
NW: 5,
/**
* | Rotation | Direction |
* |-------------|--------------|
* | -90°/270°↻ | North |
* @readonly
*/
N: 6,
/**
* | Rotation | Direction |
* |-------------|--------------|
* | -45°/315°↻ | Northeast |
* @readonly
*/
NE: 7,
/**
* Reflection about Y-axis.
* @readonly
*/
MIRROR_VERTICAL: 8,
/**
* Reflection about the main diagonal.
* @readonly
*/
MAIN_DIAGONAL: 10,
/**
* Reflection about X-axis.
* @readonly
*/
MIRROR_HORIZONTAL: 12,
/**
* Reflection about reverse diagonal.
* @readonly
*/
REVERSE_DIAGONAL: 14,
/**
* @param {PIXI.GD8Symmetry} ind - sprite rotation angle.
* @returns {PIXI.GD8Symmetry} The X-component of the U-axis
* after rotating the axes.
*/
uX: (ind) => ux[ind],
/**
* @param {PIXI.GD8Symmetry} ind - sprite rotation angle.
* @returns {PIXI.GD8Symmetry} The Y-component of the U-axis
* after rotating the axes.
*/
uY: (ind) => uy[ind],
/**
* @param {PIXI.GD8Symmetry} ind - sprite rotation angle.
* @returns {PIXI.GD8Symmetry} The X-component of the V-axis
* after rotating the axes.
*/
vX: (ind) => vx[ind],
/**
* @param {PIXI.GD8Symmetry} ind - sprite rotation angle.
* @returns {PIXI.GD8Symmetry} The Y-component of the V-axis
* after rotating the axes.
*/
vY: (ind) => vy[ind],
inv: (rotation) => {
if (rotation & 8) {
return rotation & 15;
}
return -rotation & 7;
},
/**
* @param {PIXI.GD8Symmetry} rotation - symmetry whose opposite
* is needed. Only rotations have opposite symmetries while
* reflections don't.
* @returns {PIXI.GD8Symmetry} The opposite symmetry of `rotation`
*/
inv: (rotation) => rotation & 8 ? rotation & 15 : -rotation & 7,
/**
* Composes the two D8 operations.
*
* Taking `^` as reflection:
*
* | | E=0 | S=2 | W=4 | N=6 | E^=8 | S^=10 | W^=12 | N^=14 |
* |-------|-----|-----|-----|-----|------|-------|-------|-------|
* | E=0 | E | S | W | N | E^ | S^ | W^ | N^ |
* | S=2 | S | W | N | E | S^ | W^ | N^ | E^ |
* | W=4 | W | N | E | S | W^ | N^ | E^ | S^ |
* | N=6 | N | E | S | W | N^ | E^ | S^ | W^ |
* | E^=8 | E^ | N^ | W^ | S^ | E | N | W | S |
* | S^=10 | S^ | E^ | N^ | W^ | S | E | N | W |
* | W^=12 | W^ | S^ | E^ | N^ | W | S | E | N |
* | N^=14 | N^ | W^ | S^ | E^ | N | W | S | E |
*
* [This is a Cayley table]{@link https://en.wikipedia.org/wiki/Cayley_table}
* @param {PIXI.GD8Symmetry} rotationSecond - Second operation, which
* is the row in the above cayley table.
* @param {PIXI.GD8Symmetry} rotationFirst - First operation, which
* is the column in the above cayley table.
* @returns {PIXI.GD8Symmetry} Composed operation
*/
add: (rotationSecond, rotationFirst) => rotationCayley[rotationSecond][rotationFirst],
/**
* Reverse of `add`.
* @param {PIXI.GD8Symmetry} rotationSecond - Second operation
* @param {PIXI.GD8Symmetry} rotationFirst - First operation
* @returns {PIXI.GD8Symmetry} Result
*/
sub: (rotationSecond, rotationFirst) => rotationCayley[rotationSecond][groupD8.inv(rotationFirst)],
/**
* Adds 180 degrees to rotation, which is a commutative
* operation.
* @param {number} rotation - The number to rotate.
* @returns {number} Rotated number
*/
rotate180: (rotation) => rotation ^ 4,
/**
* Checks if the rotation angle is vertical, i.e. south
* or north. It doesn't work for reflections.
* @param {PIXI.GD8Symmetry} rotation - The number to check.
* @returns {boolean} Whether or not the direction is vertical
*/
isVertical: (rotation) => (rotation & 3) === 2,
byDirection: (dx, dy) => {
if (Math.abs(dx) * 2 <= Math.abs(dy)) {
if (dy >= 0) {
return groupD8.S;
}
return groupD8.N;
} else if (Math.abs(dy) * 2 <= Math.abs(dx)) {
if (dx > 0) {
return groupD8.E;
}
return groupD8.W;
} else if (dy > 0) {
if (dx > 0) {
return groupD8.SE;
}
return groupD8.SW;
} else if (dx > 0) {
return groupD8.NE;
}
return groupD8.NW;
},
// rotation % 4 === 2
/**
* Approximates the vector `V(dx,dy)` into one of the
* eight directions provided by `groupD8`.
* @param {number} dx - X-component of the vector
* @param {number} dy - Y-component of the vector
* @returns {PIXI.GD8Symmetry} Approximation of the vector into
* one of the eight symmetries.
*/
byDirection: (dx, dy) => Math.abs(dx) * 2 <= Math.abs(dy) ? dy >= 0 ? groupD8.S : groupD8.N : Math.abs(dy) * 2 <= Math.abs(dx) ? dx > 0 ? groupD8.E : groupD8.W : dy > 0 ? dx > 0 ? groupD8.SE : groupD8.SW : dx > 0 ? groupD8.NE : groupD8.NW,
/**
* Helps sprite to compensate texture packer rotation.
* @param {PIXI.Matrix} matrix - sprite world matrix
* @param {PIXI.GD8Symmetry} rotation - The rotation factor to use.
* @param {number} tx - sprite anchoring
* @param {number} ty - sprite anchoring
*/
matrixAppendRotationInv: (matrix, rotation, tx = 0, ty = 0) => {
const mat = rotationMatrices[groupD8.inv(rotation)];
mat.tx = tx;
mat.ty = ty;
matrix.append(mat);
mat.tx = tx, mat.ty = ty, matrix.append(mat);
}
};
exports.groupD8 = groupD8;
//# sourceMappingURL=groupD8.js.map

@@ -1,21 +0,6 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var Circle = require('./shapes/Circle.js');
var Ellipse = require('./shapes/Ellipse.js');
var Polygon = require('./shapes/Polygon.js');
var Rectangle = require('./shapes/Rectangle.js');
var RoundedRectangle = require('./shapes/RoundedRectangle.js');
var groupD8 = require('./groupD8.js');
require('./IPoint.js');
require('./IPointData.js');
var Matrix = require('./Matrix.js');
var ObservablePoint = require('./ObservablePoint.js');
var Point = require('./Point.js');
var Transform = require('./Transform.js');
var _const = require('./const.js');
"use strict";
var Circle = require("./shapes/Circle.js"), Ellipse = require("./shapes/Ellipse.js"), Polygon = require("./shapes/Polygon.js"), Rectangle = require("./shapes/Rectangle.js"), RoundedRectangle = require("./shapes/RoundedRectangle.js"), groupD8 = require("./groupD8.js");
require("./IPoint.js");
require("./IPointData.js");
var Matrix = require("./Matrix.js"), ObservablePoint = require("./ObservablePoint.js"), Point = require("./Point.js"), Transform = require("./Transform.js"), _const = require("./const.js");
exports.Circle = Circle.Circle;

@@ -22,0 +7,0 @@ exports.Ellipse = Ellipse.Ellipse;

@@ -1,3 +0,2 @@

'use strict';
"use strict";
//# sourceMappingURL=IPoint.js.map

@@ -1,3 +0,2 @@

'use strict';
"use strict";
//# sourceMappingURL=IPointData.js.map

@@ -163,3 +163,2 @@ import { Point } from './Point';

copyFrom(matrix: Matrix): this;
toString(): string;
/**

@@ -166,0 +165,0 @@ * A default (identity) matrix

@@ -1,225 +0,201 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _const = require('./const.js');
var Point = require('./Point.js');
"use strict";
var _const = require("./const.js"), Point = require("./Point.js");
class Matrix {
/**
* @param a - x scale
* @param b - y skew
* @param c - x skew
* @param d - y scale
* @param tx - x translation
* @param ty - y translation
*/
constructor(a = 1, b = 0, c = 0, d = 1, tx = 0, ty = 0) {
this.array = null;
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.tx = tx;
this.ty = ty;
this.array = null, this.a = a, this.b = b, this.c = c, this.d = d, this.tx = tx, this.ty = ty;
}
/**
* Creates a Matrix object based on the given array. The Element to Matrix mapping order is as follows:
*
* a = array[0]
* b = array[1]
* c = array[3]
* d = array[4]
* tx = array[2]
* ty = array[5]
* @param array - The array that the matrix will be populated from.
*/
fromArray(array) {
this.a = array[0];
this.b = array[1];
this.c = array[3];
this.d = array[4];
this.tx = array[2];
this.ty = array[5];
this.a = array[0], this.b = array[1], this.c = array[3], this.d = array[4], this.tx = array[2], this.ty = array[5];
}
/**
* Sets the matrix properties.
* @param a - Matrix component
* @param b - Matrix component
* @param c - Matrix component
* @param d - Matrix component
* @param tx - Matrix component
* @param ty - Matrix component
* @returns This matrix. Good for chaining method calls.
*/
set(a, b, c, d, tx, ty) {
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.tx = tx;
this.ty = ty;
return this;
return this.a = a, this.b = b, this.c = c, this.d = d, this.tx = tx, this.ty = ty, this;
}
/**
* Creates an array from the current Matrix object.
* @param transpose - Whether we need to transpose the matrix or not
* @param [out=new Float32Array(9)] - If provided the array will be assigned to out
* @returns The newly created array which contains the matrix
*/
toArray(transpose, out) {
if (!this.array) {
this.array = new Float32Array(9);
}
this.array || (this.array = new Float32Array(9));
const array = out || this.array;
if (transpose) {
array[0] = this.a;
array[1] = this.b;
array[2] = 0;
array[3] = this.c;
array[4] = this.d;
array[5] = 0;
array[6] = this.tx;
array[7] = this.ty;
array[8] = 1;
} else {
array[0] = this.a;
array[1] = this.c;
array[2] = this.tx;
array[3] = this.b;
array[4] = this.d;
array[5] = this.ty;
array[6] = 0;
array[7] = 0;
array[8] = 1;
}
return array;
return transpose ? (array[0] = this.a, array[1] = this.b, array[2] = 0, array[3] = this.c, array[4] = this.d, array[5] = 0, array[6] = this.tx, array[7] = this.ty, array[8] = 1) : (array[0] = this.a, array[1] = this.c, array[2] = this.tx, array[3] = this.b, array[4] = this.d, array[5] = this.ty, array[6] = 0, array[7] = 0, array[8] = 1), array;
}
/**
* Get a new position with the current transformation applied.
* Can be used to go from a child's coordinate space to the world coordinate space. (e.g. rendering)
* @param pos - The origin
* @param {PIXI.Point} [newPos] - The point that the new position is assigned to (allowed to be same as input)
* @returns {PIXI.Point} The new point, transformed through this matrix
*/
apply(pos, newPos) {
newPos = newPos || new Point.Point();
const x = pos.x;
const y = pos.y;
newPos.x = this.a * x + this.c * y + this.tx;
newPos.y = this.b * x + this.d * y + this.ty;
return newPos;
const x = pos.x, y = pos.y;
return newPos.x = this.a * x + this.c * y + this.tx, newPos.y = this.b * x + this.d * y + this.ty, newPos;
}
/**
* Get a new position with the inverse of the current transformation applied.
* Can be used to go from the world coordinate space to a child's coordinate space. (e.g. input)
* @param pos - The origin
* @param {PIXI.Point} [newPos] - The point that the new position is assigned to (allowed to be same as input)
* @returns {PIXI.Point} The new point, inverse-transformed through this matrix
*/
applyInverse(pos, newPos) {
newPos = newPos || new Point.Point();
const id = 1 / (this.a * this.d + this.c * -this.b);
const x = pos.x;
const y = pos.y;
newPos.x = this.d * id * x + -this.c * id * y + (this.ty * this.c - this.tx * this.d) * id;
newPos.y = this.a * id * y + -this.b * id * x + (-this.ty * this.a + this.tx * this.b) * id;
return newPos;
const id = 1 / (this.a * this.d + this.c * -this.b), x = pos.x, y = pos.y;
return newPos.x = this.d * id * x + -this.c * id * y + (this.ty * this.c - this.tx * this.d) * id, newPos.y = this.a * id * y + -this.b * id * x + (-this.ty * this.a + this.tx * this.b) * id, newPos;
}
/**
* Translates the matrix on the x and y.
* @param x - How much to translate x by
* @param y - How much to translate y by
* @returns This matrix. Good for chaining method calls.
*/
translate(x, y) {
this.tx += x;
this.ty += y;
return this;
return this.tx += x, this.ty += y, this;
}
/**
* Applies a scale transformation to the matrix.
* @param x - The amount to scale horizontally
* @param y - The amount to scale vertically
* @returns This matrix. Good for chaining method calls.
*/
scale(x, y) {
this.a *= x;
this.d *= y;
this.c *= x;
this.b *= y;
this.tx *= x;
this.ty *= y;
return this;
return this.a *= x, this.d *= y, this.c *= x, this.b *= y, this.tx *= x, this.ty *= y, this;
}
/**
* Applies a rotation transformation to the matrix.
* @param angle - The angle in radians.
* @returns This matrix. Good for chaining method calls.
*/
rotate(angle) {
const cos = Math.cos(angle);
const sin = Math.sin(angle);
const a1 = this.a;
const c1 = this.c;
const tx1 = this.tx;
this.a = a1 * cos - this.b * sin;
this.b = a1 * sin + this.b * cos;
this.c = c1 * cos - this.d * sin;
this.d = c1 * sin + this.d * cos;
this.tx = tx1 * cos - this.ty * sin;
this.ty = tx1 * sin + this.ty * cos;
return this;
const cos = Math.cos(angle), sin = Math.sin(angle), a1 = this.a, c1 = this.c, tx1 = this.tx;
return this.a = a1 * cos - this.b * sin, this.b = a1 * sin + this.b * cos, this.c = c1 * cos - this.d * sin, this.d = c1 * sin + this.d * cos, this.tx = tx1 * cos - this.ty * sin, this.ty = tx1 * sin + this.ty * cos, this;
}
/**
* Appends the given Matrix to this Matrix.
* @param matrix - The matrix to append.
* @returns This matrix. Good for chaining method calls.
*/
append(matrix) {
const a1 = this.a;
const b1 = this.b;
const c1 = this.c;
const d1 = this.d;
this.a = matrix.a * a1 + matrix.b * c1;
this.b = matrix.a * b1 + matrix.b * d1;
this.c = matrix.c * a1 + matrix.d * c1;
this.d = matrix.c * b1 + matrix.d * d1;
this.tx = matrix.tx * a1 + matrix.ty * c1 + this.tx;
this.ty = matrix.tx * b1 + matrix.ty * d1 + this.ty;
return this;
const a1 = this.a, b1 = this.b, c1 = this.c, d1 = this.d;
return this.a = matrix.a * a1 + matrix.b * c1, this.b = matrix.a * b1 + matrix.b * d1, this.c = matrix.c * a1 + matrix.d * c1, this.d = matrix.c * b1 + matrix.d * d1, this.tx = matrix.tx * a1 + matrix.ty * c1 + this.tx, this.ty = matrix.tx * b1 + matrix.ty * d1 + this.ty, this;
}
/**
* Sets the matrix based on all the available properties
* @param x - Position on the x axis
* @param y - Position on the y axis
* @param pivotX - Pivot on the x axis
* @param pivotY - Pivot on the y axis
* @param scaleX - Scale on the x axis
* @param scaleY - Scale on the y axis
* @param rotation - Rotation in radians
* @param skewX - Skew on the x axis
* @param skewY - Skew on the y axis
* @returns This matrix. Good for chaining method calls.
*/
setTransform(x, y, pivotX, pivotY, scaleX, scaleY, rotation, skewX, skewY) {
this.a = Math.cos(rotation + skewY) * scaleX;
this.b = Math.sin(rotation + skewY) * scaleX;
this.c = -Math.sin(rotation - skewX) * scaleY;
this.d = Math.cos(rotation - skewX) * scaleY;
this.tx = x - (pivotX * this.a + pivotY * this.c);
this.ty = y - (pivotX * this.b + pivotY * this.d);
return this;
return this.a = Math.cos(rotation + skewY) * scaleX, this.b = Math.sin(rotation + skewY) * scaleX, this.c = -Math.sin(rotation - skewX) * scaleY, this.d = Math.cos(rotation - skewX) * scaleY, this.tx = x - (pivotX * this.a + pivotY * this.c), this.ty = y - (pivotX * this.b + pivotY * this.d), this;
}
/**
* Prepends the given Matrix to this Matrix.
* @param matrix - The matrix to prepend
* @returns This matrix. Good for chaining method calls.
*/
prepend(matrix) {
const tx1 = this.tx;
if (matrix.a !== 1 || matrix.b !== 0 || matrix.c !== 0 || matrix.d !== 1) {
const a1 = this.a;
const c1 = this.c;
this.a = a1 * matrix.a + this.b * matrix.c;
this.b = a1 * matrix.b + this.b * matrix.d;
this.c = c1 * matrix.a + this.d * matrix.c;
this.d = c1 * matrix.b + this.d * matrix.d;
const a1 = this.a, c1 = this.c;
this.a = a1 * matrix.a + this.b * matrix.c, this.b = a1 * matrix.b + this.b * matrix.d, this.c = c1 * matrix.a + this.d * matrix.c, this.d = c1 * matrix.b + this.d * matrix.d;
}
this.tx = tx1 * matrix.a + this.ty * matrix.c + matrix.tx;
this.ty = tx1 * matrix.b + this.ty * matrix.d + matrix.ty;
return this;
return this.tx = tx1 * matrix.a + this.ty * matrix.c + matrix.tx, this.ty = tx1 * matrix.b + this.ty * matrix.d + matrix.ty, this;
}
/**
* Decomposes the matrix (x, y, scaleX, scaleY, and rotation) and sets the properties on to a transform.
* @param transform - The transform to apply the properties to.
* @returns The transform with the newly applied properties
*/
decompose(transform) {
const a = this.a;
const b = this.b;
const c = this.c;
const d = this.d;
const pivot = transform.pivot;
const skewX = -Math.atan2(-c, d);
const skewY = Math.atan2(b, a);
const delta = Math.abs(skewX + skewY);
if (delta < 1e-5 || Math.abs(_const.PI_2 - delta) < 1e-5) {
transform.rotation = skewY;
transform.skew.x = transform.skew.y = 0;
} else {
transform.rotation = 0;
transform.skew.x = skewX;
transform.skew.y = skewY;
}
transform.scale.x = Math.sqrt(a * a + b * b);
transform.scale.y = Math.sqrt(c * c + d * d);
transform.position.x = this.tx + (pivot.x * a + pivot.y * c);
transform.position.y = this.ty + (pivot.x * b + pivot.y * d);
return transform;
const a = this.a, b = this.b, c = this.c, d = this.d, pivot = transform.pivot, skewX = -Math.atan2(-c, d), skewY = Math.atan2(b, a), delta = Math.abs(skewX + skewY);
return delta < 1e-5 || Math.abs(_const.PI_2 - delta) < 1e-5 ? (transform.rotation = skewY, transform.skew.x = transform.skew.y = 0) : (transform.rotation = 0, transform.skew.x = skewX, transform.skew.y = skewY), transform.scale.x = Math.sqrt(a * a + b * b), transform.scale.y = Math.sqrt(c * c + d * d), transform.position.x = this.tx + (pivot.x * a + pivot.y * c), transform.position.y = this.ty + (pivot.x * b + pivot.y * d), transform;
}
/**
* Inverts this matrix
* @returns This matrix. Good for chaining method calls.
*/
invert() {
const a1 = this.a;
const b1 = this.b;
const c1 = this.c;
const d1 = this.d;
const tx1 = this.tx;
const n = a1 * d1 - b1 * c1;
this.a = d1 / n;
this.b = -b1 / n;
this.c = -c1 / n;
this.d = a1 / n;
this.tx = (c1 * this.ty - d1 * tx1) / n;
this.ty = -(a1 * this.ty - b1 * tx1) / n;
return this;
const a1 = this.a, b1 = this.b, c1 = this.c, d1 = this.d, tx1 = this.tx, n = a1 * d1 - b1 * c1;
return this.a = d1 / n, this.b = -b1 / n, this.c = -c1 / n, this.d = a1 / n, this.tx = (c1 * this.ty - d1 * tx1) / n, this.ty = -(a1 * this.ty - b1 * tx1) / n, this;
}
/**
* Resets this Matrix to an identity (default) matrix.
* @returns This matrix. Good for chaining method calls.
*/
identity() {
this.a = 1;
this.b = 0;
this.c = 0;
this.d = 1;
this.tx = 0;
this.ty = 0;
return this;
return this.a = 1, this.b = 0, this.c = 0, this.d = 1, this.tx = 0, this.ty = 0, this;
}
/**
* Creates a new Matrix object with the same values as this one.
* @returns A copy of this matrix. Good for chaining method calls.
*/
clone() {
const matrix = new Matrix();
matrix.a = this.a;
matrix.b = this.b;
matrix.c = this.c;
matrix.d = this.d;
matrix.tx = this.tx;
matrix.ty = this.ty;
return matrix;
return matrix.a = this.a, matrix.b = this.b, matrix.c = this.c, matrix.d = this.d, matrix.tx = this.tx, matrix.ty = this.ty, matrix;
}
/**
* Changes the values of the given matrix to be the same as the ones in this matrix
* @param matrix - The matrix to copy to.
* @returns The matrix given in parameter with its values updated.
*/
copyTo(matrix) {
matrix.a = this.a;
matrix.b = this.b;
matrix.c = this.c;
matrix.d = this.d;
matrix.tx = this.tx;
matrix.ty = this.ty;
return matrix;
return matrix.a = this.a, matrix.b = this.b, matrix.c = this.c, matrix.d = this.d, matrix.tx = this.tx, matrix.ty = this.ty, matrix;
}
/**
* Changes the values of the matrix to be the same as the ones in given matrix
* @param {PIXI.Matrix} matrix - The matrix to copy from.
* @returns {PIXI.Matrix} this
*/
copyFrom(matrix) {
this.a = matrix.a;
this.b = matrix.b;
this.c = matrix.c;
this.d = matrix.d;
this.tx = matrix.tx;
this.ty = matrix.ty;
return this;
return this.a = matrix.a, this.b = matrix.b, this.c = matrix.c, this.d = matrix.d, this.tx = matrix.tx, this.ty = matrix.ty, this;
}
toString() {
return `[@pixi/math:Matrix a=${this.a} b=${this.b} c=${this.c} d=${this.d} tx=${this.tx} ty=${this.ty}]`;
}
/**
* A default (identity) matrix
* @readonly
*/
static get IDENTITY() {
return new Matrix();
}
/**
* A temp matrix
* @readonly
*/
static get TEMP_MATRIX() {

@@ -229,4 +205,6 @@ return new Matrix();

}
Matrix.prototype.toString = function() {
return `[@pixi/math:Matrix a=${this.a} b=${this.b} c=${this.c} d=${this.d} tx=${this.tx} ty=${this.ty}]`;
};
exports.Matrix = Matrix;
//# sourceMappingURL=Matrix.js.map

@@ -63,3 +63,2 @@ import type { IPoint } from './IPoint';

equals(p: IPointData): boolean;
toString(): string;
/** Position of the observable point on the x axis. */

@@ -66,0 +65,0 @@ get x(): number;

@@ -1,41 +0,60 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
"use strict";
class ObservablePoint {
/**
* Creates a new `ObservablePoint`
* @param cb - callback function triggered when `x` and/or `y` are changed
* @param scope - owner of callback
* @param {number} [x=0] - position of the point on the x axis
* @param {number} [y=0] - position of the point on the y axis
*/
constructor(cb, scope, x = 0, y = 0) {
this._x = x;
this._y = y;
this.cb = cb;
this.scope = scope;
this._x = x, this._y = y, this.cb = cb, this.scope = scope;
}
/**
* Creates a clone of this point.
* The callback and scope params can be overridden otherwise they will default
* to the clone object's values.
* @override
* @param cb - The callback function triggered when `x` and/or `y` are changed
* @param scope - The owner of the callback
* @returns a copy of this observable point
*/
clone(cb = this.cb, scope = this.scope) {
return new ObservablePoint(cb, scope, this._x, this._y);
}
/**
* Sets the point to a new `x` and `y` position.
* If `y` is omitted, both `x` and `y` will be set to `x`.
* @param {number} [x=0] - position of the point on the x axis
* @param {number} [y=x] - position of the point on the y axis
* @returns The observable point instance itself
*/
set(x = 0, y = x) {
if (this._x !== x || this._y !== y) {
this._x = x;
this._y = y;
this.cb.call(this.scope);
}
return this;
return (this._x !== x || this._y !== y) && (this._x = x, this._y = y, this.cb.call(this.scope)), this;
}
/**
* Copies x and y from the given point (`p`)
* @param p - The point to copy from. Can be any of type that is or extends `IPointData`
* @returns The observable point instance itself
*/
copyFrom(p) {
if (this._x !== p.x || this._y !== p.y) {
this._x = p.x;
this._y = p.y;
this.cb.call(this.scope);
}
return this;
return (this._x !== p.x || this._y !== p.y) && (this._x = p.x, this._y = p.y, this.cb.call(this.scope)), this;
}
/**
* Copies this point's x and y into that of the given point (`p`)
* @param p - The point to copy to. Can be any of type that is or extends `IPointData`
* @returns The point (`p`) with values updated
*/
copyTo(p) {
p.set(this._x, this._y);
return p;
return p.set(this._x, this._y), p;
}
/**
* Accepts another point (`p`) and returns `true` if the given point is equal to this point
* @param p - The point to check
* @returns Returns `true` if both `x` and `y` are equal
*/
equals(p) {
return p.x === this._x && p.y === this._y;
}
toString() {
return `[@pixi/math:ObservablePoint x=${0} y=${0} scope=${this.scope}]`;
}
/** Position of the observable point on the x axis. */
get x() {

@@ -45,7 +64,5 @@ return this._x;

set x(value) {
if (this._x !== value) {
this._x = value;
this.cb.call(this.scope);
}
this._x !== value && (this._x = value, this.cb.call(this.scope));
}
/** Position of the observable point on the y axis. */
get y() {

@@ -55,10 +72,9 @@ return this._y;

set y(value) {
if (this._y !== value) {
this._y = value;
this.cb.call(this.scope);
}
this._y !== value && (this._y = value, this.cb.call(this.scope));
}
}
ObservablePoint.prototype.toString = function() {
return `[@pixi/math:ObservablePoint x=${this.x} y=${this.y} scope=${this.scope}]`;
};
exports.ObservablePoint = ObservablePoint;
//# sourceMappingURL=ObservablePoint.js.map

@@ -54,3 +54,2 @@ import type { IPoint } from './IPoint';

set(x?: number, y?: number): this;
toString(): string;
}

@@ -1,37 +0,57 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
"use strict";
class Point {
/**
* Creates a new `Point`
* @param {number} [x=0] - position of the point on the x axis
* @param {number} [y=0] - position of the point on the y axis
*/
constructor(x = 0, y = 0) {
this.x = 0;
this.y = 0;
this.x = x;
this.y = y;
this.x = 0, this.y = 0, this.x = x, this.y = y;
}
/**
* Creates a clone of this point
* @returns A clone of this point
*/
clone() {
return new Point(this.x, this.y);
}
/**
* Copies `x` and `y` from the given point into this point
* @param p - The point to copy from
* @returns The point instance itself
*/
copyFrom(p) {
this.set(p.x, p.y);
return this;
return this.set(p.x, p.y), this;
}
/**
* Copies this point's x and y into the given point (`p`).
* @param p - The point to copy to. Can be any of type that is or extends `IPointData`
* @returns The point (`p`) with values updated
*/
copyTo(p) {
p.set(this.x, this.y);
return p;
return p.set(this.x, this.y), p;
}
/**
* Accepts another point (`p`) and returns `true` if the given point is equal to this point
* @param p - The point to check
* @returns Returns `true` if both `x` and `y` are equal
*/
equals(p) {
return p.x === this.x && p.y === this.y;
}
/**
* Sets the point to a new `x` and `y` position.
* If `y` is omitted, both `x` and `y` will be set to `x`.
* @param {number} [x=0] - position of the point on the `x` axis
* @param {number} [y=x] - position of the point on the `y` axis
* @returns The point instance itself
*/
set(x = 0, y = x) {
this.x = x;
this.y = y;
return this;
return this.x = x, this.y = y, this;
}
toString() {
return `[@pixi/math:Point x=${this.x} y=${this.y}]`;
}
}
Point.prototype.toString = function() {
return `[@pixi/math:Point x=${this.x} y=${this.y}]`;
};
exports.Point = Point;
//# sourceMappingURL=Point.js.map

@@ -43,3 +43,2 @@ import { SHAPES } from './../const';

getBounds(): Rectangle;
toString(): string;
}

@@ -1,38 +0,44 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _const = require('../const.js');
var Rectangle = require('./Rectangle.js');
"use strict";
var _const = require("../const.js"), Rectangle = require("./Rectangle.js");
class Circle {
/**
* @param x - The X coordinate of the center of this circle
* @param y - The Y coordinate of the center of this circle
* @param radius - The radius of the circle
*/
constructor(x = 0, y = 0, radius = 0) {
this.x = x;
this.y = y;
this.radius = radius;
this.type = _const.SHAPES.CIRC;
this.x = x, this.y = y, this.radius = radius, this.type = _const.SHAPES.CIRC;
}
/**
* Creates a clone of this Circle instance
* @returns A copy of the Circle
*/
clone() {
return new Circle(this.x, this.y, this.radius);
}
/**
* Checks whether the x and y coordinates given are contained within this circle
* @param x - The X coordinate of the point to test
* @param y - The Y coordinate of the point to test
* @returns Whether the x/y coordinates are within this Circle
*/
contains(x, y) {
if (this.radius <= 0) {
return false;
}
if (this.radius <= 0)
return !1;
const r2 = this.radius * this.radius;
let dx = this.x - x;
let dy = this.y - y;
dx *= dx;
dy *= dy;
return dx + dy <= r2;
let dx = this.x - x, dy = this.y - y;
return dx *= dx, dy *= dy, dx + dy <= r2;
}
/**
* Returns the framing rectangle of the circle as a Rectangle object
* @returns The framing rectangle
*/
getBounds() {
return new Rectangle.Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2);
}
toString() {
return `[@pixi/math:Circle x=${this.x} y=${this.y} radius=${this.radius}]`;
}
}
Circle.prototype.toString = function() {
return `[@pixi/math:Circle x=${this.x} y=${this.y} radius=${this.radius}]`;
};
exports.Circle = Circle;
//# sourceMappingURL=Circle.js.map

@@ -46,3 +46,2 @@ import { SHAPES } from '../const';

getBounds(): Rectangle;
toString(): string;
}

@@ -1,38 +0,44 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _const = require('../const.js');
var Rectangle = require('./Rectangle.js');
"use strict";
var _const = require("../const.js"), Rectangle = require("./Rectangle.js");
class Ellipse {
/**
* @param x - The X coordinate of the center of this ellipse
* @param y - The Y coordinate of the center of this ellipse
* @param halfWidth - The half width of this ellipse
* @param halfHeight - The half height of this ellipse
*/
constructor(x = 0, y = 0, halfWidth = 0, halfHeight = 0) {
this.x = x;
this.y = y;
this.width = halfWidth;
this.height = halfHeight;
this.type = _const.SHAPES.ELIP;
this.x = x, this.y = y, this.width = halfWidth, this.height = halfHeight, this.type = _const.SHAPES.ELIP;
}
/**
* Creates a clone of this Ellipse instance
* @returns {PIXI.Ellipse} A copy of the ellipse
*/
clone() {
return new Ellipse(this.x, this.y, this.width, this.height);
}
/**
* Checks whether the x and y coordinates given are contained within this ellipse
* @param x - The X coordinate of the point to test
* @param y - The Y coordinate of the point to test
* @returns Whether the x/y coords are within this ellipse
*/
contains(x, y) {
if (this.width <= 0 || this.height <= 0) {
return false;
}
let normx = (x - this.x) / this.width;
let normy = (y - this.y) / this.height;
normx *= normx;
normy *= normy;
return normx + normy <= 1;
if (this.width <= 0 || this.height <= 0)
return !1;
let normx = (x - this.x) / this.width, normy = (y - this.y) / this.height;
return normx *= normx, normy *= normy, normx + normy <= 1;
}
/**
* Returns the framing rectangle of the ellipse as a Rectangle object
* @returns The framing rectangle
*/
getBounds() {
return new Rectangle.Rectangle(this.x - this.width, this.y - this.height, this.width, this.height);
}
toString() {
return `[@pixi/math:Ellipse x=${this.x} y=${this.y} width=${this.width} height=${this.height}]`;
}
}
Ellipse.prototype.toString = function() {
return `[@pixi/math:Ellipse x=${this.x} y=${this.y} width=${this.width} height=${this.height}]`;
};
exports.Ellipse = Ellipse;
//# sourceMappingURL=Ellipse.js.map

@@ -32,3 +32,2 @@ import { SHAPES } from '../const';

contains(x: number, y: number): boolean;
toString(): string;
}

@@ -1,48 +0,49 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _const = require('../const.js');
"use strict";
var _const = require("../const.js");
class Polygon {
/**
* @param {PIXI.IPointData[]|number[]} points - This can be an array of Points
* that form the polygon, a flat array of numbers that will be interpreted as [x,y, x,y, ...], or
* the arguments passed can be all the points of the polygon e.g.
* `new Polygon(new Point(), new Point(), ...)`, or the arguments passed can be flat
* x,y values e.g. `new Polygon(x,y, x,y, x,y, ...)` where `x` and `y` are Numbers.
*/
constructor(...points) {
let flat = Array.isArray(points[0]) ? points[0] : points;
if (typeof flat[0] !== "number") {
if (typeof flat[0] != "number") {
const p = [];
for (let i = 0, il = flat.length; i < il; i++) {
for (let i = 0, il = flat.length; i < il; i++)
p.push(flat[i].x, flat[i].y);
}
flat = p;
}
this.points = flat;
this.type = _const.SHAPES.POLY;
this.closeStroke = true;
this.points = flat, this.type = _const.SHAPES.POLY, this.closeStroke = !0;
}
/**
* Creates a clone of this polygon.
* @returns - A copy of the polygon.
*/
clone() {
const points = this.points.slice();
const polygon = new Polygon(points);
polygon.closeStroke = this.closeStroke;
return polygon;
const points = this.points.slice(), polygon = new Polygon(points);
return polygon.closeStroke = this.closeStroke, polygon;
}
/**
* Checks whether the x and y coordinates passed to this function are contained within this polygon.
* @param x - The X coordinate of the point to test.
* @param y - The Y coordinate of the point to test.
* @returns - Whether the x/y coordinates are within this polygon.
*/
contains(x, y) {
let inside = false;
let inside = !1;
const length = this.points.length / 2;
for (let i = 0, j = length - 1; i < length; j = i++) {
const xi = this.points[i * 2];
const yi = this.points[i * 2 + 1];
const xj = this.points[j * 2];
const yj = this.points[j * 2 + 1];
const intersect = yi > y !== yj > y && x < (xj - xi) * ((y - yi) / (yj - yi)) + xi;
if (intersect) {
inside = !inside;
}
const xi = this.points[i * 2], yi = this.points[i * 2 + 1], xj = this.points[j * 2], yj = this.points[j * 2 + 1];
yi > y != yj > y && x < (xj - xi) * ((y - yi) / (yj - yi)) + xi && (inside = !inside);
}
return inside;
}
toString() {
return `[@pixi/math:PolygoncloseStroke=${this.closeStroke}points=${this.points.reduce((pointsDesc, currentPoint) => `${pointsDesc}, ${currentPoint}`, "")}]`;
}
}
Polygon.prototype.toString = function() {
return `[@pixi/math:PolygoncloseStroke=${this.closeStroke}points=${this.points.reduce((pointsDesc, currentPoint) => `${pointsDesc}, ${currentPoint}`, "")}]`;
};
exports.Polygon = Polygon;
//# sourceMappingURL=Polygon.js.map

@@ -110,3 +110,2 @@ import { SHAPES } from '../const';

enlarge(rectangle: Rectangle): this;
toString(): string;
}

@@ -1,160 +0,141 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _const = require('../const.js');
var Point = require('../Point.js');
"use strict";
var _const = require("../const.js"), Point = require("../Point.js");
const tempPoints = [new Point.Point(), new Point.Point(), new Point.Point(), new Point.Point()];
class Rectangle {
/**
* @param x - The X coordinate of the upper-left corner of the rectangle
* @param y - The Y coordinate of the upper-left corner of the rectangle
* @param width - The overall width of the rectangle
* @param height - The overall height of the rectangle
*/
constructor(x = 0, y = 0, width = 0, height = 0) {
this.x = Number(x);
this.y = Number(y);
this.width = Number(width);
this.height = Number(height);
this.type = _const.SHAPES.RECT;
this.x = Number(x), this.y = Number(y), this.width = Number(width), this.height = Number(height), this.type = _const.SHAPES.RECT;
}
/** Returns the left edge of the rectangle. */
get left() {
return this.x;
}
/** Returns the right edge of the rectangle. */
get right() {
return this.x + this.width;
}
/** Returns the top edge of the rectangle. */
get top() {
return this.y;
}
/** Returns the bottom edge of the rectangle. */
get bottom() {
return this.y + this.height;
}
/** A constant empty rectangle. */
static get EMPTY() {
return new Rectangle(0, 0, 0, 0);
}
/**
* Creates a clone of this Rectangle
* @returns a copy of the rectangle
*/
clone() {
return new Rectangle(this.x, this.y, this.width, this.height);
}
/**
* Copies another rectangle to this one.
* @param rectangle - The rectangle to copy from.
* @returns Returns itself.
*/
copyFrom(rectangle) {
this.x = rectangle.x;
this.y = rectangle.y;
this.width = rectangle.width;
this.height = rectangle.height;
return this;
return this.x = rectangle.x, this.y = rectangle.y, this.width = rectangle.width, this.height = rectangle.height, this;
}
/**
* Copies this rectangle to another one.
* @param rectangle - The rectangle to copy to.
* @returns Returns given parameter.
*/
copyTo(rectangle) {
rectangle.x = this.x;
rectangle.y = this.y;
rectangle.width = this.width;
rectangle.height = this.height;
return rectangle;
return rectangle.x = this.x, rectangle.y = this.y, rectangle.width = this.width, rectangle.height = this.height, rectangle;
}
/**
* Checks whether the x and y coordinates given are contained within this Rectangle
* @param x - The X coordinate of the point to test
* @param y - The Y coordinate of the point to test
* @returns Whether the x/y coordinates are within this Rectangle
*/
contains(x, y) {
if (this.width <= 0 || this.height <= 0) {
return false;
}
if (x >= this.x && x < this.x + this.width) {
if (y >= this.y && y < this.y + this.height) {
return true;
}
}
return false;
return this.width <= 0 || this.height <= 0 ? !1 : x >= this.x && x < this.x + this.width && y >= this.y && y < this.y + this.height;
}
/**
* Determines whether the `other` Rectangle transformed by `transform` intersects with `this` Rectangle object.
* Returns true only if the area of the intersection is >0, this means that Rectangles
* sharing a side are not overlapping. Another side effect is that an arealess rectangle
* (width or height equal to zero) can't intersect any other rectangle.
* @param {Rectangle} other - The Rectangle to intersect with `this`.
* @param {Matrix} transform - The transformation matrix of `other`.
* @returns {boolean} A value of `true` if the transformed `other` Rectangle intersects with `this`; otherwise `false`.
*/
intersects(other, transform) {
if (!transform) {
const x02 = this.x < other.x ? other.x : this.x;
const x12 = this.right > other.right ? other.right : this.right;
if (x12 <= x02) {
return false;
}
if ((this.right > other.right ? other.right : this.right) <= x02)
return !1;
const y02 = this.y < other.y ? other.y : this.y;
const y12 = this.bottom > other.bottom ? other.bottom : this.bottom;
return y12 > y02;
return (this.bottom > other.bottom ? other.bottom : this.bottom) > y02;
}
const x0 = this.left;
const x1 = this.right;
const y0 = this.top;
const y1 = this.bottom;
if (x1 <= x0 || y1 <= y0) {
return false;
}
const lt = tempPoints[0].set(other.left, other.top);
const lb = tempPoints[1].set(other.left, other.bottom);
const rt = tempPoints[2].set(other.right, other.top);
const rb = tempPoints[3].set(other.right, other.bottom);
if (rt.x <= lt.x || lb.y <= lt.y) {
return false;
}
const x0 = this.left, x1 = this.right, y0 = this.top, y1 = this.bottom;
if (x1 <= x0 || y1 <= y0)
return !1;
const lt = tempPoints[0].set(other.left, other.top), lb = tempPoints[1].set(other.left, other.bottom), rt = tempPoints[2].set(other.right, other.top), rb = tempPoints[3].set(other.right, other.bottom);
if (rt.x <= lt.x || lb.y <= lt.y)
return !1;
const s = Math.sign(transform.a * transform.d - transform.b * transform.c);
if (s === 0) {
return false;
}
transform.apply(lt, lt);
transform.apply(lb, lb);
transform.apply(rt, rt);
transform.apply(rb, rb);
if (Math.max(lt.x, lb.x, rt.x, rb.x) <= x0 || Math.min(lt.x, lb.x, rt.x, rb.x) >= x1 || Math.max(lt.y, lb.y, rt.y, rb.y) <= y0 || Math.min(lt.y, lb.y, rt.y, rb.y) >= y1) {
return false;
}
const nx = s * (lb.y - lt.y);
const ny = s * (lt.x - lb.x);
const n00 = nx * x0 + ny * y0;
const n10 = nx * x1 + ny * y0;
const n01 = nx * x0 + ny * y1;
const n11 = nx * x1 + ny * y1;
if (Math.max(n00, n10, n01, n11) <= nx * lt.x + ny * lt.y || Math.min(n00, n10, n01, n11) >= nx * rb.x + ny * rb.y) {
return false;
}
const mx = s * (lt.y - rt.y);
const my = s * (rt.x - lt.x);
const m00 = mx * x0 + my * y0;
const m10 = mx * x1 + my * y0;
const m01 = mx * x0 + my * y1;
const m11 = mx * x1 + my * y1;
if (Math.max(m00, m10, m01, m11) <= mx * lt.x + my * lt.y || Math.min(m00, m10, m01, m11) >= mx * rb.x + my * rb.y) {
return false;
}
return true;
if (s === 0 || (transform.apply(lt, lt), transform.apply(lb, lb), transform.apply(rt, rt), transform.apply(rb, rb), Math.max(lt.x, lb.x, rt.x, rb.x) <= x0 || Math.min(lt.x, lb.x, rt.x, rb.x) >= x1 || Math.max(lt.y, lb.y, rt.y, rb.y) <= y0 || Math.min(lt.y, lb.y, rt.y, rb.y) >= y1))
return !1;
const nx = s * (lb.y - lt.y), ny = s * (lt.x - lb.x), n00 = nx * x0 + ny * y0, n10 = nx * x1 + ny * y0, n01 = nx * x0 + ny * y1, n11 = nx * x1 + ny * y1;
if (Math.max(n00, n10, n01, n11) <= nx * lt.x + ny * lt.y || Math.min(n00, n10, n01, n11) >= nx * rb.x + ny * rb.y)
return !1;
const mx = s * (lt.y - rt.y), my = s * (rt.x - lt.x), m00 = mx * x0 + my * y0, m10 = mx * x1 + my * y0, m01 = mx * x0 + my * y1, m11 = mx * x1 + my * y1;
return !(Math.max(m00, m10, m01, m11) <= mx * lt.x + my * lt.y || Math.min(m00, m10, m01, m11) >= mx * rb.x + my * rb.y);
}
/**
* Pads the rectangle making it grow in all directions.
* If paddingY is omitted, both paddingX and paddingY will be set to paddingX.
* @param paddingX - The horizontal padding amount.
* @param paddingY - The vertical padding amount.
* @returns Returns itself.
*/
pad(paddingX = 0, paddingY = paddingX) {
this.x -= paddingX;
this.y -= paddingY;
this.width += paddingX * 2;
this.height += paddingY * 2;
return this;
return this.x -= paddingX, this.y -= paddingY, this.width += paddingX * 2, this.height += paddingY * 2, this;
}
/**
* Fits this rectangle around the passed one.
* @param rectangle - The rectangle to fit.
* @returns Returns itself.
*/
fit(rectangle) {
const x1 = Math.max(this.x, rectangle.x);
const x2 = Math.min(this.x + this.width, rectangle.x + rectangle.width);
const y1 = Math.max(this.y, rectangle.y);
const y2 = Math.min(this.y + this.height, rectangle.y + rectangle.height);
this.x = x1;
this.width = Math.max(x2 - x1, 0);
this.y = y1;
this.height = Math.max(y2 - y1, 0);
return this;
const x1 = Math.max(this.x, rectangle.x), x2 = Math.min(this.x + this.width, rectangle.x + rectangle.width), y1 = Math.max(this.y, rectangle.y), y2 = Math.min(this.y + this.height, rectangle.y + rectangle.height);
return this.x = x1, this.width = Math.max(x2 - x1, 0), this.y = y1, this.height = Math.max(y2 - y1, 0), this;
}
/**
* Enlarges rectangle that way its corners lie on grid
* @param resolution - resolution
* @param eps - precision
* @returns Returns itself.
*/
ceil(resolution = 1, eps = 1e-3) {
const x2 = Math.ceil((this.x + this.width - eps) * resolution) / resolution;
const y2 = Math.ceil((this.y + this.height - eps) * resolution) / resolution;
this.x = Math.floor((this.x + eps) * resolution) / resolution;
this.y = Math.floor((this.y + eps) * resolution) / resolution;
this.width = x2 - this.x;
this.height = y2 - this.y;
return this;
const x2 = Math.ceil((this.x + this.width - eps) * resolution) / resolution, y2 = Math.ceil((this.y + this.height - eps) * resolution) / resolution;
return this.x = Math.floor((this.x + eps) * resolution) / resolution, this.y = Math.floor((this.y + eps) * resolution) / resolution, this.width = x2 - this.x, this.height = y2 - this.y, this;
}
/**
* Enlarges this rectangle to include the passed rectangle.
* @param rectangle - The rectangle to include.
* @returns Returns itself.
*/
enlarge(rectangle) {
const x1 = Math.min(this.x, rectangle.x);
const x2 = Math.max(this.x + this.width, rectangle.x + rectangle.width);
const y1 = Math.min(this.y, rectangle.y);
const y2 = Math.max(this.y + this.height, rectangle.y + rectangle.height);
this.x = x1;
this.width = x2 - x1;
this.y = y1;
this.height = y2 - y1;
return this;
const x1 = Math.min(this.x, rectangle.x), x2 = Math.max(this.x + this.width, rectangle.x + rectangle.width), y1 = Math.min(this.y, rectangle.y), y2 = Math.max(this.y + this.height, rectangle.y + rectangle.height);
return this.x = x1, this.width = x2 - x1, this.y = y1, this.height = y2 - y1, this;
}
toString() {
return `[@pixi/math:Rectangle x=${this.x} y=${this.y} width=${this.width} height=${this.height}]`;
}
}
Rectangle.prototype.toString = function() {
return `[@pixi/math:Rectangle x=${this.x} y=${this.y} width=${this.width} height=${this.height}]`;
};
exports.Rectangle = Rectangle;
//# sourceMappingURL=Rectangle.js.map

@@ -44,3 +44,2 @@ import { SHAPES } from '../const';

contains(x: number, y: number): boolean;
toString(): string;
}

@@ -1,57 +0,46 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var _const = require('../const.js');
"use strict";
var _const = require("../const.js");
class RoundedRectangle {
/**
* @param x - The X coordinate of the upper-left corner of the rounded rectangle
* @param y - The Y coordinate of the upper-left corner of the rounded rectangle
* @param width - The overall width of this rounded rectangle
* @param height - The overall height of this rounded rectangle
* @param radius - Controls the radius of the rounded corners
*/
constructor(x = 0, y = 0, width = 0, height = 0, radius = 20) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.radius = radius;
this.type = _const.SHAPES.RREC;
this.x = x, this.y = y, this.width = width, this.height = height, this.radius = radius, this.type = _const.SHAPES.RREC;
}
/**
* Creates a clone of this Rounded Rectangle.
* @returns - A copy of the rounded rectangle.
*/
clone() {
return new RoundedRectangle(this.x, this.y, this.width, this.height, this.radius);
}
/**
* Checks whether the x and y coordinates given are contained within this Rounded Rectangle
* @param x - The X coordinate of the point to test.
* @param y - The Y coordinate of the point to test.
* @returns - Whether the x/y coordinates are within this Rounded Rectangle.
*/
contains(x, y) {
if (this.width <= 0 || this.height <= 0) {
return false;
if (this.width <= 0 || this.height <= 0)
return !1;
if (x >= this.x && x <= this.x + this.width && y >= this.y && y <= this.y + this.height) {
const radius = Math.max(0, Math.min(this.radius, Math.min(this.width, this.height) / 2));
if (y >= this.y + radius && y <= this.y + this.height - radius || x >= this.x + radius && x <= this.x + this.width - radius)
return !0;
let dx = x - (this.x + radius), dy = y - (this.y + radius);
const radius2 = radius * radius;
if (dx * dx + dy * dy <= radius2 || (dx = x - (this.x + this.width - radius), dx * dx + dy * dy <= radius2) || (dy = y - (this.y + this.height - radius), dx * dx + dy * dy <= radius2) || (dx = x - (this.x + radius), dx * dx + dy * dy <= radius2))
return !0;
}
if (x >= this.x && x <= this.x + this.width) {
if (y >= this.y && y <= this.y + this.height) {
const radius = Math.max(0, Math.min(this.radius, Math.min(this.width, this.height) / 2));
if (y >= this.y + radius && y <= this.y + this.height - radius || x >= this.x + radius && x <= this.x + this.width - radius) {
return true;
}
let dx = x - (this.x + radius);
let dy = y - (this.y + radius);
const radius2 = radius * radius;
if (dx * dx + dy * dy <= radius2) {
return true;
}
dx = x - (this.x + this.width - radius);
if (dx * dx + dy * dy <= radius2) {
return true;
}
dy = y - (this.y + this.height - radius);
if (dx * dx + dy * dy <= radius2) {
return true;
}
dx = x - (this.x + radius);
if (dx * dx + dy * dy <= radius2) {
return true;
}
}
}
return false;
return !1;
}
toString() {
return `[@pixi/math:RoundedRectangle x=${this.x} y=${this.y}width=${this.width} height=${this.height} radius=${this.radius}]`;
}
}
RoundedRectangle.prototype.toString = function() {
return `[@pixi/math:RoundedRectangle x=${this.x} y=${this.y}width=${this.width} height=${this.height} radius=${this.radius}]`;
};
exports.RoundedRectangle = RoundedRectangle;
//# sourceMappingURL=RoundedRectangle.js.map

@@ -63,3 +63,2 @@ import { Matrix } from './Matrix';

protected updateSkew(): void;
toString(): string;
/** Updates the local transformation matrix. */

@@ -66,0 +65,0 @@ updateLocalTransform(): void;

@@ -1,81 +0,39 @@

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var Matrix = require('./Matrix.js');
var ObservablePoint = require('./ObservablePoint.js');
"use strict";
var Matrix = require("./Matrix.js"), ObservablePoint = require("./ObservablePoint.js");
const _Transform = class {
constructor() {
this.worldTransform = new Matrix.Matrix();
this.localTransform = new Matrix.Matrix();
this.position = new ObservablePoint.ObservablePoint(this.onChange, this, 0, 0);
this.scale = new ObservablePoint.ObservablePoint(this.onChange, this, 1, 1);
this.pivot = new ObservablePoint.ObservablePoint(this.onChange, this, 0, 0);
this.skew = new ObservablePoint.ObservablePoint(this.updateSkew, this, 0, 0);
this._rotation = 0;
this._cx = 1;
this._sx = 0;
this._cy = 0;
this._sy = 1;
this._localID = 0;
this._currentLocalID = 0;
this._worldID = 0;
this._parentID = 0;
this.worldTransform = new Matrix.Matrix(), this.localTransform = new Matrix.Matrix(), this.position = new ObservablePoint.ObservablePoint(this.onChange, this, 0, 0), this.scale = new ObservablePoint.ObservablePoint(this.onChange, this, 1, 1), this.pivot = new ObservablePoint.ObservablePoint(this.onChange, this, 0, 0), this.skew = new ObservablePoint.ObservablePoint(this.updateSkew, this, 0, 0), this._rotation = 0, this._cx = 1, this._sx = 0, this._cy = 0, this._sy = 1, this._localID = 0, this._currentLocalID = 0, this._worldID = 0, this._parentID = 0;
}
/** Called when a value changes. */
onChange() {
this._localID++;
}
/** Called when the skew or the rotation changes. */
updateSkew() {
this._cx = Math.cos(this._rotation + this.skew.y);
this._sx = Math.sin(this._rotation + this.skew.y);
this._cy = -Math.sin(this._rotation - this.skew.x);
this._sy = Math.cos(this._rotation - this.skew.x);
this._localID++;
this._cx = Math.cos(this._rotation + this.skew.y), this._sx = Math.sin(this._rotation + this.skew.y), this._cy = -Math.sin(this._rotation - this.skew.x), this._sy = Math.cos(this._rotation - this.skew.x), this._localID++;
}
toString() {
return `[@pixi/math:Transform position=(${this.position.x}, ${this.position.y}) rotation=${this.rotation} scale=(${this.scale.x}, ${this.scale.y}) skew=(${this.skew.x}, ${this.skew.y}) ]`;
}
/** Updates the local transformation matrix. */
updateLocalTransform() {
const lt = this.localTransform;
if (this._localID !== this._currentLocalID) {
lt.a = this._cx * this.scale.x;
lt.b = this._sx * this.scale.x;
lt.c = this._cy * this.scale.y;
lt.d = this._sy * this.scale.y;
lt.tx = this.position.x - (this.pivot.x * lt.a + this.pivot.y * lt.c);
lt.ty = this.position.y - (this.pivot.x * lt.b + this.pivot.y * lt.d);
this._currentLocalID = this._localID;
this._parentID = -1;
}
this._localID !== this._currentLocalID && (lt.a = this._cx * this.scale.x, lt.b = this._sx * this.scale.x, lt.c = this._cy * this.scale.y, lt.d = this._sy * this.scale.y, lt.tx = this.position.x - (this.pivot.x * lt.a + this.pivot.y * lt.c), lt.ty = this.position.y - (this.pivot.x * lt.b + this.pivot.y * lt.d), this._currentLocalID = this._localID, this._parentID = -1);
}
/**
* Updates the local and the world transformation matrices.
* @param parentTransform - The parent transform
*/
updateTransform(parentTransform) {
const lt = this.localTransform;
if (this._localID !== this._currentLocalID) {
lt.a = this._cx * this.scale.x;
lt.b = this._sx * this.scale.x;
lt.c = this._cy * this.scale.y;
lt.d = this._sy * this.scale.y;
lt.tx = this.position.x - (this.pivot.x * lt.a + this.pivot.y * lt.c);
lt.ty = this.position.y - (this.pivot.x * lt.b + this.pivot.y * lt.d);
this._currentLocalID = this._localID;
this._parentID = -1;
if (this._localID !== this._currentLocalID && (lt.a = this._cx * this.scale.x, lt.b = this._sx * this.scale.x, lt.c = this._cy * this.scale.y, lt.d = this._sy * this.scale.y, lt.tx = this.position.x - (this.pivot.x * lt.a + this.pivot.y * lt.c), lt.ty = this.position.y - (this.pivot.x * lt.b + this.pivot.y * lt.d), this._currentLocalID = this._localID, this._parentID = -1), this._parentID !== parentTransform._worldID) {
const pt = parentTransform.worldTransform, wt = this.worldTransform;
wt.a = lt.a * pt.a + lt.b * pt.c, wt.b = lt.a * pt.b + lt.b * pt.d, wt.c = lt.c * pt.a + lt.d * pt.c, wt.d = lt.c * pt.b + lt.d * pt.d, wt.tx = lt.tx * pt.a + lt.ty * pt.c + pt.tx, wt.ty = lt.tx * pt.b + lt.ty * pt.d + pt.ty, this._parentID = parentTransform._worldID, this._worldID++;
}
if (this._parentID !== parentTransform._worldID) {
const pt = parentTransform.worldTransform;
const wt = this.worldTransform;
wt.a = lt.a * pt.a + lt.b * pt.c;
wt.b = lt.a * pt.b + lt.b * pt.d;
wt.c = lt.c * pt.a + lt.d * pt.c;
wt.d = lt.c * pt.b + lt.d * pt.d;
wt.tx = lt.tx * pt.a + lt.ty * pt.c + pt.tx;
wt.ty = lt.tx * pt.b + lt.ty * pt.d + pt.ty;
this._parentID = parentTransform._worldID;
this._worldID++;
}
}
/**
* Decomposes a matrix and sets the transforms properties based on it.
* @param matrix - The matrix to decompose
*/
setFromMatrix(matrix) {
matrix.decompose(this);
this._localID++;
matrix.decompose(this), this._localID++;
}
/** The rotation of the object in radians. */
get rotation() {

@@ -85,12 +43,11 @@ return this._rotation;

set rotation(value) {
if (this._rotation !== value) {
this._rotation = value;
this.updateSkew();
}
this._rotation !== value && (this._rotation = value, this.updateSkew());
}
};
_Transform.IDENTITY = new _Transform();
let Transform = _Transform;
Transform.IDENTITY = new _Transform();
Transform.prototype.toString = function() {
return `[@pixi/math:Transform position=(${this.position.x}, ${this.position.y}) rotation=${this.rotation} scale=(${this.scale.x}, ${this.scale.y}) skew=(${this.skew.x}, ${this.skew.y}) ]`;
};
exports.Transform = Transform;
//# sourceMappingURL=Transform.js.map
{
"name": "@pixi/math",
"version": "7.2.4",
"version": "7.3.0-rc",
"main": "lib/index.js",

@@ -5,0 +5,0 @@ "module": "lib/index.mjs",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc