Socket
Socket
Sign inDemoInstall

@pixi/math

Package Overview
Dependencies
Maintainers
3
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 6.5.3 to 7.0.0-alpha

2315

dist/cjs/math.js
/*!
* @pixi/math - v6.5.3
* Compiled Fri, 09 Sep 2022 13:55:20 UTC
* @pixi/math - v7.0.0-alpha
* Compiled Fri, 09 Sep 2022 16:09:18 UTC
*

@@ -12,1577 +12,793 @@ * @pixi/math is licensed under the MIT License.

/**
* Two Pi.
* @static
* @member {number}
* @memberof PIXI
*/
var PI_2 = Math.PI * 2;
/**
* Conversion factor for converting radians to degrees.
* @static
* @member {number} RAD_TO_DEG
* @memberof PIXI
*/
var RAD_TO_DEG = 180 / Math.PI;
/**
* Conversion factor for converting degrees to radians.
* @static
* @member {number}
* @memberof PIXI
*/
var DEG_TO_RAD = Math.PI / 180;
/**
* Constants that identify shapes, mainly to prevent `instanceof` calls.
* @static
* @memberof PIXI
* @enum {number}
* @property {number} POLY Polygon
* @property {number} RECT Rectangle
* @property {number} CIRC Circle
* @property {number} ELIP Ellipse
* @property {number} RREC Rounded Rectangle
*/
exports.SHAPES = void 0;
(function (SHAPES) {
SHAPES[SHAPES["POLY"] = 0] = "POLY";
SHAPES[SHAPES["RECT"] = 1] = "RECT";
SHAPES[SHAPES["CIRC"] = 2] = "CIRC";
SHAPES[SHAPES["ELIP"] = 3] = "ELIP";
SHAPES[SHAPES["RREC"] = 4] = "RREC";
})(exports.SHAPES || (exports.SHAPES = {}));
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 || {});
/**
* The Point object represents a location in a two-dimensional coordinate system, where `x` represents
* the position on the horizontal axis and `y` represents the position on the vertical axis
* @class
* @memberof PIXI
* @implements {IPoint}
*/
var Point = /** @class */ (function () {
/**
* 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
*/
function Point(x, y) {
if (x === void 0) { x = 0; }
if (y === void 0) { y = 0; }
/** Position of the point on the x axis */
this.x = 0;
/** Position of the point on the y axis */
this.y = 0;
this.x = x;
this.y = y;
}
/**
* Creates a clone of this point
* @returns A clone of this point
*/
Point.prototype.clone = function () {
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
*/
Point.prototype.copyFrom = function (p) {
this.set(p.x, p.y);
return 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
*/
Point.prototype.copyTo = function (p) {
p.set(this.x, this.y);
return 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
*/
Point.prototype.equals = function (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
*/
Point.prototype.set = function (x, y) {
if (x === void 0) { x = 0; }
if (y === void 0) { y = x; }
this.x = x;
this.y = y;
return this;
};
Point.prototype.toString = function () {
return "[@pixi/math:Point x=" + this.x + " y=" + this.y + "]";
};
return Point;
}());
class Point {
constructor(x = 0, y = 0) {
this.x = 0;
this.y = 0;
this.x = x;
this.y = y;
}
clone() {
return new Point(this.x, this.y);
}
copyFrom(p) {
this.set(p.x, p.y);
return this;
}
copyTo(p) {
p.set(this.x, this.y);
return p;
}
equals(p) {
return p.x === this.x && p.y === this.y;
}
set(x = 0, y = x) {
this.x = x;
this.y = y;
return this;
}
toString() {
return `[@pixi/math:Point x=${this.x} y=${this.y}]`;
}
}
var tempPoints = [new Point(), new Point(), new Point(), new Point()];
/**
* Size object, contains width and height
* @memberof PIXI
* @typedef {object} ISize
* @property {number} width - Width component
* @property {number} height - Height component
*/
/**
* Rectangle object is an area defined by its position, as indicated by its top-left corner
* point (x, y) and by its width and its height.
* @memberof PIXI
*/
var Rectangle = /** @class */ (function () {
/**
* @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
*/
function Rectangle(x, y, width, height) {
if (x === void 0) { x = 0; }
if (y === void 0) { y = 0; }
if (width === void 0) { width = 0; }
if (height === void 0) { height = 0; }
this.x = Number(x);
this.y = Number(y);
this.width = Number(width);
this.height = Number(height);
this.type = exports.SHAPES.RECT;
const tempPoints = [new Point(), new Point(), new Point(), new Point()];
class 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 = SHAPES.RECT;
}
get left() {
return this.x;
}
get right() {
return this.x + this.width;
}
get top() {
return this.y;
}
get bottom() {
return this.y + this.height;
}
static get EMPTY() {
return new Rectangle(0, 0, 0, 0);
}
clone() {
return new Rectangle(this.x, this.y, this.width, this.height);
}
copyFrom(rectangle) {
this.x = rectangle.x;
this.y = rectangle.y;
this.width = rectangle.width;
this.height = rectangle.height;
return this;
}
copyTo(rectangle) {
rectangle.x = this.x;
rectangle.y = this.y;
rectangle.width = this.width;
rectangle.height = this.height;
return rectangle;
}
contains(x, y) {
if (this.width <= 0 || this.height <= 0) {
return false;
}
Object.defineProperty(Rectangle.prototype, "left", {
/** Returns the left edge of the rectangle. */
get: function () {
return this.x;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Rectangle.prototype, "right", {
/** Returns the right edge of the rectangle. */
get: function () {
return this.x + this.width;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Rectangle.prototype, "top", {
/** Returns the top edge of the rectangle. */
get: function () {
return this.y;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Rectangle.prototype, "bottom", {
/** Returns the bottom edge of the rectangle. */
get: function () {
return this.y + this.height;
},
enumerable: false,
configurable: true
});
Object.defineProperty(Rectangle, "EMPTY", {
/** A constant empty rectangle. */
get: function () {
return new Rectangle(0, 0, 0, 0);
},
enumerable: false,
configurable: true
});
/**
* Creates a clone of this Rectangle
* @returns a copy of the rectangle
*/
Rectangle.prototype.clone = function () {
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.
*/
Rectangle.prototype.copyFrom = function (rectangle) {
this.x = rectangle.x;
this.y = rectangle.y;
this.width = rectangle.width;
this.height = rectangle.height;
return this;
};
/**
* Copies this rectangle to another one.
* @param rectangle - The rectangle to copy to.
* @returns Returns given parameter.
*/
Rectangle.prototype.copyTo = function (rectangle) {
rectangle.x = this.x;
rectangle.y = this.y;
rectangle.width = this.width;
rectangle.height = this.height;
return 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
*/
Rectangle.prototype.contains = function (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;
};
/**
* 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`.
*/
Rectangle.prototype.intersects = function (other, transform) {
if (!transform) {
var x0_1 = this.x < other.x ? other.x : this.x;
var x1_1 = this.right > other.right ? other.right : this.right;
if (x1_1 <= x0_1) {
return false;
}
var y0_1 = this.y < other.y ? other.y : this.y;
var y1_1 = this.bottom > other.bottom ? other.bottom : this.bottom;
return y1_1 > y0_1;
}
var x0 = this.left;
var x1 = this.right;
var y0 = this.top;
var y1 = this.bottom;
if (x1 <= x0 || y1 <= y0) {
return false;
}
var lt = tempPoints[0].set(other.left, other.top);
var lb = tempPoints[1].set(other.left, other.bottom);
var rt = tempPoints[2].set(other.right, other.top);
var rb = tempPoints[3].set(other.right, other.bottom);
if (rt.x <= lt.x || lb.y <= lt.y) {
return false;
}
var 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;
}
var nx = s * (lb.y - lt.y);
var ny = s * (lt.x - lb.x);
var n00 = (nx * x0) + (ny * y0);
var n10 = (nx * x1) + (ny * y0);
var n01 = (nx * x0) + (ny * y1);
var 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;
}
var mx = s * (lt.y - rt.y);
var my = s * (rt.x - lt.x);
var m00 = (mx * x0) + (my * y0);
var m10 = (mx * x1) + (my * y0);
var m01 = (mx * x0) + (my * y1);
var 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;
}
if (x >= this.x && x < this.x + this.width) {
if (y >= this.y && y < this.y + this.height) {
return true;
};
/**
* 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.
*/
Rectangle.prototype.pad = function (paddingX, paddingY) {
if (paddingX === void 0) { paddingX = 0; }
if (paddingY === void 0) { paddingY = paddingX; }
this.x -= paddingX;
this.y -= paddingY;
this.width += paddingX * 2;
this.height += paddingY * 2;
return this;
};
/**
* Fits this rectangle around the passed one.
* @param rectangle - The rectangle to fit.
* @returns Returns itself.
*/
Rectangle.prototype.fit = function (rectangle) {
var x1 = Math.max(this.x, rectangle.x);
var x2 = Math.min(this.x + this.width, rectangle.x + rectangle.width);
var y1 = Math.max(this.y, rectangle.y);
var 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;
};
/**
* Enlarges rectangle that way its corners lie on grid
* @param resolution - resolution
* @param eps - precision
* @returns Returns itself.
*/
Rectangle.prototype.ceil = function (resolution, eps) {
if (resolution === void 0) { resolution = 1; }
if (eps === void 0) { eps = 0.001; }
var x2 = Math.ceil((this.x + this.width - eps) * resolution) / resolution;
var 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;
};
/**
* Enlarges this rectangle to include the passed rectangle.
* @param rectangle - The rectangle to include.
* @returns Returns itself.
*/
Rectangle.prototype.enlarge = function (rectangle) {
var x1 = Math.min(this.x, rectangle.x);
var x2 = Math.max(this.x + this.width, rectangle.x + rectangle.width);
var y1 = Math.min(this.y, rectangle.y);
var 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;
};
Rectangle.prototype.toString = function () {
return "[@pixi/math:Rectangle x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height + "]";
};
return Rectangle;
}());
/**
* The Circle object is used to help draw graphics and can also be used to specify a hit area for displayObjects.
* @memberof PIXI
*/
var Circle = /** @class */ (function () {
/**
* @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
*/
function Circle(x, y, radius) {
if (x === void 0) { x = 0; }
if (y === void 0) { y = 0; }
if (radius === void 0) { radius = 0; }
this.x = x;
this.y = y;
this.radius = radius;
this.type = exports.SHAPES.CIRC;
}
}
/**
* Creates a clone of this Circle instance
* @returns A copy of the Circle
*/
Circle.prototype.clone = function () {
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
*/
Circle.prototype.contains = function (x, y) {
if (this.radius <= 0) {
return false;
}
var r2 = this.radius * this.radius;
var dx = (this.x - x);
var dy = (this.y - y);
dx *= dx;
dy *= dy;
return (dx + dy <= r2);
};
/**
* Returns the framing rectangle of the circle as a Rectangle object
* @returns The framing rectangle
*/
Circle.prototype.getBounds = function () {
return new Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2);
};
Circle.prototype.toString = function () {
return "[@pixi/math:Circle x=" + this.x + " y=" + this.y + " radius=" + this.radius + "]";
};
return Circle;
}());
/**
* The Ellipse object is used to help draw graphics and can also be used to specify a hit area for displayObjects.
* @memberof PIXI
*/
var Ellipse = /** @class */ (function () {
/**
* @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
*/
function Ellipse(x, y, halfWidth, halfHeight) {
if (x === void 0) { x = 0; }
if (y === void 0) { y = 0; }
if (halfWidth === void 0) { halfWidth = 0; }
if (halfHeight === void 0) { halfHeight = 0; }
this.x = x;
this.y = y;
this.width = halfWidth;
this.height = halfHeight;
this.type = exports.SHAPES.ELIP;
return 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;
}
const y02 = this.y < other.y ? other.y : this.y;
const y12 = this.bottom > other.bottom ? other.bottom : this.bottom;
return y12 > y02;
}
/**
* Creates a clone of this Ellipse instance
* @returns {PIXI.Ellipse} A copy of the ellipse
*/
Ellipse.prototype.clone = function () {
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
*/
Ellipse.prototype.contains = function (x, y) {
if (this.width <= 0 || this.height <= 0) {
return false;
}
// normalize the coords to an ellipse with center 0,0
var normx = ((x - this.x) / this.width);
var normy = ((y - this.y) / this.height);
normx *= normx;
normy *= normy;
return (normx + normy <= 1);
};
/**
* Returns the framing rectangle of the ellipse as a Rectangle object
* @returns The framing rectangle
*/
Ellipse.prototype.getBounds = function () {
return new Rectangle(this.x - this.width, this.y - this.height, this.width, this.height);
};
Ellipse.prototype.toString = function () {
return "[@pixi/math:Ellipse x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height + "]";
};
return Ellipse;
}());
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 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;
}
pad(paddingX = 0, paddingY = paddingX) {
this.x -= paddingX;
this.y -= paddingY;
this.width += paddingX * 2;
this.height += paddingY * 2;
return this;
}
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;
}
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;
}
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;
}
toString() {
return `[@pixi/math:Rectangle x=${this.x} y=${this.y} width=${this.width} height=${this.height}]`;
}
}
/**
* A class to define a shape via user defined coordinates.
* @memberof PIXI
*/
var Polygon = /** @class */ (function () {
/**
* @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 PIXI.Polygon(new PIXI.Point(), new PIXI.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.
*/
function Polygon() {
var arguments$1 = arguments;
var points = [];
for (var _i = 0; _i < arguments.length; _i++) {
points[_i] = arguments$1[_i];
}
var flat = Array.isArray(points[0]) ? points[0] : points;
// if this is an array of points, convert it to a flat array of numbers
if (typeof flat[0] !== 'number') {
var p = [];
for (var i = 0, il = flat.length; i < il; i++) {
p.push(flat[i].x, flat[i].y);
}
flat = p;
}
this.points = flat;
this.type = exports.SHAPES.POLY;
this.closeStroke = true;
class Circle {
constructor(x = 0, y = 0, radius = 0) {
this.x = x;
this.y = y;
this.radius = radius;
this.type = SHAPES.CIRC;
}
clone() {
return new Circle(this.x, this.y, this.radius);
}
contains(x, y) {
if (this.radius <= 0) {
return false;
}
/**
* Creates a clone of this polygon.
* @returns - A copy of the polygon.
*/
Polygon.prototype.clone = function () {
var points = this.points.slice();
var polygon = new Polygon(points);
polygon.closeStroke = this.closeStroke;
return 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.
*/
Polygon.prototype.contains = function (x, y) {
var inside = false;
// use some raycasting to test hits
// https://github.com/substack/point-in-polygon/blob/master/index.js
var length = this.points.length / 2;
for (var i = 0, j = length - 1; i < length; j = i++) {
var xi = this.points[i * 2];
var yi = this.points[(i * 2) + 1];
var xj = this.points[j * 2];
var yj = this.points[(j * 2) + 1];
var intersect = ((yi > y) !== (yj > y)) && (x < ((xj - xi) * ((y - yi) / (yj - yi))) + xi);
if (intersect) {
inside = !inside;
}
}
return inside;
};
Polygon.prototype.toString = function () {
return "[@pixi/math:Polygon"
+ ("closeStroke=" + this.closeStroke)
+ ("points=" + this.points.reduce(function (pointsDesc, currentPoint) { return pointsDesc + ", " + currentPoint; }, '') + "]");
};
return Polygon;
}());
const r2 = this.radius * this.radius;
let dx = this.x - x;
let dy = this.y - y;
dx *= dx;
dy *= dy;
return dx + dy <= r2;
}
getBounds() {
return new 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}]`;
}
}
/**
* The Rounded Rectangle object is an area that has nice rounded corners, as indicated by its
* top-left corner point (x, y) and by its width and its height and its radius.
* @memberof PIXI
*/
var RoundedRectangle = /** @class */ (function () {
/**
* @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
*/
function RoundedRectangle(x, y, width, height, radius) {
if (x === void 0) { x = 0; }
if (y === void 0) { y = 0; }
if (width === void 0) { width = 0; }
if (height === void 0) { height = 0; }
if (radius === void 0) { radius = 20; }
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.radius = radius;
this.type = exports.SHAPES.RREC;
class Ellipse {
constructor(x = 0, y = 0, halfWidth = 0, halfHeight = 0) {
this.x = x;
this.y = y;
this.width = halfWidth;
this.height = halfHeight;
this.type = SHAPES.ELIP;
}
clone() {
return new Ellipse(this.x, this.y, this.width, this.height);
}
contains(x, y) {
if (this.width <= 0 || this.height <= 0) {
return false;
}
/**
* Creates a clone of this Rounded Rectangle.
* @returns - A copy of the rounded rectangle.
*/
RoundedRectangle.prototype.clone = function () {
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.
*/
RoundedRectangle.prototype.contains = function (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) {
var 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;
}
var dx = x - (this.x + radius);
var dy = y - (this.y + radius);
var 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;
};
RoundedRectangle.prototype.toString = function () {
return "[@pixi/math:RoundedRectangle x=" + this.x + " y=" + this.y
+ ("width=" + this.width + " height=" + this.height + " radius=" + this.radius + "]");
};
return RoundedRectangle;
}());
let normx = (x - this.x) / this.width;
let normy = (y - this.y) / this.height;
normx *= normx;
normy *= normy;
return normx + normy <= 1;
}
getBounds() {
return new 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}]`;
}
}
/**
* The ObservablePoint object represents a location in a two-dimensional coordinate system, where `x` represents
* the position on the horizontal axis and `y` represents the position on the vertical axis.
*
* An `ObservablePoint` is a point that triggers a callback when the point's position is changed.
* @memberof PIXI
*/
var ObservablePoint = /** @class */ (function () {
/**
* 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
*/
function ObservablePoint(cb, scope, x, y) {
if (x === void 0) { x = 0; }
if (y === void 0) { y = 0; }
this._x = x;
this._y = y;
this.cb = cb;
this.scope = scope;
class Polygon {
constructor(...points) {
let flat = Array.isArray(points[0]) ? points[0] : points;
if (typeof flat[0] !== "number") {
const p = [];
for (let i = 0, il = flat.length; i < il; i++) {
p.push(flat[i].x, flat[i].y);
}
flat = p;
}
/**
* 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
*/
ObservablePoint.prototype.clone = function (cb, scope) {
if (cb === void 0) { cb = this.cb; }
if (scope === void 0) { 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
*/
ObservablePoint.prototype.set = function (x, y) {
if (x === void 0) { x = 0; }
if (y === void 0) { y = x; }
if (this._x !== x || this._y !== y) {
this._x = x;
this._y = y;
this.cb.call(this.scope);
}
return 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
*/
ObservablePoint.prototype.copyFrom = function (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;
};
/**
* 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
*/
ObservablePoint.prototype.copyTo = function (p) {
p.set(this._x, this._y);
return 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
*/
ObservablePoint.prototype.equals = function (p) {
return (p.x === this._x) && (p.y === this._y);
};
ObservablePoint.prototype.toString = function () {
return "[@pixi/math:ObservablePoint x=" + 0 + " y=" + 0 + " scope=" + this.scope + "]";
};
Object.defineProperty(ObservablePoint.prototype, "x", {
/** Position of the observable point on the x axis. */
get: function () {
return this._x;
},
set: function (value) {
if (this._x !== value) {
this._x = value;
this.cb.call(this.scope);
}
},
enumerable: false,
configurable: true
});
Object.defineProperty(ObservablePoint.prototype, "y", {
/** Position of the observable point on the y axis. */
get: function () {
return this._y;
},
set: function (value) {
if (this._y !== value) {
this._y = value;
this.cb.call(this.scope);
}
},
enumerable: false,
configurable: true
});
return ObservablePoint;
}());
this.points = flat;
this.type = SHAPES.POLY;
this.closeStroke = true;
}
clone() {
const points = this.points.slice();
const polygon = new Polygon(points);
polygon.closeStroke = this.closeStroke;
return polygon;
}
contains(x, y) {
let inside = false;
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;
}
}
return inside;
}
toString() {
return `[@pixi/math:PolygoncloseStroke=${this.closeStroke}points=${this.points.reduce((pointsDesc, currentPoint) => `${pointsDesc}, ${currentPoint}`, "")}]`;
}
}
/**
* The PixiJS Matrix as a class makes it a lot faster.
*
* Here is a representation of it:
* ```js
* | a | c | tx|
* | b | d | ty|
* | 0 | 0 | 1 |
* ```
* @memberof PIXI
*/
var Matrix = /** @class */ (function () {
/**
* @param a - x scale
* @param b - y skew
* @param c - x skew
* @param d - y scale
* @param tx - x translation
* @param ty - y translation
*/
function Matrix(a, b, c, d, tx, ty) {
if (a === void 0) { a = 1; }
if (b === void 0) { b = 0; }
if (c === void 0) { c = 0; }
if (d === void 0) { d = 1; }
if (tx === void 0) { tx = 0; }
if (ty === void 0) { ty = 0; }
this.array = null;
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.tx = tx;
this.ty = ty;
class RoundedRectangle {
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 = SHAPES.RREC;
}
clone() {
return new RoundedRectangle(this.x, this.y, this.width, this.height, this.radius);
}
contains(x, y) {
if (this.width <= 0 || this.height <= 0) {
return false;
}
/**
* 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.
*/
Matrix.prototype.fromArray = function (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];
};
/**
* 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.
*/
Matrix.prototype.set = function (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;
};
/**
* 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
*/
Matrix.prototype.toArray = function (transpose, out) {
if (!this.array) {
this.array = new Float32Array(9);
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;
}
var 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;
let dx = x - (this.x + radius);
let dy = y - (this.y + radius);
const radius2 = radius * radius;
if (dx * dx + dy * dy <= radius2) {
return true;
}
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;
dx = x - (this.x + this.width - radius);
if (dx * dx + dy * dy <= radius2) {
return true;
}
return 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
*/
Matrix.prototype.apply = function (pos, newPos) {
newPos = (newPos || new Point());
var x = pos.x;
var 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;
};
/**
* 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
*/
Matrix.prototype.applyInverse = function (pos, newPos) {
newPos = (newPos || new Point());
var id = 1 / ((this.a * this.d) + (this.c * -this.b));
var x = pos.x;
var 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;
};
/**
* 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.
*/
Matrix.prototype.translate = function (x, y) {
this.tx += x;
this.ty += y;
return 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.
*/
Matrix.prototype.scale = function (x, y) {
this.a *= x;
this.d *= y;
this.c *= x;
this.b *= y;
this.tx *= x;
this.ty *= y;
return this;
};
/**
* Applies a rotation transformation to the matrix.
* @param angle - The angle in radians.
* @returns This matrix. Good for chaining method calls.
*/
Matrix.prototype.rotate = function (angle) {
var cos = Math.cos(angle);
var sin = Math.sin(angle);
var a1 = this.a;
var c1 = this.c;
var 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;
};
/**
* Appends the given Matrix to this Matrix.
* @param matrix - The matrix to append.
* @returns This matrix. Good for chaining method calls.
*/
Matrix.prototype.append = function (matrix) {
var a1 = this.a;
var b1 = this.b;
var c1 = this.c;
var 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;
};
/**
* 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.
*/
Matrix.prototype.setTransform = function (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;
};
/**
* Prepends the given Matrix to this Matrix.
* @param matrix - The matrix to prepend
* @returns This matrix. Good for chaining method calls.
*/
Matrix.prototype.prepend = function (matrix) {
var tx1 = this.tx;
if (matrix.a !== 1 || matrix.b !== 0 || matrix.c !== 0 || matrix.d !== 1) {
var a1 = this.a;
var 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);
dy = y - (this.y + this.height - radius);
if (dx * dx + dy * dy <= radius2) {
return true;
}
this.tx = (tx1 * matrix.a) + (this.ty * matrix.c) + matrix.tx;
this.ty = (tx1 * matrix.b) + (this.ty * matrix.d) + matrix.ty;
return 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
*/
Matrix.prototype.decompose = function (transform) {
// sort out rotation / skew..
var a = this.a;
var b = this.b;
var c = this.c;
var d = this.d;
var pivot = transform.pivot;
var skewX = -Math.atan2(-c, d);
var skewY = Math.atan2(b, a);
var delta = Math.abs(skewX + skewY);
if (delta < 0.00001 || Math.abs(PI_2 - delta) < 0.00001) {
transform.rotation = skewY;
transform.skew.x = transform.skew.y = 0;
dx = x - (this.x + radius);
if (dx * dx + dy * dy <= radius2) {
return true;
}
else {
transform.rotation = 0;
transform.skew.x = skewX;
transform.skew.y = skewY;
}
// next set scale
transform.scale.x = Math.sqrt((a * a) + (b * b));
transform.scale.y = Math.sqrt((c * c) + (d * d));
// next set position
transform.position.x = this.tx + ((pivot.x * a) + (pivot.y * c));
transform.position.y = this.ty + ((pivot.x * b) + (pivot.y * d));
return transform;
};
/**
* Inverts this matrix
* @returns This matrix. Good for chaining method calls.
*/
Matrix.prototype.invert = function () {
var a1 = this.a;
var b1 = this.b;
var c1 = this.c;
var d1 = this.d;
var tx1 = this.tx;
var 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;
};
/**
* Resets this Matrix to an identity (default) matrix.
* @returns This matrix. Good for chaining method calls.
*/
Matrix.prototype.identity = function () {
this.a = 1;
this.b = 0;
this.c = 0;
this.d = 1;
this.tx = 0;
this.ty = 0;
return this;
};
/**
* Creates a new Matrix object with the same values as this one.
* @returns A copy of this matrix. Good for chaining method calls.
*/
Matrix.prototype.clone = function () {
var 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;
};
/**
* 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.
*/
Matrix.prototype.copyTo = function (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;
};
/**
* 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
*/
Matrix.prototype.copyFrom = function (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;
};
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 + "]";
};
Object.defineProperty(Matrix, "IDENTITY", {
/**
* A default (identity) matrix
* @readonly
*/
get: function () {
return new Matrix();
},
enumerable: false,
configurable: true
});
Object.defineProperty(Matrix, "TEMP_MATRIX", {
/**
* A temp matrix
* @readonly
*/
get: function () {
return new Matrix();
},
enumerable: false,
configurable: true
});
return Matrix;
}());
}
}
return false;
}
toString() {
return `[@pixi/math:RoundedRectangle x=${this.x} y=${this.y}width=${this.width} height=${this.height} radius=${this.radius}]`;
}
}
// Your friendly neighbour https://en.wikipedia.org/wiki/Dihedral_group
/*
* Transform matrix for operation n is:
* | ux | vx |
* | uy | vy |
*/
var ux = [1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1];
var uy = [0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 1, 1, 0, -1, -1, -1];
var vx = [0, -1, -1, -1, 0, 1, 1, 1, 0, 1, 1, 1, 0, -1, -1, -1];
var vy = [1, 1, 0, -1, -1, -1, 0, 1, -1, -1, 0, 1, 1, 1, 0, -1];
/**
* [Cayley Table]{@link https://en.wikipedia.org/wiki/Cayley_table}
* for the composition of each rotation in the dihederal group D8.
* @type {number[][]}
* @private
*/
var rotationCayley = [];
/**
* Matrices for each `GD8Symmetry` rotation.
* @type {PIXI.Matrix[]}
* @private
*/
var rotationMatrices = [];
/*
* Alias for {@code Math.sign}.
*/
var signum = Math.sign;
/*
* Initializes `rotationCayley` and `rotationMatrices`. It is called
* only once below.
*/
class ObservablePoint {
constructor(cb, scope, x = 0, y = 0) {
this._x = x;
this._y = y;
this.cb = cb;
this.scope = scope;
}
clone(cb = this.cb, scope = this.scope) {
return new ObservablePoint(cb, scope, this._x, this._y);
}
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;
}
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;
}
copyTo(p) {
p.set(this._x, this._y);
return p;
}
equals(p) {
return p.x === this._x && p.y === this._y;
}
toString() {
return `[@pixi/math:ObservablePoint x=${0} y=${0} scope=${this.scope}]`;
}
get x() {
return this._x;
}
set x(value) {
if (this._x !== value) {
this._x = value;
this.cb.call(this.scope);
}
}
get y() {
return this._y;
}
set y(value) {
if (this._y !== value) {
this._y = value;
this.cb.call(this.scope);
}
}
}
class Matrix {
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;
}
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];
}
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;
}
toArray(transpose, out) {
if (!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;
}
apply(pos, newPos) {
newPos = newPos || new 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;
}
applyInverse(pos, newPos) {
newPos = newPos || new 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;
}
translate(x, y) {
this.tx += x;
this.ty += y;
return this;
}
scale(x, y) {
this.a *= x;
this.d *= y;
this.c *= x;
this.b *= y;
this.tx *= x;
this.ty *= y;
return this;
}
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;
}
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;
}
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;
}
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;
}
this.tx = tx1 * matrix.a + this.ty * matrix.c + matrix.tx;
this.ty = tx1 * matrix.b + this.ty * matrix.d + matrix.ty;
return this;
}
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(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;
}
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;
}
identity() {
this.a = 1;
this.b = 0;
this.c = 0;
this.d = 1;
this.tx = 0;
this.ty = 0;
return this;
}
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;
}
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;
}
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;
}
toString() {
return `[@pixi/math:Matrix a=${this.a} b=${this.b} c=${this.c} d=${this.d} tx=${this.tx} ty=${this.ty}]`;
}
static get IDENTITY() {
return new Matrix();
}
static get TEMP_MATRIX() {
return new Matrix();
}
}
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;
function init() {
for (var i = 0; i < 16; i++) {
var row = [];
rotationCayley.push(row);
for (var j = 0; j < 16; j++) {
/* Multiplies rotation matrices i and j. */
var _ux = signum((ux[i] * ux[j]) + (vx[i] * uy[j]));
var _uy = signum((uy[i] * ux[j]) + (vy[i] * uy[j]));
var _vx = signum((ux[i] * vx[j]) + (vx[i] * vy[j]));
var _vy = signum((uy[i] * vx[j]) + (vy[i] * vy[j]));
/* Finds rotation matrix matching the product and pushes it. */
for (var k = 0; k < 16; k++) {
if (ux[k] === _ux && uy[k] === _uy
&& vx[k] === _vx && vy[k] === _vy) {
row.push(k);
break;
}
}
for (let i = 0; i < 16; i++) {
const row = [];
rotationCayley.push(row);
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++) {
if (ux[k] === _ux && uy[k] === _uy && vx[k] === _vx && vy[k] === _vy) {
row.push(k);
break;
}
}
}
for (var i = 0; i < 16; i++) {
var mat = new Matrix();
mat.set(ux[i], uy[i], vx[i], vy[i], 0, 0);
rotationMatrices.push(mat);
}
}
for (let i = 0; i < 16; i++) {
const mat = new Matrix();
mat.set(ux[i], uy[i], vx[i], vy[i], 0, 0);
rotationMatrices.push(mat);
}
}
init();
/**
* @memberof PIXI
* @typedef {number} GD8Symmetry
* @see PIXI.groupD8
*/
/**
* Implements the dihedral group D8, which is similar to
* [group D4]{@link http://mathworld.wolfram.com/DihedralGroupD4.html};
* D8 is the same but with diagonals, and it is used for texture
* rotations.
*
* The directions the U- and V- axes after rotation
* of an angle of `a: GD8Constant` are the vectors `(uX(a), uY(a))`
* and `(vX(a), vY(a))`. These aren't necessarily unit vectors.
*
* **Origin:**<br>
* This is the small part of gameofbombs.com portal system. It works.
* @see PIXI.groupD8.E
* @see PIXI.groupD8.SE
* @see PIXI.groupD8.S
* @see PIXI.groupD8.SW
* @see PIXI.groupD8.W
* @see PIXI.groupD8.NW
* @see PIXI.groupD8.N
* @see PIXI.groupD8.NE
* @author Ivan @ivanpopelyshev
* @namespace PIXI.groupD8
* @memberof PIXI
*/
var groupD8 = {
/**
* | Rotation | Direction |
* |----------|-----------|
* | 0° | East |
* @memberof PIXI.groupD8
* @constant {PIXI.GD8Symmetry}
*/
E: 0,
/**
* | Rotation | Direction |
* |----------|-----------|
* | 45°↻ | Southeast |
* @memberof PIXI.groupD8
* @constant {PIXI.GD8Symmetry}
*/
SE: 1,
/**
* | Rotation | Direction |
* |----------|-----------|
* | 90°↻ | South |
* @memberof PIXI.groupD8
* @constant {PIXI.GD8Symmetry}
*/
S: 2,
/**
* | Rotation | Direction |
* |----------|-----------|
* | 135°↻ | Southwest |
* @memberof PIXI.groupD8
* @constant {PIXI.GD8Symmetry}
*/
SW: 3,
/**
* | Rotation | Direction |
* |----------|-----------|
* | 180° | West |
* @memberof PIXI.groupD8
* @constant {PIXI.GD8Symmetry}
*/
W: 4,
/**
* | Rotation | Direction |
* |-------------|--------------|
* | -135°/225°↻ | Northwest |
* @memberof PIXI.groupD8
* @constant {PIXI.GD8Symmetry}
*/
NW: 5,
/**
* | Rotation | Direction |
* |-------------|--------------|
* | -90°/270°↻ | North |
* @memberof PIXI.groupD8
* @constant {PIXI.GD8Symmetry}
*/
N: 6,
/**
* | Rotation | Direction |
* |-------------|--------------|
* | -45°/315°↻ | Northeast |
* @memberof PIXI.groupD8
* @constant {PIXI.GD8Symmetry}
*/
NE: 7,
/**
* Reflection about Y-axis.
* @memberof PIXI.groupD8
* @constant {PIXI.GD8Symmetry}
*/
MIRROR_VERTICAL: 8,
/**
* Reflection about the main diagonal.
* @memberof PIXI.groupD8
* @constant {PIXI.GD8Symmetry}
*/
MAIN_DIAGONAL: 10,
/**
* Reflection about X-axis.
* @memberof PIXI.groupD8
* @constant {PIXI.GD8Symmetry}
*/
MIRROR_HORIZONTAL: 12,
/**
* Reflection about reverse diagonal.
* @memberof PIXI.groupD8
* @constant {PIXI.GD8Symmetry}
*/
REVERSE_DIAGONAL: 14,
/**
* @memberof PIXI.groupD8
* @param {PIXI.GD8Symmetry} ind - sprite rotation angle.
* @returns {PIXI.GD8Symmetry} The X-component of the U-axis
* after rotating the axes.
*/
uX: function (ind) { return ux[ind]; },
/**
* @memberof PIXI.groupD8
* @param {PIXI.GD8Symmetry} ind - sprite rotation angle.
* @returns {PIXI.GD8Symmetry} The Y-component of the U-axis
* after rotating the axes.
*/
uY: function (ind) { return uy[ind]; },
/**
* @memberof PIXI.groupD8
* @param {PIXI.GD8Symmetry} ind - sprite rotation angle.
* @returns {PIXI.GD8Symmetry} The X-component of the V-axis
* after rotating the axes.
*/
vX: function (ind) { return vx[ind]; },
/**
* @memberof PIXI.groupD8
* @param {PIXI.GD8Symmetry} ind - sprite rotation angle.
* @returns {PIXI.GD8Symmetry} The Y-component of the V-axis
* after rotating the axes.
*/
vY: function (ind) { return vy[ind]; },
/**
* @memberof PIXI.groupD8
* @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: function (rotation) {
if (rotation & 8) // true only if between 8 & 15 (reflections)
{
return rotation & 15; // or rotation % 16
}
return (-rotation) & 7; // or (8 - rotation) % 8
},
/**
* 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}
* @memberof PIXI.groupD8
* @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: function (rotationSecond, rotationFirst) { return (rotationCayley[rotationSecond][rotationFirst]); },
/**
* Reverse of `add`.
* @memberof PIXI.groupD8
* @param {PIXI.GD8Symmetry} rotationSecond - Second operation
* @param {PIXI.GD8Symmetry} rotationFirst - First operation
* @returns {PIXI.GD8Symmetry} Result
*/
sub: function (rotationSecond, rotationFirst) { return (rotationCayley[rotationSecond][groupD8.inv(rotationFirst)]); },
/**
* Adds 180 degrees to rotation, which is a commutative
* operation.
* @memberof PIXI.groupD8
* @param {number} rotation - The number to rotate.
* @returns {number} Rotated number
*/
rotate180: function (rotation) { return rotation ^ 4; },
/**
* Checks if the rotation angle is vertical, i.e. south
* or north. It doesn't work for reflections.
* @memberof PIXI.groupD8
* @param {PIXI.GD8Symmetry} rotation - The number to check.
* @returns {boolean} Whether or not the direction is vertical
*/
isVertical: function (rotation) { return (rotation & 3) === 2; },
/**
* Approximates the vector `V(dx,dy)` into one of the
* eight directions provided by `groupD8`.
* @memberof PIXI.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: function (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;
},
/**
* Helps sprite to compensate texture packer rotation.
* @memberof PIXI.groupD8
* @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: function (matrix, rotation, tx, ty) {
if (tx === void 0) { tx = 0; }
if (ty === void 0) { ty = 0; }
// Packer used "rotation", we use "inv(rotation)"
var mat = rotationMatrices[groupD8.inv(rotation)];
mat.tx = tx;
mat.ty = ty;
matrix.append(mat);
},
const groupD8 = {
E: 0,
SE: 1,
S: 2,
SW: 3,
W: 4,
NW: 5,
N: 6,
NE: 7,
MIRROR_VERTICAL: 8,
MAIN_DIAGONAL: 10,
MIRROR_HORIZONTAL: 12,
REVERSE_DIAGONAL: 14,
uX: (ind) => ux[ind],
uY: (ind) => uy[ind],
vX: (ind) => vx[ind],
vY: (ind) => vy[ind],
inv: (rotation) => {
if (rotation & 8) {
return rotation & 15;
}
return -rotation & 7;
},
add: (rotationSecond, rotationFirst) => rotationCayley[rotationSecond][rotationFirst],
sub: (rotationSecond, rotationFirst) => rotationCayley[rotationSecond][groupD8.inv(rotationFirst)],
rotate180: (rotation) => rotation ^ 4,
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;
},
matrixAppendRotationInv: (matrix, rotation, tx = 0, ty = 0) => {
const mat = rotationMatrices[groupD8.inv(rotation)];
mat.tx = tx;
mat.ty = ty;
matrix.append(mat);
}
};
/**
* Transform that takes care about its versions.
* @memberof PIXI
*/
var Transform = /** @class */ (function () {
function Transform() {
this.worldTransform = new Matrix();
this.localTransform = new Matrix();
this.position = new ObservablePoint(this.onChange, this, 0, 0);
this.scale = new ObservablePoint(this.onChange, this, 1, 1);
this.pivot = new ObservablePoint(this.onChange, this, 0, 0);
this.skew = new 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;
const _Transform = class {
constructor() {
this.worldTransform = new Matrix();
this.localTransform = new Matrix();
this.position = new ObservablePoint(this.onChange, this, 0, 0);
this.scale = new ObservablePoint(this.onChange, this, 1, 1);
this.pivot = new ObservablePoint(this.onChange, this, 0, 0);
this.skew = new 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;
}
onChange() {
this._localID++;
}
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++;
}
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}) ]`;
}
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;
}
/** Called when a value changes. */
Transform.prototype.onChange = function () {
this._localID++;
};
/** Called when the skew or the rotation changes. */
Transform.prototype.updateSkew = function () {
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); // cos, added PI/2
this._sy = Math.cos(this._rotation - this.skew.x); // sin, added PI/2
this._localID++;
};
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 + ") ")
+ "]";
};
/** Updates the local transformation matrix. */
Transform.prototype.updateLocalTransform = function () {
var lt = this.localTransform;
if (this._localID !== this._currentLocalID) {
// get the matrix values of the displayobject based on its transform properties..
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;
// force an update..
this._parentID = -1;
}
};
/**
* Updates the local and the world transformation matrices.
* @param parentTransform - The parent transform
*/
Transform.prototype.updateTransform = function (parentTransform) {
var lt = this.localTransform;
if (this._localID !== this._currentLocalID) {
// get the matrix values of the displayobject based on its transform properties..
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;
// force an update..
this._parentID = -1;
}
if (this._parentID !== parentTransform._worldID) {
// concat the parent matrix with the objects transform.
var pt = parentTransform.worldTransform;
var 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;
// update the id of the transform..
this._worldID++;
}
};
/**
* Decomposes a matrix and sets the transforms properties based on it.
* @param matrix - The matrix to decompose
*/
Transform.prototype.setFromMatrix = function (matrix) {
matrix.decompose(this);
this._localID++;
};
Object.defineProperty(Transform.prototype, "rotation", {
/** The rotation of the object in radians. */
get: function () {
return this._rotation;
},
set: function (value) {
if (this._rotation !== value) {
this._rotation = value;
this.updateSkew();
}
},
enumerable: false,
configurable: true
});
/** A default (identity) transform. */
Transform.IDENTITY = new Transform();
return 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._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++;
}
}
setFromMatrix(matrix) {
matrix.decompose(this);
this._localID++;
}
get rotation() {
return this._rotation;
}
set rotation(value) {
if (this._rotation !== value) {
this._rotation = value;
this.updateSkew();
}
}
};
let Transform = _Transform;
Transform.IDENTITY = new _Transform();

@@ -1600,4 +816,5 @@ exports.Circle = Circle;

exports.RoundedRectangle = RoundedRectangle;
exports.SHAPES = SHAPES;
exports.Transform = Transform;
exports.groupD8 = groupD8;
//# sourceMappingURL=math.js.map

@@ -1,9 +0,8 @@

/*!
* @pixi/math - v6.5.3
* Compiled Fri, 09 Sep 2022 13:55:20 UTC
"use strict";/*!
* @pixi/math - v7.0.0-alpha
* Compiled Fri, 09 Sep 2022 16:09:18 UTC
*
* @pixi/math is licensed under the MIT License.
* http://www.opensource.org/licenses/mit-license
*/
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,i=2*Math.PI,h=180/Math.PI,s=Math.PI/180;exports.SHAPES=void 0,(t=exports.SHAPES||(exports.SHAPES={}))[t.POLY=0]="POLY",t[t.RECT=1]="RECT",t[t.CIRC=2]="CIRC",t[t.ELIP=3]="ELIP",t[t.RREC=4]="RREC";var o=function(){function t(t,i){void 0===t&&(t=0),void 0===i&&(i=0),this.x=0,this.y=0,this.x=t,this.y=i}return t.prototype.clone=function(){return new t(this.x,this.y)},t.prototype.copyFrom=function(t){return this.set(t.x,t.y),this},t.prototype.copyTo=function(t){return t.set(this.x,this.y),t},t.prototype.equals=function(t){return t.x===this.x&&t.y===this.y},t.prototype.set=function(t,i){return void 0===t&&(t=0),void 0===i&&(i=t),this.x=t,this.y=i,this},t}(),r=[new o,new o,new o,new o],e=function(){function t(t,i,h,s){void 0===t&&(t=0),void 0===i&&(i=0),void 0===h&&(h=0),void 0===s&&(s=0),this.x=Number(t),this.y=Number(i),this.width=Number(h),this.height=Number(s),this.type=exports.SHAPES.RECT}return Object.defineProperty(t.prototype,"left",{get:function(){return this.x},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"right",{get:function(){return this.x+this.width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"top",{get:function(){return this.y},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!1,configurable:!0}),Object.defineProperty(t,"EMPTY",{get:function(){return new t(0,0,0,0)},enumerable:!1,configurable:!0}),t.prototype.clone=function(){return new t(this.x,this.y,this.width,this.height)},t.prototype.copyFrom=function(t){return this.x=t.x,this.y=t.y,this.width=t.width,this.height=t.height,this},t.prototype.copyTo=function(t){return t.x=this.x,t.y=this.y,t.width=this.width,t.height=this.height,t},t.prototype.contains=function(t,i){return!(this.width<=0||this.height<=0)&&(t>=this.x&&t<this.x+this.width&&i>=this.y&&i<this.y+this.height)},t.prototype.intersects=function(t,i){if(!i){var h=this.x<t.x?t.x:this.x;if((this.right>t.right?t.right:this.right)<=h)return!1;var s=this.y<t.y?t.y:this.y;return(this.bottom>t.bottom?t.bottom:this.bottom)>s}var o=this.left,e=this.right,n=this.top,a=this.bottom;if(e<=o||a<=n)return!1;var c=r[0].set(t.left,t.top),y=r[1].set(t.left,t.bottom),u=r[2].set(t.right,t.top),p=r[3].set(t.right,t.bottom);if(u.x<=c.x||y.y<=c.y)return!1;var x=Math.sign(i.a*i.d-i.b*i.c);if(0===x)return!1;if(i.apply(c,c),i.apply(y,y),i.apply(u,u),i.apply(p,p),Math.max(c.x,y.x,u.x,p.x)<=o||Math.min(c.x,y.x,u.x,p.x)>=e||Math.max(c.y,y.y,u.y,p.y)<=n||Math.min(c.y,y.y,u.y,p.y)>=a)return!1;var d=x*(y.y-c.y),f=x*(c.x-y.x),l=d*o+f*n,b=d*e+f*n,v=d*o+f*a,_=d*e+f*a;if(Math.max(l,b,v,_)<=d*c.x+f*c.y||Math.min(l,b,v,_)>=d*p.x+f*p.y)return!1;var w=x*(c.y-u.y),g=x*(u.x-c.x),m=w*o+g*n,M=w*e+g*n,I=w*o+g*a,E=w*e+g*a;return!(Math.max(m,M,I,E)<=w*c.x+g*c.y||Math.min(m,M,I,E)>=w*p.x+g*p.y)},t.prototype.pad=function(t,i){return void 0===t&&(t=0),void 0===i&&(i=t),this.x-=t,this.y-=i,this.width+=2*t,this.height+=2*i,this},t.prototype.fit=function(t){var i=Math.max(this.x,t.x),h=Math.min(this.x+this.width,t.x+t.width),s=Math.max(this.y,t.y),o=Math.min(this.y+this.height,t.y+t.height);return this.x=i,this.width=Math.max(h-i,0),this.y=s,this.height=Math.max(o-s,0),this},t.prototype.ceil=function(t,i){void 0===t&&(t=1),void 0===i&&(i=.001);var h=Math.ceil((this.x+this.width-i)*t)/t,s=Math.ceil((this.y+this.height-i)*t)/t;return this.x=Math.floor((this.x+i)*t)/t,this.y=Math.floor((this.y+i)*t)/t,this.width=h-this.x,this.height=s-this.y,this},t.prototype.enlarge=function(t){var i=Math.min(this.x,t.x),h=Math.max(this.x+this.width,t.x+t.width),s=Math.min(this.y,t.y),o=Math.max(this.y+this.height,t.y+t.height);return this.x=i,this.width=h-i,this.y=s,this.height=o-s,this},t}(),n=function(){function t(t,i,h){void 0===t&&(t=0),void 0===i&&(i=0),void 0===h&&(h=0),this.x=t,this.y=i,this.radius=h,this.type=exports.SHAPES.CIRC}return t.prototype.clone=function(){return new t(this.x,this.y,this.radius)},t.prototype.contains=function(t,i){if(this.radius<=0)return!1;var h=this.radius*this.radius,s=this.x-t,o=this.y-i;return(s*=s)+(o*=o)<=h},t.prototype.getBounds=function(){return new e(this.x-this.radius,this.y-this.radius,2*this.radius,2*this.radius)},t}(),a=function(){function t(t,i,h,s){void 0===t&&(t=0),void 0===i&&(i=0),void 0===h&&(h=0),void 0===s&&(s=0),this.x=t,this.y=i,this.width=h,this.height=s,this.type=exports.SHAPES.ELIP}return t.prototype.clone=function(){return new t(this.x,this.y,this.width,this.height)},t.prototype.contains=function(t,i){if(this.width<=0||this.height<=0)return!1;var h=(t-this.x)/this.width,s=(i-this.y)/this.height;return(h*=h)+(s*=s)<=1},t.prototype.getBounds=function(){return new e(this.x-this.width,this.y-this.height,this.width,this.height)},t}(),c=function(){function t(){for(var t=arguments,i=[],h=0;h<arguments.length;h++)i[h]=t[h];var s=Array.isArray(i[0])?i[0]:i;if("number"!=typeof s[0]){for(var o=[],r=0,e=s.length;r<e;r++)o.push(s[r].x,s[r].y);s=o}this.points=s,this.type=exports.SHAPES.POLY,this.closeStroke=!0}return t.prototype.clone=function(){var i=new t(this.points.slice());return i.closeStroke=this.closeStroke,i},t.prototype.contains=function(t,i){for(var h=!1,s=this.points.length/2,o=0,r=s-1;o<s;r=o++){var e=this.points[2*o],n=this.points[2*o+1],a=this.points[2*r],c=this.points[2*r+1];n>i!=c>i&&t<(i-n)/(c-n)*(a-e)+e&&(h=!h)}return h},t}(),y=function(){function t(t,i,h,s,o){void 0===t&&(t=0),void 0===i&&(i=0),void 0===h&&(h=0),void 0===s&&(s=0),void 0===o&&(o=20),this.x=t,this.y=i,this.width=h,this.height=s,this.radius=o,this.type=exports.SHAPES.RREC}return t.prototype.clone=function(){return new t(this.x,this.y,this.width,this.height,this.radius)},t.prototype.contains=function(t,i){if(this.width<=0||this.height<=0)return!1;if(t>=this.x&&t<=this.x+this.width&&i>=this.y&&i<=this.y+this.height){var h=Math.max(0,Math.min(this.radius,Math.min(this.width,this.height)/2));if(i>=this.y+h&&i<=this.y+this.height-h||t>=this.x+h&&t<=this.x+this.width-h)return!0;var s=t-(this.x+h),o=i-(this.y+h),r=h*h;if(s*s+o*o<=r)return!0;if((s=t-(this.x+this.width-h))*s+o*o<=r)return!0;if(s*s+(o=i-(this.y+this.height-h))*o<=r)return!0;if((s=t-(this.x+h))*s+o*o<=r)return!0}return!1},t}(),u=function(){function t(t,i,h,s){void 0===h&&(h=0),void 0===s&&(s=0),this._x=h,this._y=s,this.cb=t,this.scope=i}return t.prototype.clone=function(i,h){return void 0===i&&(i=this.cb),void 0===h&&(h=this.scope),new t(i,h,this._x,this._y)},t.prototype.set=function(t,i){return void 0===t&&(t=0),void 0===i&&(i=t),this._x===t&&this._y===i||(this._x=t,this._y=i,this.cb.call(this.scope)),this},t.prototype.copyFrom=function(t){return this._x===t.x&&this._y===t.y||(this._x=t.x,this._y=t.y,this.cb.call(this.scope)),this},t.prototype.copyTo=function(t){return t.set(this._x,this._y),t},t.prototype.equals=function(t){return t.x===this._x&&t.y===this._y},Object.defineProperty(t.prototype,"x",{get:function(){return this._x},set:function(t){this._x!==t&&(this._x=t,this.cb.call(this.scope))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"y",{get:function(){return this._y},set:function(t){this._y!==t&&(this._y=t,this.cb.call(this.scope))},enumerable:!1,configurable:!0}),t}(),p=function(){function t(t,i,h,s,o,r){void 0===t&&(t=1),void 0===i&&(i=0),void 0===h&&(h=0),void 0===s&&(s=1),void 0===o&&(o=0),void 0===r&&(r=0),this.array=null,this.a=t,this.b=i,this.c=h,this.d=s,this.tx=o,this.ty=r}return t.prototype.fromArray=function(t){this.a=t[0],this.b=t[1],this.c=t[3],this.d=t[4],this.tx=t[2],this.ty=t[5]},t.prototype.set=function(t,i,h,s,o,r){return this.a=t,this.b=i,this.c=h,this.d=s,this.tx=o,this.ty=r,this},t.prototype.toArray=function(t,i){this.array||(this.array=new Float32Array(9));var h=i||this.array;return t?(h[0]=this.a,h[1]=this.b,h[2]=0,h[3]=this.c,h[4]=this.d,h[5]=0,h[6]=this.tx,h[7]=this.ty,h[8]=1):(h[0]=this.a,h[1]=this.c,h[2]=this.tx,h[3]=this.b,h[4]=this.d,h[5]=this.ty,h[6]=0,h[7]=0,h[8]=1),h},t.prototype.apply=function(t,i){i=i||new o;var h=t.x,s=t.y;return i.x=this.a*h+this.c*s+this.tx,i.y=this.b*h+this.d*s+this.ty,i},t.prototype.applyInverse=function(t,i){i=i||new o;var h=1/(this.a*this.d+this.c*-this.b),s=t.x,r=t.y;return i.x=this.d*h*s+-this.c*h*r+(this.ty*this.c-this.tx*this.d)*h,i.y=this.a*h*r+-this.b*h*s+(-this.ty*this.a+this.tx*this.b)*h,i},t.prototype.translate=function(t,i){return this.tx+=t,this.ty+=i,this},t.prototype.scale=function(t,i){return this.a*=t,this.d*=i,this.c*=t,this.b*=i,this.tx*=t,this.ty*=i,this},t.prototype.rotate=function(t){var i=Math.cos(t),h=Math.sin(t),s=this.a,o=this.c,r=this.tx;return this.a=s*i-this.b*h,this.b=s*h+this.b*i,this.c=o*i-this.d*h,this.d=o*h+this.d*i,this.tx=r*i-this.ty*h,this.ty=r*h+this.ty*i,this},t.prototype.append=function(t){var i=this.a,h=this.b,s=this.c,o=this.d;return this.a=t.a*i+t.b*s,this.b=t.a*h+t.b*o,this.c=t.c*i+t.d*s,this.d=t.c*h+t.d*o,this.tx=t.tx*i+t.ty*s+this.tx,this.ty=t.tx*h+t.ty*o+this.ty,this},t.prototype.setTransform=function(t,i,h,s,o,r,e,n,a){return this.a=Math.cos(e+a)*o,this.b=Math.sin(e+a)*o,this.c=-Math.sin(e-n)*r,this.d=Math.cos(e-n)*r,this.tx=t-(h*this.a+s*this.c),this.ty=i-(h*this.b+s*this.d),this},t.prototype.prepend=function(t){var i=this.tx;if(1!==t.a||0!==t.b||0!==t.c||1!==t.d){var h=this.a,s=this.c;this.a=h*t.a+this.b*t.c,this.b=h*t.b+this.b*t.d,this.c=s*t.a+this.d*t.c,this.d=s*t.b+this.d*t.d}return this.tx=i*t.a+this.ty*t.c+t.tx,this.ty=i*t.b+this.ty*t.d+t.ty,this},t.prototype.decompose=function(t){var h=this.a,s=this.b,o=this.c,r=this.d,e=t.pivot,n=-Math.atan2(-o,r),a=Math.atan2(s,h),c=Math.abs(n+a);return c<1e-5||Math.abs(i-c)<1e-5?(t.rotation=a,t.skew.x=t.skew.y=0):(t.rotation=0,t.skew.x=n,t.skew.y=a),t.scale.x=Math.sqrt(h*h+s*s),t.scale.y=Math.sqrt(o*o+r*r),t.position.x=this.tx+(e.x*h+e.y*o),t.position.y=this.ty+(e.x*s+e.y*r),t},t.prototype.invert=function(){var t=this.a,i=this.b,h=this.c,s=this.d,o=this.tx,r=t*s-i*h;return this.a=s/r,this.b=-i/r,this.c=-h/r,this.d=t/r,this.tx=(h*this.ty-s*o)/r,this.ty=-(t*this.ty-i*o)/r,this},t.prototype.identity=function(){return this.a=1,this.b=0,this.c=0,this.d=1,this.tx=0,this.ty=0,this},t.prototype.clone=function(){var i=new t;return i.a=this.a,i.b=this.b,i.c=this.c,i.d=this.d,i.tx=this.tx,i.ty=this.ty,i},t.prototype.copyTo=function(t){return t.a=this.a,t.b=this.b,t.c=this.c,t.d=this.d,t.tx=this.tx,t.ty=this.ty,t},t.prototype.copyFrom=function(t){return this.a=t.a,this.b=t.b,this.c=t.c,this.d=t.d,this.tx=t.tx,this.ty=t.ty,this},Object.defineProperty(t,"IDENTITY",{get:function(){return new t},enumerable:!1,configurable:!0}),Object.defineProperty(t,"TEMP_MATRIX",{get:function(){return new t},enumerable:!1,configurable:!0}),t}(),x=[1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1],d=[0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1],f=[0,-1,-1,-1,0,1,1,1,0,1,1,1,0,-1,-1,-1],l=[1,1,0,-1,-1,-1,0,1,-1,-1,0,1,1,1,0,-1],b=[],v=[],_=Math.sign;!function(){for(var t=0;t<16;t++){var i=[];b.push(i);for(var h=0;h<16;h++)for(var s=_(x[t]*x[h]+f[t]*d[h]),o=_(d[t]*x[h]+l[t]*d[h]),r=_(x[t]*f[h]+f[t]*l[h]),e=_(d[t]*f[h]+l[t]*l[h]),n=0;n<16;n++)if(x[n]===s&&d[n]===o&&f[n]===r&&l[n]===e){i.push(n);break}}for(t=0;t<16;t++){var a=new p;a.set(x[t],d[t],f[t],l[t],0,0),v.push(a)}}();var w={E:0,SE:1,S:2,SW:3,W:4,NW:5,N:6,NE:7,MIRROR_VERTICAL:8,MAIN_DIAGONAL:10,MIRROR_HORIZONTAL:12,REVERSE_DIAGONAL:14,uX:function(t){return x[t]},uY:function(t){return d[t]},vX:function(t){return f[t]},vY:function(t){return l[t]},inv:function(t){return 8&t?15&t:7&-t},add:function(t,i){return b[t][i]},sub:function(t,i){return b[t][w.inv(i)]},rotate180:function(t){return 4^t},isVertical:function(t){return 2==(3&t)},byDirection:function(t,i){return 2*Math.abs(t)<=Math.abs(i)?i>=0?w.S:w.N:2*Math.abs(i)<=Math.abs(t)?t>0?w.E:w.W:i>0?t>0?w.SE:w.SW:t>0?w.NE:w.NW},matrixAppendRotationInv:function(t,i,h,s){void 0===h&&(h=0),void 0===s&&(s=0);var o=v[w.inv(i)];o.tx=h,o.ty=s,t.append(o)}},g=function(){function t(){this.worldTransform=new p,this.localTransform=new p,this.position=new u(this.onChange,this,0,0),this.scale=new u(this.onChange,this,1,1),this.pivot=new u(this.onChange,this,0,0),this.skew=new u(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}return t.prototype.onChange=function(){this._localID++},t.prototype.updateSkew=function(){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++},t.prototype.updateLocalTransform=function(){var t=this.localTransform;this._localID!==this._currentLocalID&&(t.a=this._cx*this.scale.x,t.b=this._sx*this.scale.x,t.c=this._cy*this.scale.y,t.d=this._sy*this.scale.y,t.tx=this.position.x-(this.pivot.x*t.a+this.pivot.y*t.c),t.ty=this.position.y-(this.pivot.x*t.b+this.pivot.y*t.d),this._currentLocalID=this._localID,this._parentID=-1)},t.prototype.updateTransform=function(t){var i=this.localTransform;if(this._localID!==this._currentLocalID&&(i.a=this._cx*this.scale.x,i.b=this._sx*this.scale.x,i.c=this._cy*this.scale.y,i.d=this._sy*this.scale.y,i.tx=this.position.x-(this.pivot.x*i.a+this.pivot.y*i.c),i.ty=this.position.y-(this.pivot.x*i.b+this.pivot.y*i.d),this._currentLocalID=this._localID,this._parentID=-1),this._parentID!==t._worldID){var h=t.worldTransform,s=this.worldTransform;s.a=i.a*h.a+i.b*h.c,s.b=i.a*h.b+i.b*h.d,s.c=i.c*h.a+i.d*h.c,s.d=i.c*h.b+i.d*h.d,s.tx=i.tx*h.a+i.ty*h.c+h.tx,s.ty=i.tx*h.b+i.ty*h.d+h.ty,this._parentID=t._worldID,this._worldID++}},t.prototype.setFromMatrix=function(t){t.decompose(this),this._localID++},Object.defineProperty(t.prototype,"rotation",{get:function(){return this._rotation},set:function(t){this._rotation!==t&&(this._rotation=t,this.updateSkew())},enumerable:!1,configurable:!0}),t.IDENTITY=new t,t}();exports.Circle=n,exports.DEG_TO_RAD=s,exports.Ellipse=a,exports.Matrix=p,exports.ObservablePoint=u,exports.PI_2=i,exports.Point=o,exports.Polygon=c,exports.RAD_TO_DEG=h,exports.Rectangle=e,exports.RoundedRectangle=y,exports.Transform=g,exports.groupD8=w;
*/Object.defineProperty(exports,"__esModule",{value:!0});const q=Math.PI*2,Z=180/Math.PI,z=Math.PI/180;var d=(e=>(e[e.POLY=0]="POLY",e[e.RECT=1]="RECT",e[e.CIRC=2]="CIRC",e[e.ELIP=3]="ELIP",e[e.RREC=4]="RREC",e))(d||{});class u{constructor(t=0,s=0){this.x=0,this.y=0,this.x=t,this.y=s}clone(){return new u(this.x,this.y)}copyFrom(t){return this.set(t.x,t.y),this}copyTo(t){return t.set(this.x,this.y),t}equals(t){return t.x===this.x&&t.y===this.y}set(t=0,s=t){return this.x=t,this.y=s,this}}const R=[new u,new u,new u,new u];class D{constructor(t=0,s=0,i=0,h=0){this.x=Number(t),this.y=Number(s),this.width=Number(i),this.height=Number(h),this.type=d.RECT}get left(){return this.x}get right(){return this.x+this.width}get top(){return this.y}get bottom(){return this.y+this.height}static get EMPTY(){return new D(0,0,0,0)}clone(){return new D(this.x,this.y,this.width,this.height)}copyFrom(t){return this.x=t.x,this.y=t.y,this.width=t.width,this.height=t.height,this}copyTo(t){return t.x=this.x,t.y=this.y,t.width=this.width,t.height=this.height,t}contains(t,s){return this.width<=0||this.height<=0?!1:t>=this.x&&t<this.x+this.width&&s>=this.y&&s<this.y+this.height}intersects(t,s){if(!s){const B=this.x<t.x?t.x:this.x;if((this.right>t.right?t.right:this.right)<=B)return!1;const j=this.y<t.y?t.y:this.y;return(this.bottom>t.bottom?t.bottom:this.bottom)>j}const i=this.left,h=this.right,r=this.top,n=this.bottom;if(h<=i||n<=r)return!1;const a=R[0].set(t.left,t.top),o=R[1].set(t.left,t.bottom),c=R[2].set(t.right,t.top),y=R[3].set(t.right,t.bottom);if(c.x<=a.x||o.y<=a.y)return!1;const E=Math.sign(s.a*s.d-s.b*s.c);if(E===0||(s.apply(a,a),s.apply(o,o),s.apply(c,c),s.apply(y,y),Math.max(a.x,o.x,c.x,y.x)<=i||Math.min(a.x,o.x,c.x,y.x)>=h||Math.max(a.y,o.y,c.y,y.y)<=r||Math.min(a.y,o.y,c.y,y.y)>=n))return!1;const M=E*(o.y-a.y),m=E*(a.x-o.x),N=M*i+m*r,k=M*h+m*r,L=M*i+m*n,O=M*h+m*n;if(Math.max(N,k,L,O)<=M*a.x+m*a.y||Math.min(N,k,L,O)>=M*y.x+m*y.y)return!1;const I=E*(a.y-c.y),f=E*(c.x-a.x),Y=I*i+f*r,G=I*h+f*r,F=I*i+f*n,W=I*h+f*n;return!(Math.max(Y,G,F,W)<=I*a.x+f*a.y||Math.min(Y,G,F,W)>=I*y.x+f*y.y)}pad(t=0,s=t){return this.x-=t,this.y-=s,this.width+=t*2,this.height+=s*2,this}fit(t){const s=Math.max(this.x,t.x),i=Math.min(this.x+this.width,t.x+t.width),h=Math.max(this.y,t.y),r=Math.min(this.y+this.height,t.y+t.height);return this.x=s,this.width=Math.max(i-s,0),this.y=h,this.height=Math.max(r-h,0),this}ceil(t=1,s=.001){const i=Math.ceil((this.x+this.width-s)*t)/t,h=Math.ceil((this.y+this.height-s)*t)/t;return this.x=Math.floor((this.x+s)*t)/t,this.y=Math.floor((this.y+s)*t)/t,this.width=i-this.x,this.height=h-this.y,this}enlarge(t){const s=Math.min(this.x,t.x),i=Math.max(this.x+this.width,t.x+t.width),h=Math.min(this.y,t.y),r=Math.max(this.y+this.height,t.y+t.height);return this.x=s,this.width=i-s,this.y=h,this.height=r-h,this}}class A{constructor(t=0,s=0,i=0){this.x=t,this.y=s,this.radius=i,this.type=d.CIRC}clone(){return new A(this.x,this.y,this.radius)}contains(t,s){if(this.radius<=0)return!1;const i=this.radius*this.radius;let h=this.x-t,r=this.y-s;return h*=h,r*=r,h+r<=i}getBounds(){return new D(this.x-this.radius,this.y-this.radius,this.radius*2,this.radius*2)}}class P{constructor(t=0,s=0,i=0,h=0){this.x=t,this.y=s,this.width=i,this.height=h,this.type=d.ELIP}clone(){return new P(this.x,this.y,this.width,this.height)}contains(t,s){if(this.width<=0||this.height<=0)return!1;let i=(t-this.x)/this.width,h=(s-this.y)/this.height;return i*=i,h*=h,i+h<=1}getBounds(){return new D(this.x-this.width,this.y-this.height,this.width,this.height)}}class S{constructor(...t){let s=Array.isArray(t[0])?t[0]:t;if(typeof s[0]!="number"){const i=[];for(let h=0,r=s.length;h<r;h++)i.push(s[h].x,s[h].y);s=i}this.points=s,this.type=d.POLY,this.closeStroke=!0}clone(){const t=this.points.slice(),s=new S(t);return s.closeStroke=this.closeStroke,s}contains(t,s){let i=!1;const h=this.points.length/2;for(let r=0,n=h-1;r<h;n=r++){const a=this.points[r*2],o=this.points[r*2+1],c=this.points[n*2],y=this.points[n*2+1];o>s!=y>s&&t<(c-a)*((s-o)/(y-o))+a&&(i=!i)}return i}}class C{constructor(t=0,s=0,i=0,h=0,r=20){this.x=t,this.y=s,this.width=i,this.height=h,this.radius=r,this.type=d.RREC}clone(){return new C(this.x,this.y,this.width,this.height,this.radius)}contains(t,s){if(this.width<=0||this.height<=0)return!1;if(t>=this.x&&t<=this.x+this.width&&s>=this.y&&s<=this.y+this.height){const i=Math.max(0,Math.min(this.radius,Math.min(this.width,this.height)/2));if(s>=this.y+i&&s<=this.y+this.height-i||t>=this.x+i&&t<=this.x+this.width-i)return!0;let h=t-(this.x+i),r=s-(this.y+i);const n=i*i;if(h*h+r*r<=n||(h=t-(this.x+this.width-i),h*h+r*r<=n)||(r=s-(this.y+this.height-i),h*h+r*r<=n)||(h=t-(this.x+i),h*h+r*r<=n))return!0}return!1}}class g{constructor(t,s,i=0,h=0){this._x=i,this._y=h,this.cb=t,this.scope=s}clone(t=this.cb,s=this.scope){return new g(t,s,this._x,this._y)}set(t=0,s=t){return(this._x!==t||this._y!==s)&&(this._x=t,this._y=s,this.cb.call(this.scope)),this}copyFrom(t){return(this._x!==t.x||this._y!==t.y)&&(this._x=t.x,this._y=t.y,this.cb.call(this.scope)),this}copyTo(t){return t.set(this._x,this._y),t}equals(t){return t.x===this._x&&t.y===this._y}get x(){return this._x}set x(t){this._x!==t&&(this._x=t,this.cb.call(this.scope))}get y(){return this._y}set y(t){this._y!==t&&(this._y=t,this.cb.call(this.scope))}}class l{constructor(t=1,s=0,i=0,h=1,r=0,n=0){this.array=null,this.a=t,this.b=s,this.c=i,this.d=h,this.tx=r,this.ty=n}fromArray(t){this.a=t[0],this.b=t[1],this.c=t[3],this.d=t[4],this.tx=t[2],this.ty=t[5]}set(t,s,i,h,r,n){return this.a=t,this.b=s,this.c=i,this.d=h,this.tx=r,this.ty=n,this}toArray(t,s){this.array||(this.array=new Float32Array(9));const i=s||this.array;return t?(i[0]=this.a,i[1]=this.b,i[2]=0,i[3]=this.c,i[4]=this.d,i[5]=0,i[6]=this.tx,i[7]=this.ty,i[8]=1):(i[0]=this.a,i[1]=this.c,i[2]=this.tx,i[3]=this.b,i[4]=this.d,i[5]=this.ty,i[6]=0,i[7]=0,i[8]=1),i}apply(t,s){s=s||new u;const i=t.x,h=t.y;return s.x=this.a*i+this.c*h+this.tx,s.y=this.b*i+this.d*h+this.ty,s}applyInverse(t,s){s=s||new u;const i=1/(this.a*this.d+this.c*-this.b),h=t.x,r=t.y;return s.x=this.d*i*h+-this.c*i*r+(this.ty*this.c-this.tx*this.d)*i,s.y=this.a*i*r+-this.b*i*h+(-this.ty*this.a+this.tx*this.b)*i,s}translate(t,s){return this.tx+=t,this.ty+=s,this}scale(t,s){return this.a*=t,this.d*=s,this.c*=t,this.b*=s,this.tx*=t,this.ty*=s,this}rotate(t){const s=Math.cos(t),i=Math.sin(t),h=this.a,r=this.c,n=this.tx;return this.a=h*s-this.b*i,this.b=h*i+this.b*s,this.c=r*s-this.d*i,this.d=r*i+this.d*s,this.tx=n*s-this.ty*i,this.ty=n*i+this.ty*s,this}append(t){const s=this.a,i=this.b,h=this.c,r=this.d;return this.a=t.a*s+t.b*h,this.b=t.a*i+t.b*r,this.c=t.c*s+t.d*h,this.d=t.c*i+t.d*r,this.tx=t.tx*s+t.ty*h+this.tx,this.ty=t.tx*i+t.ty*r+this.ty,this}setTransform(t,s,i,h,r,n,a,o,c){return this.a=Math.cos(a+c)*r,this.b=Math.sin(a+c)*r,this.c=-Math.sin(a-o)*n,this.d=Math.cos(a-o)*n,this.tx=t-(i*this.a+h*this.c),this.ty=s-(i*this.b+h*this.d),this}prepend(t){const s=this.tx;if(t.a!==1||t.b!==0||t.c!==0||t.d!==1){const i=this.a,h=this.c;this.a=i*t.a+this.b*t.c,this.b=i*t.b+this.b*t.d,this.c=h*t.a+this.d*t.c,this.d=h*t.b+this.d*t.d}return this.tx=s*t.a+this.ty*t.c+t.tx,this.ty=s*t.b+this.ty*t.d+t.ty,this}decompose(t){const s=this.a,i=this.b,h=this.c,r=this.d,n=t.pivot,a=-Math.atan2(-h,r),o=Math.atan2(i,s),c=Math.abs(a+o);return c<1e-5||Math.abs(q-c)<1e-5?(t.rotation=o,t.skew.x=t.skew.y=0):(t.rotation=0,t.skew.x=a,t.skew.y=o),t.scale.x=Math.sqrt(s*s+i*i),t.scale.y=Math.sqrt(h*h+r*r),t.position.x=this.tx+(n.x*s+n.y*h),t.position.y=this.ty+(n.x*i+n.y*r),t}invert(){const t=this.a,s=this.b,i=this.c,h=this.d,r=this.tx,n=t*h-s*i;return this.a=h/n,this.b=-s/n,this.c=-i/n,this.d=t/n,this.tx=(i*this.ty-h*r)/n,this.ty=-(t*this.ty-s*r)/n,this}identity(){return this.a=1,this.b=0,this.c=0,this.d=1,this.tx=0,this.ty=0,this}clone(){const t=new l;return t.a=this.a,t.b=this.b,t.c=this.c,t.d=this.d,t.tx=this.tx,t.ty=this.ty,t}copyTo(t){return t.a=this.a,t.b=this.b,t.c=this.c,t.d=this.d,t.tx=this.tx,t.ty=this.ty,t}copyFrom(t){return this.a=t.a,this.b=t.b,this.c=t.c,this.d=t.d,this.tx=t.tx,this.ty=t.ty,this}static get IDENTITY(){return new l}static get TEMP_MATRIX(){return new l}}const p=[1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1],w=[0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1],b=[0,-1,-1,-1,0,1,1,1,0,1,1,1,0,-1,-1,-1],_=[1,1,0,-1,-1,-1,0,1,-1,-1,0,1,1,1,0,-1],v=[],H=[],T=Math.sign;function J(){for(let e=0;e<16;e++){const t=[];v.push(t);for(let s=0;s<16;s++){const i=T(p[e]*p[s]+b[e]*w[s]),h=T(w[e]*p[s]+_[e]*w[s]),r=T(p[e]*b[s]+b[e]*_[s]),n=T(w[e]*b[s]+_[e]*_[s]);for(let a=0;a<16;a++)if(p[a]===i&&w[a]===h&&b[a]===r&&_[a]===n){t.push(a);break}}}for(let e=0;e<16;e++){const t=new l;t.set(p[e],w[e],b[e],_[e],0,0),H.push(t)}}J();const x={E:0,SE:1,S:2,SW:3,W:4,NW:5,N:6,NE:7,MIRROR_VERTICAL:8,MAIN_DIAGONAL:10,MIRROR_HORIZONTAL:12,REVERSE_DIAGONAL:14,uX:e=>p[e],uY:e=>w[e],vX:e=>b[e],vY:e=>_[e],inv:e=>e&8?e&15:-e&7,add:(e,t)=>v[e][t],sub:(e,t)=>v[e][x.inv(t)],rotate180:e=>e^4,isVertical:e=>(e&3)===2,byDirection:(e,t)=>Math.abs(e)*2<=Math.abs(t)?t>=0?x.S:x.N:Math.abs(t)*2<=Math.abs(e)?e>0?x.E:x.W:t>0?e>0?x.SE:x.SW:e>0?x.NE:x.NW,matrixAppendRotationInv:(e,t,s=0,i=0)=>{const h=H[x.inv(t)];h.tx=s,h.ty=i,e.append(h)}},V=class{constructor(){this.worldTransform=new l,this.localTransform=new l,this.position=new g(this.onChange,this,0,0),this.scale=new g(this.onChange,this,1,1),this.pivot=new g(this.onChange,this,0,0),this.skew=new g(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}onChange(){this._localID++}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++}updateLocalTransform(){const e=this.localTransform;this._localID!==this._currentLocalID&&(e.a=this._cx*this.scale.x,e.b=this._sx*this.scale.x,e.c=this._cy*this.scale.y,e.d=this._sy*this.scale.y,e.tx=this.position.x-(this.pivot.x*e.a+this.pivot.y*e.c),e.ty=this.position.y-(this.pivot.x*e.b+this.pivot.y*e.d),this._currentLocalID=this._localID,this._parentID=-1)}updateTransform(e){const t=this.localTransform;if(this._localID!==this._currentLocalID&&(t.a=this._cx*this.scale.x,t.b=this._sx*this.scale.x,t.c=this._cy*this.scale.y,t.d=this._sy*this.scale.y,t.tx=this.position.x-(this.pivot.x*t.a+this.pivot.y*t.c),t.ty=this.position.y-(this.pivot.x*t.b+this.pivot.y*t.d),this._currentLocalID=this._localID,this._parentID=-1),this._parentID!==e._worldID){const s=e.worldTransform,i=this.worldTransform;i.a=t.a*s.a+t.b*s.c,i.b=t.a*s.b+t.b*s.d,i.c=t.c*s.a+t.d*s.c,i.d=t.c*s.b+t.d*s.d,i.tx=t.tx*s.a+t.ty*s.c+s.tx,i.ty=t.tx*s.b+t.ty*s.d+s.ty,this._parentID=e._worldID,this._worldID++}}setFromMatrix(e){e.decompose(this),this._localID++}get rotation(){return this._rotation}set rotation(e){this._rotation!==e&&(this._rotation=e,this.updateSkew())}};let X=V;X.IDENTITY=new V,exports.Circle=A,exports.DEG_TO_RAD=z,exports.Ellipse=P,exports.Matrix=l,exports.ObservablePoint=g,exports.PI_2=q,exports.Point=u,exports.Polygon=S,exports.RAD_TO_DEG=Z,exports.Rectangle=D,exports.RoundedRectangle=C,exports.SHAPES=d,exports.Transform=X,exports.groupD8=x;
//# sourceMappingURL=math.min.js.map
{
"name": "@pixi/math",
"version": "6.5.3",
"version": "7.0.0-alpha",
"main": "dist/cjs/math.js",
"module": "dist/esm/math.mjs",
"bundle": "dist/browser/math.js",
"types": "index.d.ts",

@@ -36,7 +35,6 @@ "exports": {

"files": [
"lib",
"dist",
"*.d.ts"
],
"gitHead": "28e6b2841a65837a5e2873a3d5a9c27cabbe795a"
"gitHead": "da993226df64b804a9c00ed9ee4d011191467b8a"
}

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