2019-06-25 23:39:58 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-10-06 02:46:53 +00:00
|
|
|
* Copyright (C) 2020 KiCad Developers, see AUTHORS.TXT for contributors.
|
2019-06-25 23:39:58 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 3
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-3.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 3 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Test suite for SCH_SHEET
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <convert_to_biu.h>
|
2021-10-05 16:57:25 +00:00
|
|
|
#include <ignore.h>
|
2019-06-25 23:39:58 +00:00
|
|
|
#include <sch_junction.h>
|
|
|
|
#include <sch_no_connect.h>
|
2021-02-06 22:20:31 +00:00
|
|
|
#include <qa_utils/wx_utils/unit_test_utils.h>
|
2019-06-25 23:39:58 +00:00
|
|
|
|
|
|
|
// Code under test
|
|
|
|
#include <sch_rtree.h>
|
|
|
|
|
2020-02-28 21:55:51 +00:00
|
|
|
#include "uuid_test_utils.h"
|
2019-06-25 23:39:58 +00:00
|
|
|
|
2021-02-06 22:20:31 +00:00
|
|
|
#include <qa_utils/wx_utils/wx_assert.h>
|
2019-06-25 23:39:58 +00:00
|
|
|
|
|
|
|
class TEST_SCH_RTREE_FIXTURE
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TEST_SCH_RTREE_FIXTURE() : m_tree()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
EE_RTREE m_tree;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Declare the test suite
|
|
|
|
*/
|
|
|
|
BOOST_FIXTURE_TEST_SUITE( SchRtree, TEST_SCH_RTREE_FIXTURE )
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check default iterators
|
|
|
|
*/
|
|
|
|
BOOST_AUTO_TEST_CASE( Default )
|
|
|
|
{
|
|
|
|
BOOST_CHECK_EQUAL( m_tree.empty(), true );
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
for( auto item : m_tree )
|
|
|
|
{
|
2021-10-05 16:57:25 +00:00
|
|
|
ignore_unused( item );
|
2019-06-25 23:39:58 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( count, 0 );
|
|
|
|
|
|
|
|
for( int type = 0; type <= MAX_STRUCT_TYPE_ID; type++ )
|
|
|
|
{
|
|
|
|
count = 0;
|
|
|
|
for( auto item : m_tree.OfType( KICAD_T( type ) ) )
|
|
|
|
{
|
2021-10-05 16:57:25 +00:00
|
|
|
ignore_unused( item );
|
2019-06-25 23:39:58 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( count, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
EDA_RECT bbox;
|
|
|
|
|
|
|
|
for( int type = 0; type <= MAX_STRUCT_TYPE_ID; type++ )
|
|
|
|
{
|
|
|
|
count = 0;
|
|
|
|
for( auto item : m_tree.Overlapping( SCH_JUNCTION_T, bbox ) )
|
|
|
|
{
|
2021-10-05 16:57:25 +00:00
|
|
|
ignore_unused( item );
|
2019-06-25 23:39:58 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( count, 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE( Junctions )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < 100; i++ )
|
|
|
|
{
|
|
|
|
SCH_JUNCTION* junction =
|
2022-01-01 18:08:03 +00:00
|
|
|
new SCH_JUNCTION( VECTOR2I( Mils2iu( 100 ) * i, Mils2iu( 100 ) * i ) );
|
2019-06-25 23:39:58 +00:00
|
|
|
m_tree.insert( junction );
|
|
|
|
}
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for( auto item : m_tree.OfType( SCH_JUNCTION_T ) )
|
|
|
|
{
|
2021-10-05 16:57:25 +00:00
|
|
|
ignore_unused( item );
|
2019-06-25 23:39:58 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( count, 100 );
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
for( auto item : m_tree.OfType( SCH_NO_CONNECT_T ) )
|
|
|
|
{
|
2021-10-05 16:57:25 +00:00
|
|
|
ignore_unused( item );
|
2019-06-25 23:39:58 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( count, 0 );
|
|
|
|
|
2022-01-01 18:08:03 +00:00
|
|
|
EDA_RECT small_bbox( VECTOR2I( -1, -1 ), VECTOR2I( Mils2iu( 2 ), Mils2iu( 2 ) ) );
|
|
|
|
EDA_RECT med_bbox( VECTOR2I( 0, 0 ), VECTOR2I( Mils2iu( 100 ), Mils2iu( 100 ) ) );
|
|
|
|
EDA_RECT big_bbox( VECTOR2I( 0, 0 ), VECTOR2I( Mils2iu( 5000 ), Mils2iu( 5000 ) ) );
|
2019-06-25 23:39:58 +00:00
|
|
|
|
|
|
|
count = 0;
|
|
|
|
for( auto item : m_tree.Overlapping( small_bbox ) )
|
|
|
|
{
|
|
|
|
BOOST_CHECK( small_bbox.Intersects( item->GetBoundingBox() ) );
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( count, 1 );
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
for( auto item : m_tree.Overlapping( SCH_JUNCTION_T, small_bbox ) )
|
|
|
|
{
|
|
|
|
BOOST_CHECK( small_bbox.Intersects( item->GetBoundingBox() ) );
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( count, 1 );
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
for( auto item : m_tree.Overlapping( SCH_NO_CONNECT_T, small_bbox ) )
|
|
|
|
{
|
|
|
|
BOOST_CHECK( small_bbox.Intersects( item->GetBoundingBox() ) );
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( count, 0 );
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
for( auto item : m_tree.Overlapping( med_bbox ) )
|
|
|
|
{
|
|
|
|
BOOST_CHECK( med_bbox.Intersects( item->GetBoundingBox() ) );
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( count, 2 );
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
for( auto item : m_tree.Overlapping( big_bbox ) )
|
|
|
|
{
|
|
|
|
BOOST_CHECK( big_bbox.Intersects( item->GetBoundingBox() ) );
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( count, 51 );
|
2021-01-19 03:40:58 +00:00
|
|
|
|
|
|
|
for( SCH_ITEM* item : m_tree )
|
|
|
|
delete item;
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE( MixedElements )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < 100; i++ )
|
|
|
|
{
|
|
|
|
int x_sign = ( i % 2 == 0 ) ? -1 : 1;
|
|
|
|
int y_sign = ( i % 3 == 0 ) ? -1 : 1;
|
|
|
|
|
|
|
|
SCH_JUNCTION* junction = new SCH_JUNCTION(
|
2022-01-01 18:08:03 +00:00
|
|
|
VECTOR2I( Mils2iu( 100 ) * i * x_sign, Mils2iu( 100 ) * i * y_sign ) );
|
2019-06-25 23:39:58 +00:00
|
|
|
m_tree.insert( junction );
|
|
|
|
|
|
|
|
SCH_NO_CONNECT* nc = new SCH_NO_CONNECT(
|
2022-01-01 18:08:03 +00:00
|
|
|
VECTOR2I( Mils2iu( 150 ) * i * y_sign, Mils2iu( 150 ) * i * x_sign ) );
|
2019-06-25 23:39:58 +00:00
|
|
|
m_tree.insert( nc );
|
|
|
|
}
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for( auto item : m_tree.OfType( SCH_JUNCTION_T ) )
|
|
|
|
{
|
2021-10-05 16:57:25 +00:00
|
|
|
ignore_unused( item );
|
2019-06-25 23:39:58 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( count, 100 );
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
for( auto item : m_tree.OfType( SCH_NO_CONNECT_T ) )
|
|
|
|
{
|
2021-10-05 16:57:25 +00:00
|
|
|
ignore_unused( item );
|
2019-06-25 23:39:58 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( count, 100 );
|
|
|
|
|
2022-01-01 18:08:03 +00:00
|
|
|
EDA_RECT small_bbox( VECTOR2I( -1, -1 ), VECTOR2I( Mils2iu( 2 ), Mils2iu( 2 ) ) );
|
2019-06-25 23:39:58 +00:00
|
|
|
|
|
|
|
count = 0;
|
|
|
|
for( auto item : m_tree.Overlapping( small_bbox ) )
|
|
|
|
{
|
|
|
|
BOOST_CHECK( small_bbox.Intersects( item->GetBoundingBox() ) );
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( count, 2 );
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
for( auto item : m_tree.Overlapping( SCH_JUNCTION_T, small_bbox ) )
|
|
|
|
{
|
|
|
|
BOOST_CHECK( small_bbox.Intersects( item->GetBoundingBox() ) );
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( count, 1 );
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
for( auto item : m_tree.Overlapping( SCH_NO_CONNECT_T, small_bbox ) )
|
|
|
|
{
|
|
|
|
BOOST_CHECK( small_bbox.Intersects( item->GetBoundingBox() ) );
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( count, 1 );
|
2021-01-19 03:40:58 +00:00
|
|
|
|
|
|
|
for( SCH_ITEM* item : m_tree )
|
|
|
|
delete item;
|
2019-06-25 23:39:58 +00:00
|
|
|
}
|
|
|
|
|
2020-01-14 08:30:15 +00:00
|
|
|
// This tests the case where the tree has no branches but we want to iterator over a subset
|
|
|
|
// where the first case may or may not match
|
|
|
|
BOOST_AUTO_TEST_CASE( SingleElementTree )
|
|
|
|
{
|
2022-01-01 18:08:03 +00:00
|
|
|
SCH_JUNCTION* junction = new SCH_JUNCTION( VECTOR2I( Mils2iu( 100 ), Mils2iu( 100 ) ) );
|
2020-01-14 08:30:15 +00:00
|
|
|
m_tree.insert( junction );
|
|
|
|
|
2022-01-01 18:08:03 +00:00
|
|
|
SCH_NO_CONNECT* nc = new SCH_NO_CONNECT( VECTOR2I( Mils2iu( 150 ), Mils2iu( 150 ) ) );
|
2020-01-14 08:30:15 +00:00
|
|
|
m_tree.insert( nc );
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for( auto item : m_tree.OfType( SCH_JUNCTION_T ) )
|
|
|
|
{
|
2021-10-05 16:57:25 +00:00
|
|
|
ignore_unused( item );
|
2020-01-14 08:30:15 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( count, 1 );
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
for( auto item : m_tree.OfType( SCH_NO_CONNECT_T ) )
|
|
|
|
{
|
2021-10-05 16:57:25 +00:00
|
|
|
ignore_unused( item );
|
2020-01-14 08:30:15 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( count, 1 );
|
2021-01-19 03:40:58 +00:00
|
|
|
|
|
|
|
for( SCH_ITEM* item : m_tree )
|
|
|
|
delete item;
|
2020-01-14 08:30:15 +00:00
|
|
|
}
|
|
|
|
|
2019-06-25 23:39:58 +00:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|