KiCad PCB EDA Suite
Loading...
Searching...
No Matches
eda_item_test_utils.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#ifndef EDA_ITEM_TEST_UTILS_H
25#define EDA_ITEM_TEST_UTILS_H
26
28#include <base_units.h>
29#include <eda_item.h>
30
31
32template <typename T>
33static void IterateOverPositionsAndReferences( T* aItem, void ( *aCallback )( T*, VECTOR2I ) )
34{
35 constexpr int XSTEP = static_cast<int>( schIUScale.mmToIU( 100 ) );
36 constexpr int YSTEP = static_cast<int>( schIUScale.mmToIU( 50 ) );
37 constexpr int XMIN = -1 * XSTEP;
38 constexpr int XMAX = 1 * XSTEP;
39 constexpr int YMIN = -1 * YSTEP;
40 constexpr int YMAX = 1 * YSTEP;
41
42 for( int posX = XMIN; posX <= XMAX; posX += XSTEP )
43 {
44 for( int posY = YMIN; posY <= YMAX; posY += YSTEP )
45 {
46 for( int refX = XMIN; refX <= XMAX; refX += XSTEP )
47 {
48 for( int refY = YMIN; refY <= YMAX; refY += YSTEP )
49 {
50 BOOST_TEST_CONTEXT( wxString::Format( "Position: %d %d, Reference: %d %d",
51 posX, posY, refX, refY ) )
52 {
53 aItem->SetPosition( VECTOR2I( posX, posY ) );
54 aCallback( aItem, VECTOR2I( refX, refY ) );
55 }
56 }
57 }
58 }
59 }
60}
61
62#endif // EDA_ITEM_TEST_UTILS_H
constexpr EDA_IU_SCALE schIUScale
Definition: base_units.h:110
static void IterateOverPositionsAndReferences(T *aItem, void(*aCallback)(T *, VECTOR2I))
constexpr int mmToIU(double mm) const
Definition: base_units.h:88
#define BOOST_TEST_CONTEXT(A)
VECTOR2< int > VECTOR2I
Definition: vector2d.h:588