forked from dimforge/parry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don’t crash mesh/mesh intersection if some mesh coordinates are …
…small denormal numbers (dimforge#214)
- Loading branch information
Showing
4 changed files
with
53 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use crate::math::Real; | ||
|
||
/// Ensures the given coordinate doesn’t go out of the bounds of spade’s acceptable values. | ||
/// | ||
/// Returns 0.0 if the coordinate is smaller than `spade::MIN_ALLOWED_VALUE`. | ||
/// Returns `spade::MAX_ALLOWED_VALUE` the coordinate is larger than `spade::MAX_ALLOWED_VALUE`. | ||
pub fn sanitize_coord(coord: Real) -> Real { | ||
let abs = coord.abs(); | ||
|
||
#[allow(clippy::unnecessary_cast)] | ||
if abs as f64 <= spade::MIN_ALLOWED_VALUE { | ||
return 0.0; | ||
} | ||
|
||
#[cfg(feature = "f64")] | ||
if abs > spade::MAX_ALLOWED_VALUE { | ||
// This cannot happen in f32 since the max is 3.40282347E+38. | ||
return spade::MAX_ALLOWED_VALUE * coord.signum(); | ||
} | ||
|
||
coord | ||
} | ||
|
||
pub fn sanitize_point(point: spade::Point2<Real>) -> spade::Point2<Real> { | ||
spade::Point2::new(sanitize_coord(point.x), sanitize_coord(point.y)) | ||
} |