1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.CircleWarp = void 0;
|
4 | const Rectangle_1 = require("./Rectangle");
|
5 | const Circle_1 = require("./Circle");
|
6 | class CircleWarp extends Circle_1.Circle {
|
7 | constructor(x, y, radius, canvasSize) {
|
8 | super(x, y, radius);
|
9 | this.canvasSize = canvasSize;
|
10 | this.canvasSize = {
|
11 | height: canvasSize.height,
|
12 | width: canvasSize.width,
|
13 | };
|
14 | }
|
15 | contains(point) {
|
16 | if (super.contains(point)) {
|
17 | return true;
|
18 | }
|
19 | const posNE = {
|
20 | x: point.x - this.canvasSize.width,
|
21 | y: point.y,
|
22 | };
|
23 | if (super.contains(posNE)) {
|
24 | return true;
|
25 | }
|
26 | const posSE = {
|
27 | x: point.x - this.canvasSize.width,
|
28 | y: point.y - this.canvasSize.height,
|
29 | };
|
30 | if (super.contains(posSE)) {
|
31 | return true;
|
32 | }
|
33 | const posSW = {
|
34 | x: point.x,
|
35 | y: point.y - this.canvasSize.height,
|
36 | };
|
37 | return super.contains(posSW);
|
38 | }
|
39 | intersects(range) {
|
40 | if (super.intersects(range)) {
|
41 | return true;
|
42 | }
|
43 | const rect = range;
|
44 | const circle = range;
|
45 | const newPos = {
|
46 | x: range.position.x - this.canvasSize.width,
|
47 | y: range.position.y - this.canvasSize.height,
|
48 | };
|
49 | if (circle.radius !== undefined) {
|
50 | const biggerCircle = new Circle_1.Circle(newPos.x, newPos.y, circle.radius * 2);
|
51 | return super.intersects(biggerCircle);
|
52 | }
|
53 | else if (rect.size !== undefined) {
|
54 | const rectSW = new Rectangle_1.Rectangle(newPos.x, newPos.y, rect.size.width * 2, rect.size.height * 2);
|
55 | return super.intersects(rectSW);
|
56 | }
|
57 | return false;
|
58 | }
|
59 | }
|
60 | exports.CircleWarp = CircleWarp;
|