KiCad PCB EDA Suite
Loading...
Searching...
No Matches
geometry.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) 2018 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 QA_UNIT_TEST_UTILS_GEOM__H
25#define QA_UNIT_TEST_UTILS_GEOM__H
26
27#include <qa_utils/numeric.h>
29
30#include <math/box2.h>
31#include <math/vector2d.h>
32
33
37template <typename T>
38std::ostream& boost_test_print_type( std::ostream& os, const BOX2<T>& aBox )
39{
40 os << "BOX[ " << aBox.GetOrigin() << " + " << aBox.GetSize() << " ]";
41 return os;
42}
43
44namespace KI_TEST
45{
46
50template <typename VEC>
51bool IsVecWithinTol( const VEC& aVec, const VEC& aExp, typename VEC::coord_type aTol )
52{
53 return IsWithin<typename VEC::coord_type>( aVec.x, aExp.x, aTol )
54 && IsWithin<typename VEC::coord_type>( aVec.y, aExp.y, aTol );
55}
56
60template <typename BOX>
61bool IsBoxWithinTol( const BOX& aBox, const BOX& aExp, typename BOX::coord_type aTol )
62{
64 return IsVecWithinTol<VEC>( aBox.GetPosition(), aExp.GetPosition(), aTol )
65 && IsVecWithinTol<VEC>( aBox.GetSize(), aExp.GetSize(), aTol * 2 );
66}
67
68} // namespace KI_TEST
69
70#endif // QA_UNIT_TEST_UTILS_GEOM__H
A 2D bounding box built on top of an origin point and size vector.
Definition: box2.h:44
constexpr const Vec & GetOrigin() const
Definition: box2.h:210
constexpr const SizeVec & GetSize() const
Definition: box2.h:206
Define a general 2D-vector/point.
Definition: vector2d.h:71
std::ostream & boost_test_print_type(std::ostream &os, const BOX2< T > &aBox)
Define a stream function for logging this type.
Definition: geometry.h:38
bool IsBoxWithinTol(const BOX &aBox, const BOX &aExp, typename BOX::coord_type aTol)
Check that a box is close enough to another box.
Definition: geometry.h:61
bool IsVecWithinTol(const VEC &aVec, const VEC &aExp, typename VEC::coord_type aTol)
Check that both x and y of a vector are within expected error.
Definition: geometry.h:51
Numerical test predicates.