Rectangle.js 497 B

123456789101112131415161718192021
  1. import { Point } from "./Point.js";
  2. export class Rectangle {
  3. constructor(x, y, width, height) {
  4. this.x = x;
  5. this.y = y;
  6. this.width = width;
  7. this.height = height;
  8. }
  9. pointWithin(point) {
  10. return point.x > this.x &&
  11. point.x < this.x + this.width &&
  12. point.y > this.y &&
  13. point.y < this.y + this.height;
  14. }
  15. get center() {
  16. return new Point(this.x + this.width / 2, this.y + this.height / 2);
  17. }
  18. }