kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #25222
Re: [PATCH 13/16] Avoid static variable in wire merge
Hi Wayne,
On 27.06.2016 20:21, Wayne Stambaugh wrote:
> This patch and 0014-Reserve-appropriate-space-in-local-vector.patch have
> been committed to the product branch r6950.
I have an even better implementation by now, using std::min and
std::max, that I posted a few days later. That patch, rebased onto the
current state, is attached.
Sorry for the extra work. :/
Simon
commit e07a906e90e461c77fbef21c2100d297fe73b85f
Author: Simon Richter <Simon.Richter@xxxxxxxxxx>
Date: Mon Jun 20 03:07:52 2016 +0200
Rewrite line merging without static vector and sort
The static vector is a massive code smell, and as we're only interested in
the most extreme elements, we can simply use std::min and std::max with
custom comparison functions instead.
diff --git a/eeschema/sch_line.cpp b/eeschema/sch_line.cpp
index c70ff12..e044927 100644
--- a/eeschema/sch_line.cpp
+++ b/eeschema/sch_line.cpp
@@ -270,17 +270,6 @@ void SCH_LINE::Rotate( wxPoint aPosition )
/*
- * helper sort function, used by MergeOverlap
- * sorts ref and test by x values, or (for same x values) by y values
- */
-bool sort_by_ends_position(const wxPoint * ref, const wxPoint * tst )
-{
- if( ref->x == tst->x )
- return ref->y < tst->y;
- return ref->x < tst->x;
-}
-
-/*
* MergeOverlap try to merge 2 lines that are colinear.
* this function expects these 2 lines have at least a common end
*/
@@ -346,16 +335,18 @@ bool SCH_LINE::MergeOverlap( SCH_LINE* aLine )
// for horizontal segments the uppermost and the lowest point
if( colinear )
{
- std::vector <wxPoint*> candidates;
- candidates.reserve( 4 );
- candidates.push_back( &m_start );
- candidates.push_back( &m_end );
- candidates.push_back( &aLine->m_start );
- candidates.push_back( &aLine->m_end );
- sort( candidates.begin(), candidates.end(), sort_by_ends_position );
- wxPoint tmp = *candidates[3];
- m_start = *candidates[0];
- m_end = tmp;
+ auto less = []( const wxPoint& lhs, const wxPoint& rhs ) -> bool
+ {
+ if( lhs.x == rhs.x )
+ return lhs.y < rhs.y;
+ return lhs.x < rhs.x;
+ };
+
+ wxPoint top_left = std::min( { m_start, m_end, aLine->m_start, aLine->m_end }, less );
+ wxPoint bottom_right = std::max( { m_start, m_end, aLine->m_start, aLine->m_end }, less );
+
+ m_start = top_left;
+ m_end = bottom_right;
return true;
}
return false;
Attachment:
signature.asc
Description: OpenPGP digital signature
Follow ups
References
-
[PATCH 00/16] Simple patches
From: Simon Richter, 2016-06-07
-
[PATCH 01/16] Fix spelling "propage" -> "propagate"
From: Simon Richter, 2016-06-07
-
[PATCH 02/16] Add missing dependency github_plugin -> pcbcommon
From: Simon Richter, 2016-06-07
-
[PATCH 03/16] Clarify ERC: we're iterating netlist items, not nets
From: Simon Richter, 2016-06-07
-
[PATCH 04/16] Explain how ERC works.
From: Simon Richter, 2016-06-07
-
[PATCH 05/16] Cache netlist item during ERC
From: Simon Richter, 2016-06-07
-
[PATCH 06/16] Check sorting of netlist during ERC
From: Simon Richter, 2016-06-07
-
[PATCH 07/16] Kill unused NETLIST_EXPORTER_GENERIC::writeListOfNets
From: Simon Richter, 2016-06-07
-
[PATCH 08/16] Drop extra copy ctors from IFSG_NODE
From: Simon Richter, 2016-06-07
-
[PATCH 09/16] Replace boost::shared_ptr with std::shared_ptr
From: Simon Richter, 2016-06-07
-
[PATCH 10/16] Replace unshared boost::shared_array with std::unique_ptr
From: Simon Richter, 2016-06-07
-
[PATCH 11/16] Clarify ownership semantics
From: Simon Richter, 2016-06-07
-
[PATCH 12/16] Make NETLIST_OBJECT::GetConnectionType() const
From: Simon Richter, 2016-06-07
-
[PATCH 13/16] Avoid static variable in wire merge
From: Simon Richter, 2016-06-07
-
Re: [PATCH 13/16] Avoid static variable in wire merge
From: Wayne Stambaugh, 2016-06-27