File CN_EDGE-Add-comparison-function.patch of Package kicad.8
From 6c725d65e142aea5d171e0d2ce1010bca5af5d33 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 093a6415c8..1b0100ed32 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 862e81050d..a684cb8d54 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 dcdffaa10a..893b33f896 100644
--- a/pcbnew/connectivity/connectivity_data.cpp
+++ b/pcbnew/connectivity/connectivity_data.cpp
@@ -708,7 +708,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