KiCad PCB EDA Suite
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 (C) 2019 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
29#ifndef QA_COMMON_COLOR4D_TEST_UTILS__H
30#define QA_COMMON_COLOR4D_TEST_UTILS__H
31
32#include <gal/color4d.h>
33
34#include <qa_utils/numeric.h>
35
36namespace KI_TEST
37{
41inline bool IsColorNear( const KIGFX::COLOR4D& aCol, const KIGFX::COLOR4D aOther, double aTol )
42{
43 return KI_TEST::IsWithin<double>( aCol.r, aOther.r, aTol )
44 && KI_TEST::IsWithin<double>( aCol.g, aOther.g, aTol )
45 && KI_TEST::IsWithin<double>( aCol.b, aOther.b, aTol )
46 && KI_TEST::IsWithin<double>( aCol.a, aOther.a, aTol );
47}
48
52inline bool IsColorNearHex( const KIGFX::COLOR4D& aCol, unsigned char r, unsigned char g,
53 unsigned char b, unsigned char a )
54{
55 const double tol = 0.5 / 255.0; // One bit of quantised error
56
57 return KI_TEST::IsWithin<double>( aCol.r, r / 255.0, tol )
58 && KI_TEST::IsWithin<double>( aCol.g, g / 255.0, tol )
59 && KI_TEST::IsWithin<double>( aCol.b, b / 255.0, tol )
60 && KI_TEST::IsWithin<double>( aCol.a, a / 255.0, tol );
61}
62} // namespace KI_TEST
63
64#endif // QA_COMMON_COLOR4D_TEST_UTILS__H
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
double r
Red component.
Definition: color4d.h:384
double g
Green component.
Definition: color4d.h:385
double a
Alpha component.
Definition: color4d.h:387
double b
Blue component.
Definition: color4d.h:386
E_SERIE r
Definition: eserie.cpp:41
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.
Numerical test predicates.