{"size": 826, "ext": "js", "max_stars_repo_path": "CG-SoftwareRenderer2/scripts/vec2.js", "max_stars_repo_name": "FanqingM/TJCG", "max_stars_repo_stars_event_min_datetime": "2021-09-21T05:48:11.000Z", "max_stars_repo_stars_event_max_datetime": "2021-09-21T05:48:11.000Z", "max_issues_repo_path": "CG-SoftwareRenderer2/scripts/vec2.js", "max_issues_repo_name": "FanqingM/TJCG", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CG-SoftwareRenderer2/scripts/vec2.js", "max_forks_repo_name": "FanqingM/TJCG", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 14.75, "max_line_length": 60, "alphanum_fraction": 0.4128329298}
export class Vector2
{
    constructor(x, y)
    {
        this.x = x;
        this.y = y;
    }

    normalize()
    {
        const len = this.getLength();

        this.x /= len;
        this.y /= len;
    }

    getLength()
    {
        return Math.sqrt(this.x * this.x + this.y * this.y);
    }

    dot(v)
    {
        return this.x * v.x + this.y * v.y;
    }

    cross(v)
    {
        return this.y * v.x - this.x * v.y;
    }

    add(v)
    {
        return new Vector2(this.x + v.x, this.y + v.y);
    }

    sub(v)
    {
        return new Vector2(this.x - v.x, this.y - v.y);
    }

    div(v)
    {
        return new Vector2(this.x / v, this.y / v);
    }

    mul(v)
    {
        return new Vector2(this.x * v, this.y * v);
    }

    equals(v)
    {
        return this.x == v.x && this.y == v.y;
    }
}