equals(sphere) 方法用于判断当前的 BoundingSphere 对象是否等同于传入的 sphere 对象。
equals(sphere: BoundingSphere): boolean
sphere: BoundingSphere:必需,表示要比较的 BoundingSphere 对象。boolean:表示比较结果,若两个 BoundingSphere 对象等同,则返回 true,否则返回 false。const sphereA = new Yuka.BoundingSphere(new Yuka.Vector3(10, 0, 0), 5);
const sphereB = new Yuka.BoundingSphere(new Yuka.Vector3(10, 0, 0), 5);
console.log(sphereA.equals(sphereB)); // 输出 true
equals() 方法实质上是通过比较当前 BoundingSphere 对象中心点和半径与传入的 BoundingSphere 对象是否一致来判断两者是否等同。
具体实现过程如下:
BoundingSphere 对象中心点的 x、y、z 坐标分别是否相等,若坐标均相等,则继续执行;否则返回 false。BoundingSphere 对象的半径是否相等,若半径相等,则返回 true;否则返回 false。BoundingSphere 对象中心点坐标时,应该使用一定的容差值,例如 0.0001。