@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
27 lines (26 loc) • 671 B
JavaScript
;
import { NamedFunction3 } from "./_Base";
export class nearestPosition extends NamedFunction3 {
static type() {
return "nearestPosition";
}
func(v3, positions, target) {
target.set(0, 0, 0);
if (positions) {
let currentDist = -1;
let minDist = null;
let nearestPosition2;
for (let position of positions) {
currentDist = position.distanceTo(v3);
if (minDist == null || currentDist < minDist) {
nearestPosition2 = position;
minDist = currentDist;
}
}
if (nearestPosition2 != null) {
target.copy(nearestPosition2);
}
}
return target;
}
}