I believe I’ve found a bug with the THREE.Box3
class, and would like someone to help me find out if I missed a step before submitting it to Github.
Whenever I create new THREE.Box3()
, its limits range are by default from -Infinity to +Infinity, according to the docs. With that in mind, using .clampPoint()
with these limits should perform no clamping whatsoever. Here’s my code:
// This box should have bounds of
// min: -Infinity
// max: +Infinity
var boundingBox = new THREE.Box3();
var sourceVector = new THREE.Vector3(-5, 10, 3);
var clampedVector = new THREE.Vector3();
// This shouldn't perform any clamping,
// since limits are infinity
boundingBox.clampPoint(sourceVector, clampedVector);
// However, this outputs
// { x: Infinity, y: Infinity, z: Infinity }
console.log(clampedVector);
You can see this bug in action in this fiddle.
I believe the source of this bug is on lines 11 and 12: https://github.com/mrdoob/three.js/blob/dev/src/math/Box3.js#L11 because min
is assigned +Infinity
, and max
is assigned -Infinity
, but it should be the opposite. This leads to wrong results when the Vec3
is being clamped