From db229353a43bfa4256ea579339671d5d1067bfa8 Mon Sep 17 00:00:00 2001
From: bartjuhhh <bart.knuiman@wur.nl>
Date: Tue, 5 Sep 2023 14:00:45 +0200
Subject: [PATCH] Fixes routelinks that contain duplicate points (points 1 mtr
 from each other are removed).

---
 ZeroMQTest/Code/OVParsers/Netex.cs | 38 ++++++++++++++++++++++++++++++
 ZeroMQTest/Code/Program.cs         |  2 +-
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/ZeroMQTest/Code/OVParsers/Netex.cs b/ZeroMQTest/Code/OVParsers/Netex.cs
index 5ceb798..3a32bd0 100644
--- a/ZeroMQTest/Code/OVParsers/Netex.cs
+++ b/ZeroMQTest/Code/OVParsers/Netex.cs
@@ -388,6 +388,44 @@ namespace OVAPI.Code.OVParsers
                 kvp.Value.line.destination = kvp.Value.destination;
             }
 
+            // Validate links.
+            foreach( var kvp in routeLinks)
+            {
+                var link = kvp.Value;
+                if (link.points.Count != 0 )
+                {
+                    Debug.Assert( link.points.Count >= 2 );
+                    for (int j = 0; j < link.points.Count-1; j++)
+                    {
+                        var p0 = link.points[j];
+                        var p1 = link.points[j+1];
+                        var dir = new Vector2( p0.rdx, p0.rdy ) - new Vector2 ( p1.rdx, p1.rdy );
+                        var len = dir.Length();
+                        if ( len < 1 )
+                        {
+                            // Remove points less than a meter apart from eachother.
+                            link.points.RemoveAt( j );
+                            j--;
+                            continue;
+                        }
+                    }
+                    if ( link.points.Count == 1 )
+                    {
+                        link.points.Clear();
+                    }
+                }
+
+                // Because of points too close together, may end up with no in between points. Always check from-to distance. Must not be sane value.
+                
+                {
+                    var p0 = link.from;
+                    var p1 = link.to;
+                    var dir = new Vector2( p0.rdx, p0.rdy ) - new Vector2 ( p1.rdx, p1.rdy );
+                    Debug.Assert( Sane( dir.Length() ) );
+                    Debug.Assert( Sane( dir/dir.Length() ) );
+                }
+            }
+
             // Fixup routes (concat routelinks).
             foreach (var kvp in routes)
             {
diff --git a/ZeroMQTest/Code/Program.cs b/ZeroMQTest/Code/Program.cs
index 82dc99a..fa58d12 100644
--- a/ZeroMQTest/Code/Program.cs
+++ b/ZeroMQTest/Code/Program.cs
@@ -42,7 +42,7 @@ class App
             // Update the active simulation with new vehicle updates.
             if( vehicleUpdates != null )
             {
-                var varFilteredList = vehicleUpdates.Where( vhi => vhi.infos[0]=="RET" ).ToList();
+                var varFilteredList = vehicleUpdates.Where( vhi => vhi.infos[0]=="HTM" ).ToList();
                 activeOV.UpdateVehicles( varFilteredList );
             }
 
-- 
GitLab