From fe2d8fe1bba569c289cf65dc6bef88082429b8d3 Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Wed, 10 Aug 2016 09:35:08 +0200
Subject: [PATCH] more checks for above/below upshift/downshift polygons to
 shift polygon

---
 .../ComponentData/AuxiliaryDataReader.cs      |  2 +-
 .../Data/Gearbox/ShiftPolygon.cs              | 39 ++++++++++++++-----
 .../SimulationComponent/Impl/ShiftStrategy.cs | 17 +-------
 3 files changed, 32 insertions(+), 26 deletions(-)

diff --git a/VectoCore/VectoCore/InputData/Reader/ComponentData/AuxiliaryDataReader.cs b/VectoCore/VectoCore/InputData/Reader/ComponentData/AuxiliaryDataReader.cs
index 83aef8d8b7..620d6018fc 100644
--- a/VectoCore/VectoCore/InputData/Reader/ComponentData/AuxiliaryDataReader.cs
+++ b/VectoCore/VectoCore/InputData/Reader/ComponentData/AuxiliaryDataReader.cs
@@ -34,7 +34,7 @@ namespace TUGraz.VectoCore.InputData.Reader.ComponentData
 				var map = ReadAuxMap(id, table);
 
 				return new AuxiliaryData(transmissionRatio, efficiencyToEngine, efficiencyToSupply, map);
-				;
+				
 			} catch (FileNotFoundException e) {
 				throw new VectoException("Auxiliary file not found: " + fileName, e);
 			}
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Data/Gearbox/ShiftPolygon.cs b/VectoCore/VectoCore/Models/SimulationComponent/Data/Gearbox/ShiftPolygon.cs
index 5c50170cc4..e427d65f31 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Data/Gearbox/ShiftPolygon.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Data/Gearbox/ShiftPolygon.cs
@@ -65,6 +65,25 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox
 			get { return _downShiftPolygon.AsReadOnly(); }
 		}
 
+		public bool IsBelowDownshiftCurve(NewtonMeter inTorque, PerSecond inAngularVelocity)
+		{
+			var section = Downshift.GetSection(entry => entry.AngularSpeed < inAngularVelocity);
+			if (section.Item2.AngularSpeed < inAngularVelocity) {
+				return false;
+			}
+			return IsLeftOf(inAngularVelocity, inTorque, section);
+		}
+
+		public bool IsAboveUpshiftCurve(NewtonMeter inTorque, PerSecond inAngularVelocity)
+		{
+			var section = Upshift.GetSection(entry => entry.AngularSpeed < inAngularVelocity);
+
+			if (section.Item2.AngularSpeed < inAngularVelocity) {
+				return true;
+			}
+			return IsRightOf(inAngularVelocity, inTorque, section);
+		}
+
 		/// <summary>
 		/// Tests if current power request is on the left side of the shiftpolygon segment
 		/// </summary>
@@ -74,13 +93,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox
 		/// <returns><c>true</c> if current power request is on the left side of the shiftpolygon segment; otherwise, <c>false</c>.</returns>
 		/// <remarks>Computes a simplified cross product for the vectors: from--X, from--to and checks
 		/// if the z-component is positive (which means that X was on the right side of from--to).</remarks>
-		public static bool IsLeftOf(PerSecond angularSpeed, NewtonMeter torque,
+		protected static bool IsLeftOf(PerSecond angularSpeed, NewtonMeter torque,
 			Tuple<ShiftPolygonEntry, ShiftPolygonEntry> segment)
 		{
-			var abX = segment.Item2.AngularSpeed - segment.Item1.AngularSpeed;
-			var abY = segment.Item2.Torque - segment.Item1.Torque;
-			var acX = angularSpeed - segment.Item1.AngularSpeed;
-			var acY = torque - segment.Item1.Torque;
+			var abX = segment.Item2.AngularSpeed.Value() - segment.Item1.AngularSpeed.Value();
+			var abY = segment.Item2.Torque.Value() - segment.Item1.Torque.Value();
+			var acX = angularSpeed.Value() - segment.Item1.AngularSpeed.Value();
+			var acY = torque.Value() - segment.Item1.Torque.Value();
 			var z = abX * acY - abY * acX;
 			return z.IsGreater(0);
 		}
@@ -94,13 +113,13 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox
 		/// <returns><c>true</c> if current power request is on the left side of the shiftpolygon segment; otherwise, <c>false</c>.</returns>
 		/// <remarks>Computes a simplified cross product for the vectors: from--X, from--to and checks
 		/// if the z-component is negative (which means that X was on the left side of from--to).</remarks>
-		public static bool IsRightOf(PerSecond angularSpeed, NewtonMeter torque,
+		protected static bool IsRightOf(PerSecond angularSpeed, NewtonMeter torque,
 			Tuple<ShiftPolygonEntry, ShiftPolygonEntry> segment)
 		{
-			var abX = segment.Item2.AngularSpeed - segment.Item1.AngularSpeed;
-			var abY = segment.Item2.Torque - segment.Item1.Torque;
-			var acX = angularSpeed - segment.Item1.AngularSpeed;
-			var acY = torque - segment.Item1.Torque;
+			var abX = segment.Item2.AngularSpeed.Value() - segment.Item1.AngularSpeed.Value();
+			var abY = segment.Item2.Torque.Value() - segment.Item1.Torque.Value();
+			var acX = angularSpeed.Value() - segment.Item1.AngularSpeed.Value();
+			var acY = torque.Value() - segment.Item1.Torque.Value();
 			var z = abX * acY - abY * acX;
 			return z.IsSmaller(0);
 		}
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Impl/ShiftStrategy.cs b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ShiftStrategy.cs
index f52e98af08..261a7d1027 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Impl/ShiftStrategy.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Impl/ShiftStrategy.cs
@@ -121,13 +121,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			if (gear <= 1) {
 				return false;
 			}
-
-			var downSection = Data.Gears[gear].ShiftPolygon.Downshift.GetSection(entry => entry.AngularSpeed < inEngineSpeed);
-			if (downSection.Item2.AngularSpeed < inEngineSpeed) {
-				return false;
-			}
-
-			return ShiftPolygon.IsLeftOf(inEngineSpeed, inTorque, downSection);
+			return Data.Gears[gear].ShiftPolygon.IsBelowDownshiftCurve(inTorque, inEngineSpeed);
 		}
 
 		/// <summary>
@@ -142,14 +136,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			if (gear >= Data.Gears.Count) {
 				return false;
 			}
-
-			var upSection = Data.Gears[gear].ShiftPolygon.Upshift.GetSection(entry => entry.AngularSpeed < inEngineSpeed);
-
-			if (upSection.Item2.AngularSpeed < inEngineSpeed) {
-				return true;
-			}
-
-			return ShiftPolygon.IsRightOf(inEngineSpeed, inTorque, upSection);
+			return Data.Gears[gear].ShiftPolygon.IsAboveUpshiftCurve(inTorque, inEngineSpeed);
 		}
 	}
 }
\ No newline at end of file
-- 
GitLab