Fix torus when a point is exactly at the center of the torus
This commit is contained in:
@@ -91,7 +91,15 @@ impl Region for Torus {
|
||||
// 3. Consider the distance from `p` to `q`.
|
||||
let rel_p = *p - *self.center;
|
||||
let p_on_plane = rel_p - self.normal.with_mag(self.normal.dot(rel_p));
|
||||
let q = p_on_plane.with_mag(self.major_rad.into_inner());
|
||||
let q = if p_on_plane == Vec3::zero() {
|
||||
// avoid division by zero.
|
||||
// The point is precisely on the axis of the torus.
|
||||
// We can choose any point on the major radius to compare it to
|
||||
// and they all give the same answer
|
||||
Vec3::new(self.major_rad.into(), 0.0, 0.0)
|
||||
} else {
|
||||
p_on_plane.with_mag(self.major_rad.into_inner())
|
||||
};
|
||||
let distance_to_circle = (rel_p - q).mag();
|
||||
distance_to_circle < self.minor_rad.into_inner()
|
||||
}
|
||||
|
Reference in New Issue
Block a user