UNPKG

1.53 kBJavaScriptView Raw
1(function (factory) {
2 if (typeof module === "object" && typeof module.exports === "object") {
3 var v = factory(require, exports);
4 if (v !== undefined) module.exports = v;
5 }
6 else if (typeof define === "function" && define.amd) {
7 define(["require", "exports", "./Circle", "./Range"], factory);
8 }
9})(function (require, exports) {
10 "use strict";
11 Object.defineProperty(exports, "__esModule", { value: true });
12 exports.Rectangle = void 0;
13 const Circle_1 = require("./Circle");
14 const Range_1 = require("./Range");
15 class Rectangle extends Range_1.Range {
16 constructor(x, y, width, height) {
17 super(x, y);
18 this.size = {
19 height: height,
20 width: width,
21 };
22 }
23 contains(point) {
24 const w = this.size.width, h = this.size.height, pos = this.position;
25 return point.x >= pos.x && point.x <= pos.x + w && point.y >= pos.y && point.y <= pos.y + h;
26 }
27 intersects(range) {
28 if (range instanceof Circle_1.Circle) {
29 range.intersects(this);
30 }
31 const w = this.size.width, h = this.size.height, pos1 = this.position, pos2 = range.position, size2 = range instanceof Rectangle ? range.size : { width: 0, height: 0 }, w2 = size2.width, h2 = size2.height;
32 return pos2.x < pos1.x + w && pos2.x + w2 > pos1.x && pos2.y < pos1.y + h && pos2.y + h2 > pos1.y;
33 }
34 }
35 exports.Rectangle = Rectangle;
36});