BufferGeometry
Object3D
Raycaster
Camera
CubeCamera
PerspectiveCamera
OrthographicCamera
StereoCamera
Clock
Curve
CurvePath
Path
Shape
ShapePath
ArrowHelper
AxesHelper
BoxHelper
Box3Helper
CameraHelper
DirectionalLightHelper
GridHelper
PolarGridHelper
HemisphereLightHelper
PlaneHelper
PointLightHelper
SkeletonHelper
SpotLightHelper
Light
PointLight
RectAreaLight
SpotLight
DirectionalLight
HemisphereLight
LightShadow
PointLightShadow
AnimationLoader
AudioLoader
BufferGeometryLoader
CompressedTextureLoader
CubeTextureLoader
DataTextureLoader
FileLoader
ImageBitmapLoader
ImageLoader
Loader
LoaderUtils
MaterialLoader
ObjectLoader
TextureLoader
LoadingManager
Material
Box2
Box3
Color
Cylindrical
Euler
Frustum
Interpolant
Line3
MathUtils
Matrix3
Matrix4
Plane
Quaternion
AnimationAction
AnimationClip
AnimationMixer
AnimationObjectGroup
AnimationUtils
keyframeTrack
PropertyBinding
PropertyMixer
BooleanKeyframeTrack
QuaternionKeyframeTrack
StringKeyframeTrack
Audio
AudioAnalyser
AudioContext
AudioListener
PositionalAudio

Box2.equals()

The equals() method is a built-in function of the three.js library that is used to compare two objects of the Box2 class to see if their properties match. The Box2 class represents a 2D axis-aligned bounding box, which is defined by the coordinates of its two opposite corners.

The equals() method compares the min and max properties of the two Box2 objects, and returns true if they are both equal. Otherwise, it returns false.

Syntax

equals(box: Box2): boolean
  • box - The Box2 object to compare with the calling object.

Examples

const box1 = new THREE.Box2(
    new THREE.Vector2(-1, -1), 
    new THREE.Vector2(1, 1)
);
const box2 = new THREE.Box2(
    new THREE.Vector2(-1, -1), 
    new THREE.Vector2(1, 1)
);
const box3 = new THREE.Box2(
    new THREE.Vector2(-1, -1), 
    new THREE.Vector2(2, 2)
);

console.log(box1.equals(box2)); // Output: true
console.log(box1.equals(box3)); // Output: false

In this example, we created three Box2 objects: box1, box2, and box3.

The first console.log() statement calls the equals() method of box1 and passes box2 as the argument. Since both boxes have the same coordinates, the function will return true.

The second console.log() statement calls the equals() method of box1 and passes box3 as the argument. Since the maximum x and y values are different between the two boxes, the function will return false.

Remarks

Note that the equals() method only compares the min and max values of the two Box2 objects, and does not take into account other properties that may differ. For example, if two boxes have the same coordinates but different uuid values, the equals() method will still return true.

If you need a more strict comparison that takes into account all properties, you should write your own comparison function.