KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_vector2.cpp
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) 2020 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
29
30// Code under test
31#include <math/vector2d.h>
32
36BOOST_AUTO_TEST_SUITE( VECTOR2TESTS )
37
38BOOST_AUTO_TEST_CASE( test_cross_product, *boost::unit_test::tolerance( 0.000001 ) )
39{
40 VECTOR2I v1(0, 1);
41 VECTOR2I v2(1, 0);
42
43 BOOST_CHECK( v2.Cross( v1 ) == 1 );
44}
45
46BOOST_AUTO_TEST_CASE( test_dot_product, *boost::unit_test::tolerance( 0.000001 ) )
47{
48 VECTOR2I v1( 0, 1 );
49 VECTOR2I v2( 1, 0 );
50
51 BOOST_CHECK( v2.Dot( v1 ) == 0 );
52}
53
54BOOST_AUTO_TEST_CASE( test_resize, *boost::unit_test::tolerance( 0.000001 ) )
55{
56 // just some arbitrary vectors
57 VECTOR2I v1( 4, 3 );
58 VECTOR2I v2( 5, -1 );
59 VECTOR2I v3( -2, 1 );
60 VECTOR2I v4( 1, 1 );
61 VECTOR2I v5( -70, -70 );
62
63 BOOST_CHECK( v1.Resize( 8 ) == VECTOR2I( 6, 5 ) );
64 BOOST_CHECK( v2.Resize( 10 ) == VECTOR2I( 10, -2 ) );
65 BOOST_CHECK( v3.Resize( 4 ) == VECTOR2I( -4, 2 ) );
66 BOOST_CHECK( v4.Resize( 1 ) == VECTOR2I( 1, 1 ) );
67 BOOST_CHECK( v5.Resize( 100 ) == VECTOR2I( -71, -71 ) );
68}
69
70BOOST_AUTO_TEST_SUITE_END()
extended_type Cross(const VECTOR2< T > &aVector) const
Compute cross product of self with aVector.
Definition: vector2d.h:457
extended_type Dot(const VECTOR2< T > &aVector) const
Compute dot product of self with aVector.
Definition: vector2d.h:465
VECTOR2< T > Resize(T aNewLength) const
Return a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:350
BOOST_AUTO_TEST_CASE(ConvertToKicadUnit)
Test conversation from Altium internal units into KiCad internal units.
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
VECTOR3I v1(5, 5, 5)
VECTOR2I v2(1, 0)
Test suite for KiCad math code.
VECTOR2I v4(1, 1)
VECTOR2I v5(-70, -70)
BOOST_CHECK(v2.Cross(v1)==1)
VECTOR2I v3(-2, 1)