"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ColorUtils_1 = require("./Utils/ColorUtils");
var Utils_1 = require("./Utils/Utils");
var Absorber = (function () {
    function Absorber(container, options, position) 

    Absorber.prototype.attract = function (particle) {
        var container = this.container;
        var dx = this.position.x - (particle.position.x + particle.offset.x);
        var dy = this.position.y - (particle.position.y + particle.offset.y);
        var distance = Math.sqrt(Math.abs(dx * dx + dy * dy));
        var angle = Math.atan2(dx, dy) * (180 / Math.PI);
        var acceleration = this.mass / Math.pow(distance, 2);
        if (distance < this.size + particle.size.value) {
            var remove = false;
            var sizeFactor = particle.size.value * 0.033;
            if (this.size > particle.size.value && distance < this.size - particle.size.value) {
                container.particles.remove(particle);
                remove = true;
            }
            else {
                particle.size.value -= sizeFactor;
                particle.velocity.horizontal += Math.sin(angle * (Math.PI / 180)) * acceleration;
                particle.velocity.vertical += Math.cos(angle * (Math.PI / 180)) * acceleration;
            }
            if (this.limit === undefined || this.size < this.limit) {
                this.size += sizeFactor;
            }
            this.mass += sizeFactor * this.options.size.density;
            return !remove;
        }
        else {
            particle.velocity.horizontal += Math.sin(angle * (Math.PI / 180)) * acceleration;
            particle.velocity.vertical += Math.cos(angle * (Math.PI / 180)) * acceleration;
            return true;
        }
    };
    Absorber.prototype.resize = function () {
        var initialPosition = this.initialPosition;
        this.position = initialPosition && Utils_1.Utils.isPointInside(initialPosition, this.container.canvas.size) ?
            initialPosition :
            this.calcPosition();
    };
    Absorber.prototype.draw = function () {
        var container = this.container;
        container.canvas.drawAbsorber(this);
    };
    Absorber.prototype.calcPosition = function () {
        var _a;
        var container = this.container;
        var percentPosition = (_a = this.options.position) !== null && _a !== void 0 ? _a : {
            x: Math.random() * 100,
            y: Math.random() * 100,
        };
        return {
            x: percentPosition.x / 100 * container.canvas.size.width,
            y: percentPosition.y / 100 * container.canvas.size.height,
        };
    };
    return Absorber;
}());
exports.Absorber = Absorber;

{
        var _a, _b;
        this.container = container;
        this.initialPosition = position;
        this.options = options;
        var size = options.size.value * container.retina.pixelRatio;
        var random = typeof options.size.random === "boolean" ? options.size.random : options.size.random.enable;
        var minSize = typeof options.size.random === "boolean" ? 1 : options.size.random.minimumValue;
        if (random) {
            size = Utils_1.Utils.randomInRange(minSize, size);
        }
        this.opacity = this.options.opacity;
        this.size = size * container.retina.pixelRatio;
        this.mass = size * options.size.density;
        this.limit = options.size.limit;
        var color = typeof options.color === "string" ? { value: options.color } : options.color;
        this.color = (_a = ColorUtils_1.ColorUtils.colorToRgb(color)) !== null && _a !== void 0 ? _a : {
            b: 0,
            g: 0,
            r: 0,
        };
        this.position = (_b = this.initialPosition) !== null && _b !== void 0 ? _b : this.calcPosition();
    }