[chronojump] CairoXY CalculatePaintX/Y handles /0 problems



commit 9316d1deac8e3f29518f4c1681485608d7827286
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Mar 15 16:27:23 2022 +0100

    CairoXY CalculatePaintX/Y handles /0 problems

 src/gui/cairo/xy.cs | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/src/gui/cairo/xy.cs b/src/gui/cairo/xy.cs
index eb44bb301..b49a70a5f 100644
--- a/src/gui/cairo/xy.cs
+++ b/src/gui/cairo/xy.cs
@@ -634,15 +634,20 @@ public abstract class CairoXY : CairoGeneric
        }
 
 
-       //TODO: check if for one value this is /0
        protected override double calculatePaintX (double realX)
        {
-                return totalMargins + (realX - minX) * (graphWidth - totalMargins - totalMargins) / 
(absoluteMaxX - minX);
+                //return totalMargins + (realX - minX) * (graphWidth - totalMargins - totalMargins) / 
(absoluteMaxX - minX);
+                return totalMargins + (realX - minX) * UtilAll.DivideSafe(
+                               graphWidth - totalMargins - totalMargins,
+                               absoluteMaxX - minX);
         }
-       //TODO: check if for one value this is /0
        protected override double calculatePaintY (double realY)
        {
-                return graphHeight - totalMargins - ((realY - minY) * (graphHeight - totalMargins - 
totalMargins) / (absoluteMaxY - minY));
+                //return graphHeight - totalMargins - ((realY - minY) * (graphHeight - totalMargins - 
totalMargins) / (absoluteMaxY - minY));
+               //to avoid /0 problems (eg raceAnalyzer change person: absoluteMaxY-minY = 0
+                return graphHeight - totalMargins - ((realY - minY) * UtilAll.DivideSafe (
+                               graphHeight - totalMargins - totalMargins,
+                               absoluteMaxY - minY));
         }
 
        private double calculateRealX (double graphX)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]