1/** \file
2 * \brief Tests for geometry.h
3 *
4 * \author Max Ilsen
5 *
6 * \par License:
7 * This file is part of the Open Graph Drawing Framework (OGDF).
8 *
9 * \par
10 * Copyright (C)<br>
11 * See README.md in the OGDF root directory for details.
12 *
13 * \par
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * Version 2 or 3 as published by the Free Software Foundation;
17 * see the file LICENSE.txt included in the packaging of this file
18 * for details.
19 *
20 * \par
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * \par
27 * You should have received a copy of the GNU General Public
28 * License along with this program; if not, see
29 * http://www.gnu.org/copyleft/gpl.html
30 */
31
32#include <ogdf/basic/geometry.h>
33#include <testing.h>
34
35go_bandit([]() {
36 describe("DPolyline", [](){
37 describe("normalize, trivial cases", [](){
38 it("works on an empty polyline", [](){
39 DPolyline dpline;
40 dpline.normalize();
41 AssertThat(dpline, Equals(dpline));
42 });
43
44 it("works on a polyline with one point", [](){
45 DPolyline dpline({DPoint(1,1)});
46 dpline.normalize();
47 AssertThat(dpline, Equals(dpline));
48 });
49
50 it("works on a polyline with two points", [](){
51 DPolyline dpline({DPoint(1,1), DPoint(2,2)});
52 dpline.normalize();
53 AssertThat(dpline, Equals(dpline));
54 });
55
56 it("works on a polyline with three points", [](){
57 DPolyline dpline({DPoint(1,1), DPoint(2,2), DPoint(3,3)});
58 DPolyline result({DPoint(1,1), DPoint(3,3)});
59 dpline.normalize();
60 AssertThat(dpline, Equals(result));
61 });
62 });
63
64 describe("normalize, non-trivial cases", [](){
65 DPoint p0(0,0);
66 DPoint p1(1,1); // 180 degree
67 DPoint p2(2,2); // 180 degree
68 DPoint p3(3,3); // 135 degree
69 DPoint p4(3,4); // 90 degree
70 DPoint p5(4,4); // 90 degree
71 DPoint p6(4,6); // 45 degree
72 DPoint p7(5,5); // 45 degree
73 DPoint p8(5,6); // 135 degree
74 DPoint p9(6,7); // 135 degree
75 DPoint p10(7,7); // 180 degree
76 DPoint p11(8,7); // 180 degree
77 DPoint p12(9,7); // 90 degree
78 DPoint p13(9,8);
79 DPolyline dpline;
80
81 before_each([&](){
82 dpline = DPolyline({p1, p2, p3, p4, p5, p6,
83 p7, p8, p9, p10, p11, p12});
84 });
85
86 it("works without parameters", [&](){
87 DPolyline result({p1, p3, p4, p5, p6, p7, p8, p9, p12});
88 dpline.normalize();
89 AssertThat(dpline, Equals(result));
90 });
91
92 it("works with a minimum angle of 3/4 Pi", [&](){
93 DPolyline result({p1, p4, p5, p6, p7, p9, p12});
94 dpline.normalize(0.75*Math::pi);
95 AssertThat(dpline, Equals(result));
96 });
97
98 it("works with a minimum angle of 1/2 Pi", [&](){
99 DPolyline result({p1, p12});
100 dpline.normalize(Math::pi_2);
101 AssertThat(dpline, Equals(result));
102 });
103
104 it("works with source/target points", [&](){
105 DPolyline result({p3, p4, p5, p6, p7, p8, p9, p12});
106 dpline.normalize(p0, p13);
107 AssertThat(dpline, Equals(result));
108 });
109
110 it("works with source/target points and a minimum angle of 3/4 Pi", [&](){
111 DPolyline result({p4, p5, p6, p7, p9, p12});
112 dpline.normalize(p0, p13, 0.75*Math::pi);
113 AssertThat(dpline, Equals(result));
114 });
115
116 it("works with source/target points and a minimum angle of 1/2 Pi", [&](){
117 dpline.normalize(p0, p13, Math::pi_2);
118 AssertThat(dpline.empty(), IsTrue());
119 });
120
121 it("works with source/target points equaling the polyline's first/last point", [&](){
122 DPolyline result({p3, p4, p5, p6, p7, p8, p9});
123 dpline.normalize(DPoint(p1), DPoint(p12));
124 AssertThat(dpline, Equals(result));
125 });
126 });
127 });
128});
129