import { degToRad, radToDeg } from './utils';
import WBVector from './wbVector';
export default class WBVector2 extends WBVector {
    constructor(x, y) {
        super();
        this.x = x;
        this.y = y;
    }
    static fromMC(vec2) {
        return new WBVector2(vec2.x, vec2.y);
    }
    add(other) {
        return new WBVector2(this.x + other.x, this.y + other.y);
    }
    subtract(other) {
        return new WBVector2(this.x - other.x, this.y - other.y);
    }
    transform(transformFn) {
        return new WBVector2(transformFn(this.x), transformFn(this.y));
    }
    multiply(value) {
        return new WBVector2(this.x * value, this.y * value);
    }
    divide(value) {
        return new WBVector2(this.x / value, this.y / value);
    }
    length() {
        return Math.sqrt(this.x ** 2 + this.y ** 2);
    }
    normalize() {
        const length = this.length();
        return new WBVector2(this.x / length, this.y / length);
    }
    dot(other) {
        return this.x * other.x + this.y * other.y;
    }
    rotate(degrees) {
        const angle = degToRad(degrees);
        return new WBVector2(this.x * Math.cos(angle) - this.y * Math.sin(angle), this.x * Math.sin(angle) + this.y * Math.cos(angle));
    }
    angle() {
        return radToDeg(Math.acos(this.x / Math.sqrt(this.x * this.x + this.y * this.y))
            * (this.y / Math.abs(this.y)));
    }
    toDirection() {
        const pitch = -degToRad(this.x);
        const yaw = -degToRad(this.y);
        return {
            x: Math.cos(pitch) * Math.sin(yaw),
            y: Math.sin(pitch),
            z: Math.cos(pitch) * Math.cos(yaw),
        };
    }
    roundAll() {
        return new WBVector2(Math.round(this.x), Math.round(this.y));
    }
    floorAll() {
        return new WBVector2(Math.floor(this.x), Math.floor(this.y));
    }
    ceilAll() {
        return new WBVector2(Math.ceil(this.x), Math.ceil(this.y));
    }
    abs() {
        return new WBVector2(Math.abs(this.x), Math.abs(this.y));
    }
    equals(other) {
        return this.x === other.x && this.y === other.y;
    }
    toString() {
        return `Vec2(${this.x}, ${this.y})`;
    }
    toTuple() {
        return [this.x, this.y];
    }
    *[Symbol.iterator]() {
        yield this.x;
        yield this.y;
    }
}
