{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * An immutable 2D Vector that supports various operations.\n * @public\n */\nexport class Vector {\n  public readonly x: number\n  public readonly y: number\n  /**\n   * Create a vector with the given components.\n   * @param x - The component of the x-axis.\n   * @param y - The component of the y-axis.\n   * @returns The vector.\n   */\n  public static of([x, y]: [number, number]): Vector {\n    return new Vector(x, y)\n  }\n\n  /**\n   * Create a vector with the given components.\n   * @param x - The component of the x-axis.\n   * @param y - The component of the y-axis.\n   * @returns The vector.\n   */\n  public constructor(\n    x: number,\n    y: number,\n  ) {\n    this.x = x\n    this.y = y\n  }\n\n  /**\n   * Add another vector to the vector.\n   * @param val - The vector to be added.\n   * @returns The resulting vector of the addition.\n   */\n  public add(val: Vector): Vector {\n    return new Vector(this.x + val.x, this.y + val.y)\n  }\n\n  /**\n   * Subtract another vector from the vector.\n   * @param val - The vector to be added.\n   * @returns The resulting vector of the subtraction.\n   */\n  public subtract(val: Vector): Vector {\n    return new Vector(this.x - val.x, this.y - val.y)\n  }\n\n  /**\n   * Multiply the vector by a scalar.\n   * @param scalar - The scalar the vector will be multiplied by.\n   * @returns The resulting vector of the multiplication.\n   */\n  public multiply(scalar: number): Vector {\n    return new Vector(this.x * scalar, this.y * scalar)\n  }\n\n  /**\n   * Divide the vector by a scalar.\n   * @param scalar - The scalar the vector will be divided by.\n   * @returns The resulting vector of the division.\n   */\n  public divide(scalar: number): Vector {\n    return new Vector(this.x / scalar, this.y / scalar)\n  }\n\n  /**\n   * Calculate the dot product of the vector and another vector.\n   * @param other - The other vector used for calculating the dot product.\n   * @returns The dot product.\n   */\n  public dot(other: Vector): number {\n    return this.x * other.x + this.y * other.y\n  }\n\n  /**\n   * Calculate the cross product of the vector and another vector. The cross product of two vectors `a` and `b` is defined as `a.x * b.y - a.y * b.x`.\n   * @param other - The other vector used for calculating the cross product.\n   * @returns The cross product.\n   */\n  public cross(other: Vector): number {\n    return this.x * other.y - other.x * this.y\n  }\n\n  /**\n   * Calculate the Hadamard product of the vector and another vector.\n   * @param other - The other vector used for calculating the Hadamard product.\n   * @returns The Hadamard product.\n   */\n  public hadamard(other: Vector): Vector {\n    return new Vector(this.x * other.x, this.y * other.y)\n  }\n\n  /**\n   * Calculate the length of the vector using the L2 norm.\n   * @returns The length.\n   */\n  public length(): number {\n    return Math.sqrt(this.x ** 2 + this.y ** 2)\n  }\n\n  /**\n   * Normalize the vector using the L2 norm.\n   * @returns The normalized vector.\n   */\n  public normalize(): Vector {\n    const length = this.length()\n    return new Vector(this.x / length, this.y / length)\n  }\n\n  /**\n   * Rotate the vector by the given radians counterclockwise.\n   * @param radians - The radians the vector will be rotated by.\n   * @returns The rotated vector.\n   */\n  public rotateByRadians(radians: number): Vector {\n    const cos = Math.cos(radians)\n    const sin = Math.sin(radians)\n    return new Vector(this.x * cos - this.y * sin, this.x * sin + this.y * cos)\n  }\n\n  /**\n   * Rotate the vector by the given degrees counterclockwise.\n   * @param degrees - The degrees the vector will be rotated by.\n   * @returns The rotated vector.\n   */\n  public rotateByDegrees(degrees: number): Vector {\n    return this.rotateByRadians((degrees * Math.PI) / 180)\n  }\n}\n"],"mappings":";;;;;AAIA,IAAa,SAAb,MAAa,OAAO;CAClB,AAAgB;CAChB,AAAgB;;;;;;;CAOhB,OAAc,GAAG,CAAC,GAAG,IAA8B;AACjD,SAAO,IAAI,OAAO,GAAG,EAAE;;;;;;;;CASzB,AAAO,YACL,GACA,GACA;AACA,OAAK,IAAI;AACT,OAAK,IAAI;;;;;;;CAQX,AAAO,IAAI,KAAqB;AAC9B,SAAO,IAAI,OAAO,KAAK,IAAI,IAAI,GAAG,KAAK,IAAI,IAAI,EAAE;;;;;;;CAQnD,AAAO,SAAS,KAAqB;AACnC,SAAO,IAAI,OAAO,KAAK,IAAI,IAAI,GAAG,KAAK,IAAI,IAAI,EAAE;;;;;;;CAQnD,AAAO,SAAS,QAAwB;AACtC,SAAO,IAAI,OAAO,KAAK,IAAI,QAAQ,KAAK,IAAI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