UNPKG

@fimbul-works/vec

Version:

A comprehensive TypeScript vector math library providing 2D, 3D, and 4D vector operations with a focus on performance and type safety.

17 lines (16 loc) 652 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.reflect2D = void 0; const dot_2d_js_1 = require("./dot-2d.js"); /** * Reflects the vector across a normal vector. * The normal vector should be normalized (unit length). * @param {ArrayVector2D} xy - Vector as `[x, y]` to reflect * @param {ArrayVector2D} normal - Normal vector to reflect across (must be normalized) * @returns {ArrayVector2D} The reflected vector */ const reflect2D = (xy, normal) => { const dot = (0, dot_2d_js_1.dot2D)(xy, normal); return [xy[0] - 2 * dot * normal[0], xy[1] - 2 * dot * normal[1]]; }; exports.reflect2D = reflect2D;