KiCad PCB EDA Suite
Loading...
Searching...
No Matches
color4d_test_utils.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
24
25#ifndef QA_COMMON_COLOR4D_TEST_UTILS__H
26#define QA_COMMON_COLOR4D_TEST_UTILS__H
27
28#include <gal/color4d.h>
29
30#include <qa_utils/numeric.h>
31
32namespace KI_TEST
33{
37inline bool IsColorNear( const KIGFX::COLOR4D& aCol, const KIGFX::COLOR4D aOther, double aTol )
38{
39 return KI_TEST::IsWithin<double>( aCol.r, aOther.r, aTol )
40 && KI_TEST::IsWithin<double>( aCol.g, aOther.g, aTol )
41 && KI_TEST::IsWithin<double>( aCol.b, aOther.b, aTol )
42 && KI_TEST::IsWithin<double>( aCol.a, aOther.a, aTol );
43}
44
48inline bool IsColorNearHex( const KIGFX::COLOR4D& aCol, unsigned char r, unsigned char g,
49 unsigned char b, unsigned char a )
50{
51 const double tol = 0.5 / 255.0; // One bit of quantised error
52
53 return KI_TEST::IsWithin<double>( aCol.r, r / 255.0, tol )
54 && KI_TEST::IsWithin<double>( aCol.g, g / 255.0, tol )
55 && KI_TEST::IsWithin<double>( aCol.b, b / 255.0, tol )
56 && KI_TEST::IsWithin<double>( aCol.a, a / 255.0, tol );
57}
58} // namespace KI_TEST
59
60#endif // QA_COMMON_COLOR4D_TEST_UTILS__H
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
double r
Red component.
Definition color4d.h:389
double g
Green component.
Definition color4d.h:390
double a
Alpha component.
Definition color4d.h:392
double b
Blue component.
Definition color4d.h:391
bool IsColorNearHex(const KIGFX::COLOR4D &aCol, unsigned char r, unsigned char g, unsigned char b, unsigned char a)
Checks if a COLOR4D is close enough to a given RGB char value.
bool IsColorNear(const KIGFX::COLOR4D &aCol, const KIGFX::COLOR4D aOther, double aTol)
Checks if a COLOR4D is close enough to another.
bool IsWithin(T aValue, T aNominal, T aError)
Check if a value is within a tolerance of a nominal value.
Definition numeric.h:57
Numerical test predicates.