The Box2.clone()
method creates a new Box2
instance with the same dimensions and position as the original Box2
instance. The newly created box is an exact replica of the original one and can be modified independently.
box2.clone()
This method returns a new Box2
instance with the same dimensions and position as the original Box2
instance.
const originalBox = new THREE.Box2(new THREE.Vector2(-1, -1), new THREE.Vector2(1, 1));
const clonedBox = originalBox.clone();
clonedBox.expandByScalar(0.5);
console.log(originalBox.min); // Output: (-1, -1)
console.log(originalBox.max); // Output: (1, 1)
console.log(clonedBox.min); // Output: (-1.5, -1.5)
console.log(clonedBox.max); // Output: (1.5, 1.5)
In this example, we create an original Box2
instance with a minimum point of (-1, -1) and a maximum point of (1, 1). Then, we clone the box and expand the cloned box by 0.5 units in all directions. When we log the minimum and maximum points of the original and cloned boxes, we can see that the cloned box is an exact replica of the original one, except that it has been expanded.
Box2
class represents a 2D axis-aligned bounding box.