All files / src/extensions extensionsBounds2.js

100% Statements 56/56
100% Branches 28/28
100% Functions 15/15
100% Lines 56/56

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73  1x 1x 1x 1x 1x 1x 1x 1x   1x 20x 20x 20x   1x 19x 19x 19x 19x   1x 1x   1x 1x   1x 1x   1x 5x   1x 4x   1x 7x   1x 7x   1x 8x   1x 8x   1x 6x   1x 23x 9x 14x   1x 8x 6x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x    
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const bounds2_1 = require("../models/bounds2");
const vector2_1 = require("../models/vector2");
bounds2_1.Bounds2.prototype.set = function (bounds) {
    this.x = bounds.x;
    this.y = bounds.y;
    this.width = bounds.width;
    this.height = bounds.height;
};
bounds2_1.Bounds2.prototype.getScale = function (bounds) {
    const scaleX = this.width / (bounds.width);
    const scaleY = this.height / (bounds.height);
    return scaleX < scaleY ? scaleX : scaleY;
};
bounds2_1.Bounds2.prototype.getCenter = function (bounds) {
    const vector = new vector2_1.Vector2();
    vector.x = (bounds.x + bounds.width * 0.5) - this.width * 0.5;
    vector.y = (bounds.y + bounds.height * 0.5) - this.height * 0.5;
    return vector;
};
bounds2_1.Bounds2.prototype.getRight = function () {
    return this.x + this.width;
};
bounds2_1.Bounds2.prototype.getBottom = function () {
    return this.y + this.height;
};
bounds2_1.Bounds2.prototype.getTopRight = function () {
    return new vector2_1.Vector2(this.x + this.width, this.y);
};
bounds2_1.Bounds2.prototype.getBottomRight = function () {
    return new vector2_1.Vector2(this.x + this.width, this.y + this.height);
};
bounds2_1.Bounds2.prototype.getBottomLeft = function () {
    return new vector2_1.Vector2(this.x, this.y + this.height);
};
bounds2_1.Bounds2.prototype.intersectTop = function (bounds) {
    return this.y <= bounds.y + bounds.height;
};
bounds2_1.Bounds2.prototype.intersectBottom = function (bounds) {
    return this.y + this.height >= bounds.y;
};
bounds2_1.Bounds2.prototype.intersectLeft = function (bounds) {
    return this.x <= bounds.x + bounds.width;
};
bounds2_1.Bounds2.prototype.intersectRight = function (bounds) {
    return this.x + this.width >= bounds.x;
};
bounds2_1.Bounds2.prototype.intersectsWith = function (bounds) {
    return this.intersectLeft(bounds) && this.intersectRight(bounds) && this.intersectTop(bounds) && this.intersectBottom(bounds);
};
bounds2_1.Bounds2.prototype.contains = function (bounds) {
    if (this.width === 0 || this.height === 0)
        return false;
    return this.x <= bounds.x && this.x + this.width >= bounds.x + bounds.width && this.y <= bounds.y && this.y + this.height >= bounds.y + bounds.height;
};
bounds2_1.Bounds2.prototype.combine = function (bounds) {
    if (this.width === 0 || this.height === 0 || bounds.width === 0 || bounds.height === 0)
        return bounds;
    const aBottomLeft = this.getBottomLeft();
    const bBottomLeft = bounds.getBottomLeft();
    const aBottomRight = this.getBottomRight();
    const bBottomRight = bounds.getBottomRight();
    const bottomLeft = aBottomLeft.y > bBottomLeft.y ? aBottomLeft.y : bBottomLeft.y;
    const bottomRight = aBottomRight.x > bBottomRight.x ? aBottomRight.x : bBottomRight.x;
    const combined = new bounds2_1.Bounds2();
    combined.x = this.x < bounds.x ? this.x : bounds.x;
    combined.y = this.y < bounds.y ? this.y : bounds.y;
    combined.width = bottomRight - combined.x;
    combined.height = bottomLeft - combined.y;
    return combined;
};