[Scummvm-git-logs] scummvm master -> f2195d8dbfd17ae50e094710cdc2207387d5415c
aquadran
aquadran at gmail.com
Tue Dec 8 18:13:27 UTC 2020
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
f2195d8dbf MATH: Make implementation of Segment2d more robust
Commit: f2195d8dbfd17ae50e094710cdc2207387d5415c
https://github.com/scummvm/scummvm/commit/f2195d8dbfd17ae50e094710cdc2207387d5415c
Author: Christian Krause (chkr at plauener.de)
Date: 2020-12-08T19:09:08+01:00
Commit Message:
MATH: Make implementation of Segment2d more robust
- prevent division by zero
Changed paths:
math/line2d.cpp
math/utils.h
diff --git a/math/line2d.cpp b/math/line2d.cpp
index 5a269ebddd..9a89485b79 100644
--- a/math/line2d.cpp
+++ b/math/line2d.cpp
@@ -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;
}
diff --git a/math/utils.h b/math/utils.h
index 2d08ee03d6..00060c02a3 100644
--- a/math/utils.h
+++ b/math/utils.h
@@ -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;
}
More information about the Scummvm-git-logs
mailing list