UNPKG

brella-transition

Version:
53 lines (52 loc) 1.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Vec2 = void 0; class Vec2 { constructor(x, y) { this.x = x; this.y = y; } add(x, y) { return new Vec2(this.x + x, this.y + y); } addVec(vec) { return this.add(vec.x, vec.y); } addX(x) { return this.add(x, 0); } addY(y) { return this.add(0, y); } distanceTo(vec) { return Math.sqrt(this.distanceToSqr(vec)); } distanceToSqr(vec) { return this.addVec(vec.inverse()).magnitudeSqr(); } inverse() { return this.scaleAll(-1); } magnitude() { return Math.sqrt(this.magnitudeSqr()); } magnitudeSqr() { return this.x * this.x + this.y * this.y; } rotate(radian) { return new Vec2(this.x * Math.cos(radian) - this.y * Math.sin(radian), this.x * Math.sin(radian) + this.y * Math.cos(radian)); } scale(x, y) { return new Vec2(this.x * x, this.y * y); } scaleAll(k) { return this.scale(k, k); } scaleX(x) { return this.scale(x, 1); } scaleY(y) { return this.scale(1, y); } } exports.Vec2 = Vec2;