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 The 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, see <https://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <qa_utils/numeric.h>
24
25#include <math/box2.h>
26#include <math/vector2d.h>
27
29
30
34template <typename T>
35std::ostream& boost_test_print_type( std::ostream& os, const BOX2<T>& aBox )
36{
37 os << "BOX[ " << aBox.GetOrigin() << " + " << aBox.GetSize() << " ]";
38 return os;
39}
40
41// Stream printing for geometry types
42std::ostream& boost_test_print_type( std::ostream& os, const SHAPE_LINE_CHAIN& c );
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
73bool ChainsAreCyclicallyEqual( const SHAPE_LINE_CHAIN& aChainA, const SHAPE_LINE_CHAIN& aChainB, int aTol );
74
75} // namespace KI_TEST
A 2D bounding box built on top of an origin point and size vector.
Definition box2.h:40
constexpr const Vec & GetOrigin() const
Definition box2.h:206
constexpr const SizeVec & GetSize() const
Definition box2.h:202
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Define a general 2D-vector/point.
Definition vector2d.h:67
std::ostream & boost_test_print_type(std::ostream &os, const BOX2< T > &aBox)
Define a stream function for logging this type.
Definition geometry.h:35
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 IsWithin(T aValue, T aNominal, T aError)
Check if a value is within a tolerance of a nominal value.
Definition numeric.h:57
bool ChainsAreCyclicallyEqual(const SHAPE_LINE_CHAIN &aChainA, const SHAPE_LINE_CHAIN &aChainB, int aTol)
Check that two chains are cyclically equal.
Definition geometry.cpp:40
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.