summaryrefslogtreecommitdiff
path: root/Build/source/texk/dvisvgm/dvisvgm-src/tests/ShadingPatchTest.cpp
blob: 17eefc287fac053668a21f912a5df6bcec5d3b6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*************************************************************************
** ShadingPatchTest.cpp                                                 **
**                                                                      **
** This file is part of dvisvgm -- a fast DVI to SVG converter          **
** Copyright (C) 2005-2019 Martin Gieseking <martin.gieseking@uos.de>   **
**                                                                      **
** This program is free software; you can redistribute it and/or        **
** modify it under the terms of the GNU General Public License as       **
** published by the Free Software Foundation; either version 3 of       **
** the License, or (at your option) any later version.                  **
**                                                                      **
** This program is distributed in the hope that it will be useful, but  **
** WITHOUT ANY WARRANTY; without even the implied warranty of           **
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the         **
** GNU General Public License for more details.                         **
**                                                                      **
** You should have received a copy of the GNU General Public License    **
** along with this program; if not, see <http://www.gnu.org/licenses/>. **
*************************************************************************/

#include <gtest/gtest.h>
#include "ShadingPatch.hpp"
#include "TensorProductPatch.hpp"
#include "TriangularPatch.hpp"

using namespace std;


TEST(ShadingPatchTest, create) {
	auto patch = ShadingPatch::create(4, Color::ColorSpace::RGB);
	EXPECT_TRUE(dynamic_cast<TriangularPatch*>(patch.get()));
	patch = ShadingPatch::create(5, Color::ColorSpace::RGB);
	EXPECT_TRUE(dynamic_cast<LatticeTriangularPatch*>(patch.get()));
	patch = ShadingPatch::create(6, Color::ColorSpace::RGB);
	EXPECT_TRUE(dynamic_cast<CoonsPatch*>(patch.get()));
	patch = ShadingPatch::create(7, Color::ColorSpace::RGB);
	EXPECT_TRUE(dynamic_cast<TensorProductPatch*>(patch.get()));
}


TEST(ShadingPatchTest, fail) {
	for (int i=0; i < 4; i++) {
		EXPECT_THROW(ShadingPatch::create(i, Color::ColorSpace::RGB), ShadingException);
	}
}


TEST(ShadingPatchTest, colorQueryFuncs) {
	vector<DPair> points(3);
	vector<Color> colors(3);
	colors[0].setRGB(1.0, 0.0, 0.0);
	colors[1].setRGB(0.0, 1.0, 0.0);
	colors[2].setRGB(0.0, 0.0, 1.0);
	TriangularPatch tp1(points, colors, Color::ColorSpace::RGB, 0, 0);
	EXPECT_EQ(tp1.colorAt(0, 0).rgbString(), "#f00");
	EXPECT_EQ(tp1.colorAt(1, 0).rgbString(), "#0f0");
	EXPECT_EQ(tp1.colorAt(0, 1).rgbString(), "#00f");

	colors[0].setGray(0.2);
	colors[1].setGray(0.4);
	colors[2].setGray(0.6);
	TriangularPatch tp2(points, colors, Color::ColorSpace::GRAY, 0, 0);
	EXPECT_EQ(tp2.colorAt(0, 0).rgbString(), "#333");
	EXPECT_EQ(tp2.colorAt(1, 0).rgbString(), "#666");
	EXPECT_EQ(tp2.colorAt(0, 1).rgbString(), "#999");

	colors[0].setCMYK(1.0, 0.0, 0.0, 0.2);
	colors[1].setCMYK(0.0, 1.0, 0.0, 0.4);
	colors[2].setCMYK(0.0, 0.0, 1.0, 0.6);
	TriangularPatch tp3(points, colors, Color::ColorSpace::CMYK, 0, 0);
	EXPECT_EQ(tp3.colorAt(0, 0).rgbString(), "#29cccc");
	EXPECT_EQ(tp3.colorAt(1, 0).rgbString(), "#993d99");
	EXPECT_EQ(tp3.colorAt(0, 1).rgbString(), "#66663d");

	colors[0].setLab(55, 80, 68);
	colors[1].setLab(30, 62, -108);
	colors[2].setLab(85, -72, 61);
	TriangularPatch tp4(points, colors, Color::ColorSpace::LAB, 0, 0);
	EXPECT_EQ(tp4.colorAt(0, 0).rgbString(), "#ff1402");
	EXPECT_EQ(tp4.colorAt(1, 0).rgbString(), "#002bf8");
	EXPECT_EQ(tp4.colorAt(0, 1).rgbString(), "#4af356");
}