[chronojump] Fixed forceSensor GetForceInPx when max(force) <= 0
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Fixed forceSensor GetForceInPx when max(force) <= 0
- Date: Mon, 30 Oct 2017 12:22:24 +0000 (UTC)
commit 84ff61854bca871896955ff8c406221348038d00
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon Oct 30 13:21:33 2017 +0100
Fixed forceSensor GetForceInPx when max(force) <= 0
src/forceSensor.cs | 6 ++++--
src/util.cs | 9 +++++++++
2 files changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index db13bb9..ec91459 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -75,8 +75,10 @@ public class ForceSensorCapturePoints
public int GetForceInPx(double force)
{
- return Convert.ToInt32( (heightG/2) - ( force * heightG / RealHeightG) );
- //return Convert.ToInt32( heightG - ( force * heightG / RealHeightG) -100 );
+ return Convert.ToInt32(
+ (heightG/2)
+ - ( Util.DivideSafe((force * heightG), (1.0 * RealHeightG)) )
+ );
}
private Gdk.Point getLastPoint()
diff --git a/src/util.cs b/src/util.cs
index 30545cd..b1ad7d7 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -1793,6 +1793,15 @@ public class Util
return DivideSafeFraction(Convert.ToDouble(val1), Convert.ToDouble(val2));
}
+ //Not restricted to values 0-1
+ public static double DivideSafe (double val1, double val2)
+ {
+ if(val1 == 0 || val2 == 0)
+ return 0;
+
+ return val1 / val2;
+ }
+
/*
//converts all values to positive
public static string StringValuesAbsolute (string myString) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]