1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.Circle = void 0;
|
4 | const Range_1 = require("./Range");
|
5 | const NumberUtils_1 = require("./NumberUtils");
|
6 | class Circle extends Range_1.Range {
|
7 | constructor(x, y, radius) {
|
8 | super(x, y);
|
9 | this.radius = radius;
|
10 | }
|
11 | contains(point) {
|
12 | return (0, NumberUtils_1.getDistance)(point, this.position) <= this.radius;
|
13 | }
|
14 | intersects(range) {
|
15 | const rect = range;
|
16 | const circle = range;
|
17 | const pos1 = this.position;
|
18 | const pos2 = range.position;
|
19 | const xDist = Math.abs(pos2.x - pos1.x);
|
20 | const yDist = Math.abs(pos2.y - pos1.y);
|
21 | const r = this.radius;
|
22 | if (circle.radius !== undefined) {
|
23 | const rSum = r + circle.radius;
|
24 | const dist = Math.sqrt(xDist * xDist + yDist + yDist);
|
25 | return rSum > dist;
|
26 | }
|
27 | else if (rect.size !== undefined) {
|
28 | const w = rect.size.width;
|
29 | const h = rect.size.height;
|
30 | const edges = Math.pow(xDist - w, 2) + Math.pow(yDist - h, 2);
|
31 | if (xDist > r + w || yDist > r + h) {
|
32 | return false;
|
33 | }
|
34 | if (xDist <= w || yDist <= h) {
|
35 | return true;
|
36 | }
|
37 | return edges <= r * r;
|
38 | }
|
39 | return false;
|
40 | }
|
41 | }
|
42 | exports.Circle = Circle;
|