Files
lan-manager/web/node_modules/gl-vec2/limit.js
openclaw 0a5f6a8047 Initial commit: Lan-manager project code
- Go backend (server/)
- Frontend (web/, server/static/)
- Database and deployment files
- Scripts and docs

Co-Authored-By: 狸花猫/Claude-Qwen3.6-Plus 🐾
2026-04-20 00:52:58 +08:00

25 lines
493 B
JavaScript

module.exports = limit;
/**
* Limit the magnitude of this vector to the value used for the `max`
* parameter.
*
* @param {vec2} the vector to limit
* @param {Number} max the maximum magnitude for the vector
* @returns {vec2} out
*/
function limit(out, a, max) {
var mSq = a[0] * a[0] + a[1] * a[1];
if (mSq > max * max) {
var n = Math.sqrt(mSq);
out[0] = a[0] / n * max;
out[1] = a[1] / n * max;
} else {
out[0] = a[0];
out[1] = a[1];
}
return out;
}