47 lines
1.6 KiB
JavaScript
47 lines
1.6 KiB
JavaScript
import { SHAPES } from "../const.mjs";
|
|
import { Rectangle } from "./Rectangle.mjs";
|
|
class Ellipse {
|
|
/**
|
|
* @param x - The X coordinate of the center of this ellipse
|
|
* @param y - The Y coordinate of the center of this ellipse
|
|
* @param halfWidth - The half width of this ellipse
|
|
* @param halfHeight - The half height of this ellipse
|
|
*/
|
|
constructor(x = 0, y = 0, halfWidth = 0, halfHeight = 0) {
|
|
this.x = x, this.y = y, this.width = halfWidth, this.height = halfHeight, this.type = SHAPES.ELIP;
|
|
}
|
|
/**
|
|
* Creates a clone of this Ellipse instance
|
|
* @returns {PIXI.Ellipse} A copy of the ellipse
|
|
*/
|
|
clone() {
|
|
return new Ellipse(this.x, this.y, this.width, this.height);
|
|
}
|
|
/**
|
|
* Checks whether the x and y coordinates given are contained within this ellipse
|
|
* @param x - The X coordinate of the point to test
|
|
* @param y - The Y coordinate of the point to test
|
|
* @returns Whether the x/y coords are within this ellipse
|
|
*/
|
|
contains(x, y) {
|
|
if (this.width <= 0 || this.height <= 0)
|
|
return !1;
|
|
let normx = (x - this.x) / this.width, normy = (y - this.y) / this.height;
|
|
return normx *= normx, normy *= normy, normx + normy <= 1;
|
|
}
|
|
/**
|
|
* Returns the framing rectangle of the ellipse as a Rectangle object
|
|
* @returns The framing rectangle
|
|
*/
|
|
getBounds() {
|
|
return new Rectangle(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}]`;
|
|
};
|
|
export {
|
|
Ellipse
|
|
};
|
|
//# sourceMappingURL=Ellipse.mjs.map
|