eeschema: Move comparison for DANGLING_ENDS

The comparison functions belong inside the class if we are using them to
test the validity of the class.
This commit is contained in:
Seth Hillbrand 2020-01-03 05:36:13 -08:00
parent b18b08e944
commit 3fb085a0b4
2 changed files with 28 additions and 19 deletions

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com * Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2004-2019 KiCad Developers, see change_log.txt for contributors. * Copyright (C) 2004-2020 KiCad Developers, see change_log.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -68,13 +68,13 @@ class DANGLING_END_ITEM
{ {
private: private:
/// A pointer to the connectable object. /// A pointer to the connectable object.
EDA_ITEM* m_item; EDA_ITEM* m_item;
/// The position of the connection point. /// The position of the connection point.
wxPoint m_pos; wxPoint m_pos;
/// The type of connection of #m_item. /// The type of connection of #m_item.
DANGLING_END_T m_type; DANGLING_END_T m_type;
/// A pointer to the parent object (in the case of pins) /// A pointer to the parent object (in the case of pins)
const EDA_ITEM* m_parent; const EDA_ITEM* m_parent;
@ -97,6 +97,28 @@ public:
m_parent = aParent; m_parent = aParent;
} }
bool operator==( const DANGLING_END_ITEM& aB )
{
return GetItem() == aB.GetItem()
&& GetPosition() == aB.GetPosition()
&& GetType() == aB.GetType()
&& GetParent() == aB.GetParent();
}
bool operator!=( const DANGLING_END_ITEM& aB )
{
return GetItem() != aB.GetItem()
|| GetPosition() != aB.GetPosition()
|| GetType() != aB.GetType()
|| GetParent() != aB.GetParent();;
}
bool operator<( const DANGLING_END_ITEM& rhs ) const
{
return( m_pos.x < rhs.m_pos.x || ( m_pos.x == rhs.m_pos.x && m_pos.y < rhs.m_pos.y )
|| ( m_pos == rhs.m_pos && m_item < rhs.m_item ) );
}
wxPoint GetPosition() const { return m_pos; } wxPoint GetPosition() const { return m_pos; }
EDA_ITEM* GetItem() const { return m_item; } EDA_ITEM* GetItem() const { return m_item; }
const EDA_ITEM* GetParent() const { return m_parent; } const EDA_ITEM* GetParent() const { return m_parent; }

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2019 KiCad Developers, see CHANGELOG.TXT for contributors. * Copyright (C) 2019-2020 KiCad Developers, see CHANGELOG.TXT for contributors.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -60,19 +60,6 @@ std::ostream& operator<<( std::ostream& os, DANGLING_END_ITEM const& d )
return os; return os;
} }
bool operator==( const DANGLING_END_ITEM& aA, const DANGLING_END_ITEM& aB )
{
return aA.GetItem() == aB.GetItem()
&& aA.GetPosition() == aB.GetPosition()
&& aA.GetType() == aB.GetType()
&& aA.GetParent() == aB.GetParent();
}
bool operator!=( const DANGLING_END_ITEM& aA, const DANGLING_END_ITEM& aB )
{
return !( aA == aB );
}
/** /**
* Declare the test suite * Declare the test suite
*/ */