aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2021-01-04 10:37:28 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-01-04 11:20:51 -0800
commitce0f64df2ef032d1a6a453569689dce4fe83cb04 (patch)
treecc2b19c0ccb0090a6d5b4f897839952ce12fd391
parentc63994f775338bacc1948e54c0f482f2ec8c364c (diff)
downloadsubsurface-ce0f64df2ef032d1a6a453569689dce4fe83cb04.tar.gz
stats: fix line segment intersection math
Linear algebra class was a while ago, but somehow this does look more logical to me. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--stats/statsview.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/stats/statsview.cpp b/stats/statsview.cpp
index 6dd858e96..817f8001d 100644
--- a/stats/statsview.cpp
+++ b/stats/statsview.cpp
@@ -686,9 +686,9 @@ void StatsView::addLinearRegression(double a, double b, double minX, double maxX
// but owing to floating point imprecision, let's test again.
if ((y1 < minY || y1 > maxY || y2 < minY || y2 > maxY) && fabs(a) > 0.0001) {
// Intersections with y = minY and y = maxY lines
- double intersect_x1 = minY / a - b;
- double intersect_x2 = maxY / a - b;
- if (intersect_x1 < intersect_x2)
+ double intersect_x1 = (minY - b) / a;
+ double intersect_x2 = (maxY - b) / a;
+ if (intersect_x1 > intersect_x2)
std::swap(intersect_x1, intersect_x2);
minX = std::max(minX, intersect_x1);
maxX = std::min(maxX, intersect_x2);