File CN_EDGE-Add-comparison-function.patch of Package kicad.9

From 6d343b34ee14cf57521a59ebfcd0428f572085ec Mon Sep 17 00:00:00 2001
From: Michal Suchanek <msuchanek@suse.de>
Date: Sun, 13 Apr 2025 13:38:01 +0200
Subject: [PATCH] CN_EDGE: Add comparison function

---
 pcbnew/connectivity/connectivity_algo.cpp | 26 +++++++++++++++++++++++
 pcbnew/connectivity/connectivity_algo.h   |  2 ++
 pcbnew/connectivity/connectivity_data.cpp |  2 +-
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/pcbnew/connectivity/connectivity_algo.cpp b/pcbnew/connectivity/connectivity_algo.cpp
index 3afb32e401..2be8001e87 100644
--- a/pcbnew/connectivity/connectivity_algo.cpp
+++ b/pcbnew/connectivity/connectivity_algo.cpp
@@ -42,6 +42,32 @@
 #include <core/profile.h>
 #endif
 
+bool CN_EDGE::id_cmp( CN_EDGE aOther ) const
+{
+    auto srcid = m_source->Item()->Parent()->m_Uuid;
+    auto tgtid = m_target->Item()->Parent()->m_Uuid;
+    if (srcid < tgtid) {
+        auto tmp = tgtid;
+        tgtid = srcid;
+        srcid = tmp;
+    }
+
+    auto o_srcid = aOther.m_source->Item()->Parent()->m_Uuid;
+    auto o_tgtid = aOther.m_target->Item()->Parent()->m_Uuid;
+    if (o_srcid < o_tgtid) {
+        auto tmp = o_tgtid;
+        o_tgtid = o_srcid;
+        o_srcid = tmp;
+    }
+    if ((srcid > o_srcid) || (o_srcid > srcid))
+        return srcid > o_srcid;
+
+    if ((srcid > o_tgtid) || (o_tgtid > tgtid))
+        return tgtid > o_tgtid;
+
+    return m_weight > aOther.m_weight;
+}
+
 
 bool CN_CONNECTIVITY_ALGO::Remove( BOARD_ITEM* aItem )
 {
diff --git a/pcbnew/connectivity/connectivity_algo.h b/pcbnew/connectivity/connectivity_algo.h
index 9954f715d7..1fc2011e9c 100644
--- a/pcbnew/connectivity/connectivity_algo.h
+++ b/pcbnew/connectivity/connectivity_algo.h
@@ -86,6 +86,8 @@ public:
         return m_weight < aOther.m_weight;
     }
 
+    bool id_cmp( CN_EDGE aOther ) const;
+
     std::shared_ptr<const CN_ANCHOR> GetSourceNode() const { return m_source; }
     std::shared_ptr<const CN_ANCHOR> GetTargetNode() const { return m_target; }
 
diff --git a/pcbnew/connectivity/connectivity_data.cpp b/pcbnew/connectivity/connectivity_data.cpp
index 170174b453..47258efb3b 100644
--- a/pcbnew/connectivity/connectivity_data.cpp
+++ b/pcbnew/connectivity/connectivity_data.cpp
@@ -722,7 +722,7 @@ void sortEdgesOnSerializationForStableOrdering( std::vector<CN_EDGE>& edges )
     std::sort(edges.begin(), edges.end(),
               [](const CN_EDGE& a, const CN_EDGE& b)
               {
-                  return a.SerializeToString() < b.SerializeToString();
+                  return a.id_cmp(b);
               });
 }
 
-- 
2.47.1

openSUSE Build Service is sponsored by