UNPKG

@phaserjs/phaser

Version:
52 lines (51 loc) 1.39 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => { __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); return value; }; /** * @author Richard Davey <rich@photonstorm.com> * @copyright 2020 Photon Storm Ltd. * @license {@link https://opensource.org/licenses/MIT|MIT License} */ import { RectangleContains } from "./RectangleContains"; export class Rectangle { constructor(x = 0, y = 0, width = 0, height = 0) { __publicField(this, "x"); __publicField(this, "y"); __publicField(this, "width"); __publicField(this, "height"); this.set(x, y, width, height); } set(x = 0, y = 0, width = 0, height = 0) { this.x = x; this.y = y; this.width = width; this.height = height; return this; } contains(x, y) { return RectangleContains(this, x, y); } set right(value) { if (value <= this.x) { this.width = 0; } else { this.width = value - this.x; } } get right() { return this.x + this.width; } set bottom(value) { if (value <= this.y) { this.height = 0; } else { this.height = value - this.y; } } get bottom() { return this.y + this.height; } }