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
39inline std::ostream& operator<<( std::ostream& os, const BOX2I& aBox )
40{
41 os << "BOX[ " << aBox.GetOrigin() << " + " << aBox.GetSize() << " ]";
42 return os;
43}
44
45namespace KI_TEST
46{
47
51template <typename VEC>
52bool IsVecWithinTol( const VEC& aVec, const VEC& aExp, typename VEC::coord_type aTol )
53{
54 return IsWithin<typename VEC::coord_type>( aVec.x, aExp.x, aTol )
55 && IsWithin<typename VEC::coord_type>( aVec.y, aExp.y, aTol );
56}
57
61template <typename BOX>
62bool IsBoxWithinTol( const BOX& aBox, const BOX& aExp, typename BOX::coord_type aTol )
63{
65 return IsVecWithinTol<VEC>( aBox.GetPosition(), aExp.GetPosition(), aTol )
66 && IsVecWithinTol<VEC>( aBox.GetSize(), aExp.GetSize(), aTol * 2 );
67}
68
69} // namespace KI_TEST
70
71#endif // QA_UNIT_TEST_UTILS_GEOM__H
const Vec & GetOrigin() const
Definition: box2.h:200
const SizeVec & GetSize() const
Definition: box2.h:196
Define a general 2D-vector/point.
Definition: vector2d.h:70
std::ostream & operator<<(std::ostream &os, const BOX2I &aBox)
Define a stream function for logging this type.
Definition: geometry.h:39
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:62
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:52
Numerical test predicates.