2023-02-17 11:06:01 +01:00

65 lines
2.3 KiB
JavaScript

(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "tsparticles-engine"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CircleWarp = void 0;
const tsparticles_engine_1 = require("tsparticles-engine");
class CircleWarp extends tsparticles_engine_1.Circle {
constructor(x, y, radius, canvasSize) {
super(x, y, radius);
this.canvasSize = canvasSize;
this.canvasSize = Object.assign({}, canvasSize);
}
contains(point) {
if (super.contains(point)) {
return true;
}
const posNE = {
x: point.x - this.canvasSize.width,
y: point.y,
};
if (super.contains(posNE)) {
return true;
}
const posSE = {
x: point.x - this.canvasSize.width,
y: point.y - this.canvasSize.height,
};
if (super.contains(posSE)) {
return true;
}
const posSW = {
x: point.x,
y: point.y - this.canvasSize.height,
};
return super.contains(posSW);
}
intersects(range) {
if (super.intersects(range)) {
return true;
}
const rect = range, circle = range, newPos = {
x: range.position.x - this.canvasSize.width,
y: range.position.y - this.canvasSize.height,
};
if (circle.radius !== undefined) {
const biggerCircle = new tsparticles_engine_1.Circle(newPos.x, newPos.y, circle.radius * 2);
return super.intersects(biggerCircle);
}
else if (rect.size !== undefined) {
const rectSW = new tsparticles_engine_1.Rectangle(newPos.x, newPos.y, rect.size.width * 2, rect.size.height * 2);
return super.intersects(rectSW);
}
return false;
}
}
exports.CircleWarp = CircleWarp;
});