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, 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#pragma once
25
26#include <qa_utils/numeric.h>
28
29#include <math/box2.h>
30#include <math/vector2d.h>
31
33
34
38template <typename T>
39std::ostream& boost_test_print_type( std::ostream& os, const BOX2<T>& aBox )
40{
41 os << "BOX[ " << aBox.GetOrigin() << " + " << aBox.GetSize() << " ]";
42 return os;
43}
44
45// Stream printing for geometry types
46std::ostream& boost_test_print_type( std::ostream& os, const SHAPE_LINE_CHAIN& c );
47
48namespace KI_TEST
49{
50
54template <typename VEC>
55bool IsVecWithinTol( const VEC& aVec, const VEC& aExp, typename VEC::coord_type aTol )
56{
57 return IsWithin<typename VEC::coord_type>( aVec.x, aExp.x, aTol )
58 && IsWithin<typename VEC::coord_type>( aVec.y, aExp.y, aTol );
59}
60
64template <typename BOX>
65bool IsBoxWithinTol( const BOX& aBox, const BOX& aExp, typename BOX::coord_type aTol )
66{
68 return IsVecWithinTol<VEC>( aBox.GetPosition(), aExp.GetPosition(), aTol )
69 && IsVecWithinTol<VEC>( aBox.GetSize(), aExp.GetSize(), aTol * 2 );
70}
71
77bool ChainsAreCyclicallyEqual( const SHAPE_LINE_CHAIN& aChainA, const SHAPE_LINE_CHAIN& aChainB, int aTol );
78
79} // namespace KI_TEST
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
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: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: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:65
bool IsWithin(T aValue, T aNominal, T aError)
Check if a value is within a tolerance of a nominal value.
Definition numeric.h:61
bool ChainsAreCyclicallyEqual(const SHAPE_LINE_CHAIN &aChainA, const SHAPE_LINE_CHAIN &aChainB, int aTol)
Check that two chains are cyclically equal.
Definition geometry.cpp:44
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:55
Numerical test predicates.