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
|
|
|
|
*/
|
|
|
|
|
2022-09-17 01:07:36 +00:00
|
|
|
#include <base_units.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>
|
2023-04-03 13:42:10 +00:00
|
|
|
#include <qa_utils/uuid_test_utils.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>
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2022-08-31 16:17:14 +00:00
|
|
|
BOX2I bbox;
|
2019-06-25 23:39:58 +00:00
|
|
|
|
|
|
|
for( int type = 0; type <= MAX_STRUCT_TYPE_ID; type++ )
|
|
|
|
{
|
|
|
|
count = 0;
|
2022-08-31 16:17:14 +00:00
|
|
|
|
|
|
|
for( SCH_ITEM* item : m_tree.Overlapping( SCH_JUNCTION_T, bbox ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
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++ )
|
|
|
|
{
|
2022-09-16 23:42:20 +00:00
|
|
|
SCH_JUNCTION* junction = new SCH_JUNCTION(
|
|
|
|
VECTOR2I( schIUScale.MilsToIU( 100 ) * i, schIUScale.MilsToIU( 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-09-16 23:42:20 +00:00
|
|
|
BOX2I small_bbox( VECTOR2I( -1, -1 ),
|
|
|
|
VECTOR2I( schIUScale.MilsToIU( 2 ), schIUScale.MilsToIU( 2 ) ) );
|
|
|
|
BOX2I med_bbox( VECTOR2I( 0, 0 ),
|
|
|
|
VECTOR2I( schIUScale.MilsToIU( 100 ), schIUScale.MilsToIU( 100 ) ) );
|
|
|
|
BOX2I big_bbox( VECTOR2I( 0, 0 ),
|
|
|
|
VECTOR2I( schIUScale.MilsToIU( 5000 ), schIUScale.MilsToIU( 5000 ) ) );
|
2019-06-25 23:39:58 +00:00
|
|
|
|
|
|
|
count = 0;
|
2022-08-31 16:17:14 +00:00
|
|
|
|
|
|
|
for( SCH_ITEM* item : m_tree.Overlapping( small_bbox ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
|
|
|
BOOST_CHECK( small_bbox.Intersects( item->GetBoundingBox() ) );
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( count, 1 );
|
|
|
|
|
|
|
|
count = 0;
|
2022-08-31 16:17:14 +00:00
|
|
|
|
|
|
|
for( SCH_ITEM* item : m_tree.Overlapping( SCH_JUNCTION_T, small_bbox ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
|
|
|
BOOST_CHECK( small_bbox.Intersects( item->GetBoundingBox() ) );
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( count, 1 );
|
|
|
|
|
|
|
|
count = 0;
|
2022-08-31 16:17:14 +00:00
|
|
|
|
|
|
|
for( SCH_ITEM* item : m_tree.Overlapping( SCH_NO_CONNECT_T, small_bbox ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
|
|
|
BOOST_CHECK( small_bbox.Intersects( item->GetBoundingBox() ) );
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( count, 0 );
|
|
|
|
|
|
|
|
count = 0;
|
2022-08-31 16:17:14 +00:00
|
|
|
|
|
|
|
for( SCH_ITEM* item : m_tree.Overlapping( med_bbox ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
|
|
|
BOOST_CHECK( med_bbox.Intersects( item->GetBoundingBox() ) );
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( count, 2 );
|
|
|
|
|
|
|
|
count = 0;
|
2022-08-31 16:17:14 +00:00
|
|
|
|
|
|
|
for( SCH_ITEM* item : m_tree.Overlapping( big_bbox ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
SCH_JUNCTION* junction = new SCH_JUNCTION( VECTOR2I( schIUScale.MilsToIU( 100 ) * i * x_sign,
|
|
|
|
schIUScale.MilsToIU( 100 ) * i * y_sign ) );
|
2019-06-25 23:39:58 +00:00
|
|
|
m_tree.insert( junction );
|
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
SCH_NO_CONNECT* nc = new SCH_NO_CONNECT( VECTOR2I( schIUScale.MilsToIU( 150 ) * i * y_sign,
|
|
|
|
schIUScale.MilsToIU( 150 ) * i * x_sign ) );
|
2019-06-25 23:39:58 +00:00
|
|
|
m_tree.insert( nc );
|
|
|
|
}
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
2022-08-31 16:17:14 +00:00
|
|
|
for( SCH_ITEM* item : m_tree.OfType( SCH_JUNCTION_T ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
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;
|
2022-08-31 16:17:14 +00:00
|
|
|
|
|
|
|
for( SCH_ITEM* item : m_tree.OfType( SCH_NO_CONNECT_T ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
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-09-16 23:42:20 +00:00
|
|
|
BOX2I small_bbox( VECTOR2I( -1, -1 ), VECTOR2I( schIUScale.MilsToIU( 2 ), schIUScale.MilsToIU( 2 ) ) );
|
2019-06-25 23:39:58 +00:00
|
|
|
|
|
|
|
count = 0;
|
2022-08-31 16:17:14 +00:00
|
|
|
|
|
|
|
for( SCH_ITEM* item : m_tree.Overlapping( small_bbox ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
|
|
|
BOOST_CHECK( small_bbox.Intersects( item->GetBoundingBox() ) );
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( count, 2 );
|
|
|
|
|
|
|
|
count = 0;
|
2022-08-31 16:17:14 +00:00
|
|
|
|
|
|
|
for( SCH_ITEM* item : m_tree.Overlapping( SCH_JUNCTION_T, small_bbox ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
|
|
|
BOOST_CHECK( small_bbox.Intersects( item->GetBoundingBox() ) );
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( count, 1 );
|
|
|
|
|
|
|
|
count = 0;
|
2022-08-31 16:17:14 +00:00
|
|
|
|
|
|
|
for( SCH_ITEM* item : m_tree.Overlapping( SCH_NO_CONNECT_T, small_bbox ) )
|
2019-06-25 23:39:58 +00:00
|
|
|
{
|
|
|
|
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-09-16 23:42:20 +00:00
|
|
|
SCH_JUNCTION* junction = new SCH_JUNCTION( VECTOR2I( schIUScale.MilsToIU( 100 ), schIUScale.MilsToIU( 100 ) ) );
|
2020-01-14 08:30:15 +00:00
|
|
|
m_tree.insert( junction );
|
|
|
|
|
2022-09-16 23:42:20 +00:00
|
|
|
SCH_NO_CONNECT* nc = new SCH_NO_CONNECT( VECTOR2I( schIUScale.MilsToIU( 150 ), schIUScale.MilsToIU( 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()
|