mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-12 03:56:20 +00:00
MATH: Make implementation of Segment2d more robust
- prevent division by zero
This commit is contained in:
parent
6098b45776
commit
f2195d8dbf
@ -169,14 +169,14 @@ bool Segment2d::intersectsSegment(const Segment2d &other, Vector2d *pos) {
|
||||
float nume_b = ((_end.getX() - _begin.getX()) * (other._begin.getY() - _begin.getY())) -
|
||||
((_end.getY() - _begin.getY()) * (other._begin.getX() - _begin.getX()));
|
||||
|
||||
if (denom == 0.0f) {
|
||||
if (denom == 0.0f || d == 0.0f ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
float ua = nume_a / denom;
|
||||
float ub = nume_b / d;
|
||||
|
||||
if (ua < 0 || ua > 1 || ub < 0 || ub > 1) {
|
||||
if (ua < 0.0f || ua > 1.0f || ub < 0.0f || ub > 1.0f) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,15 @@
|
||||
|
||||
namespace Math {
|
||||
|
||||
/* Math::epsilon is a constant with a small value which is used for comparing
|
||||
* floating point numbers.
|
||||
*
|
||||
* The value is based on the previous hard-coded numbers in
|
||||
* Line2d.cpp. Smaller numbers could be used unless they are
|
||||
* smaller than the float granularity.
|
||||
*/
|
||||
static const float epsilon = 0.0001f;
|
||||
|
||||
inline float square(float x) {
|
||||
return x * x;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user