function vec2(x = 0, y = 0) { return { x: x, y: y}; } function addVec2(v1, v2) { return { x: v1.x + v2.x, y: v1.y + v2.y }; } function subVec2(v1, v2) { return { x: v1.x - v2.x, y: v1.y - v2.y }; } function scaleVec2(v, s) { return { x: v.x * s, y: v.y * s }; } function dot2(v1, v2) { return v1.x * v2.x + v1.y * v2.y; } function length2(v) { return Math.sqrt(v.x * v.x + v.y * v.y); } function normalize2(v) { const lLength = 1.0 / length2(v); return { x: v.x * lLength, y: v.y * lLength }; } function vec2str(v) { return `(${v.x.toFixed(2)}, ${v.y.toFixed(2)})`; }