From 60336af34b42051dec320446641c0384525e1604 Mon Sep 17 00:00:00 2001
From: Markus Quaritsch <markus.quaritsch@tugraz.at>
Date: Thu, 21 Apr 2022 10:56:20 +0200
Subject: [PATCH] correct comparison in gearshift position after refactoring
 check if there is a successor/predecessor before checking shift polygon

---
 VectoCommon/VectoCommon/Models/GearshiftPosition.cs          | 4 ++--
 .../Models/SimulationComponent/Data/Gearbox/ShiftPolygon.cs  | 5 +++++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/VectoCommon/VectoCommon/Models/GearshiftPosition.cs b/VectoCommon/VectoCommon/Models/GearshiftPosition.cs
index 9de4158dae..f5ffb0f4c1 100644
--- a/VectoCommon/VectoCommon/Models/GearshiftPosition.cs
+++ b/VectoCommon/VectoCommon/Models/GearshiftPosition.cs
@@ -74,7 +74,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 
 		public GearList(GearshiftPosition[] gearList) => Entries = gearList;
 
-		public bool HasPredecessor(GearshiftPosition cur) => cur.Gear != 0 && cur != Entries[0];
+		public bool HasPredecessor(GearshiftPosition cur) => cur.Gear != 0 && !Entries[0].Equals(cur);
 		
 		public GearshiftPosition Predecessor(GearshiftPosition cur)
 		{
@@ -82,7 +82,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
 			return idx <= 0 ? null : Entries[idx - 1];
 		}
 
-		public bool HasSuccessor(GearshiftPosition cur) => cur.Gear != 0 && cur != Entries[Entries.Length-1];
+		public bool HasSuccessor(GearshiftPosition cur) => cur.Gear != 0 && !Entries[Entries.Length-1].Equals(cur);
 
 		public GearshiftPosition Successor(GearshiftPosition cur)
 		{
diff --git a/VectoCore/VectoCore/Models/SimulationComponent/Data/Gearbox/ShiftPolygon.cs b/VectoCore/VectoCore/Models/SimulationComponent/Data/Gearbox/ShiftPolygon.cs
index 43ae727730..d9f07a5528 100644
--- a/VectoCore/VectoCore/Models/SimulationComponent/Data/Gearbox/ShiftPolygon.cs
+++ b/VectoCore/VectoCore/Models/SimulationComponent/Data/Gearbox/ShiftPolygon.cs
@@ -71,6 +71,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox
 
 		public bool IsBelowDownshiftCurve(NewtonMeter inTorque, PerSecond inAngularVelocity)
 		{
+			if (!Downshift.Any()) {
+				return false;}
 			var section = Downshift.GetSection(entry => entry.AngularSpeed < inAngularVelocity);
 			if (section.Item2.AngularSpeed < inAngularVelocity) {
 				return false;
@@ -99,6 +101,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox
 
 		public bool IsAboveUpshiftCurve(NewtonMeter inTorque, PerSecond inAngularVelocity)
 		{
+			if (!Upshift.Any()) {
+				return false;
+			}
 			var section = Upshift.GetSection(entry => entry.AngularSpeed < inAngularVelocity);
 
 			if (section.Item2.AngularSpeed < inAngularVelocity) {
-- 
GitLab