Skip to content

Commit af42397

Browse files
committed
More tweaks
1 parent 86950d2 commit af42397

File tree

4 files changed

+378
-1
lines changed

4 files changed

+378
-1
lines changed

cmake/yup_modules.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ endfunction()
162162
#==============================================================================
163163

164164
function (_yup_module_setup_target module_name
165+
module_path
165166
module_cpp_standard
166167
module_include_paths
167168
module_options
@@ -289,6 +290,7 @@ function (_yup_module_setup_plugin_client target_name plugin_client_target folde
289290
endif()
290291

291292
_yup_module_setup_target ("${custom_target_name}"
293+
"${module_path}"
292294
"${module_cpp_standard}"
293295
"${module_include_paths}"
294296
"${module_options}"
@@ -524,6 +526,7 @@ function (yup_add_module module_path module_group)
524526

525527
# ==== Setup module sources and properties
526528
_yup_module_setup_target ("${module_name}"
529+
"${module_path}"
527530
"${module_cpp_standard}"
528531
"${module_include_paths}"
529532
"${module_options}"

justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ build CONFIG="Debug":
1717
test CONFIG="Debug":
1818
cmake -G Xcode -B build
1919
cmake --build build --target yup_tests --config {{CONFIG}}
20-
build/tests/{{CONFIG}}/yup_tests --gtest_filter=PathTests.*
20+
build/tests/{{CONFIG}}/yup_tests --gtest_filter=*
2121

2222
[doc("generate and open project in macOS using Xcode")]
2323
osx PROFILING="OFF":

tests/yup_graphics/yup_Line.cpp

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
/*
2+
==============================================================================
3+
4+
This file is part of the YUP library.
5+
Copyright (c) 2025 - [email protected]
6+
7+
YUP is an open source library subject to open-source licensing.
8+
9+
The code included in this file is provided under the terms of the ISC license
10+
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
11+
to use, copy, modify, and/or distribute this software for any purpose with or
12+
without fee is hereby granted provided that the above copyright notice and
13+
this permission notice appear in all copies.
14+
15+
YUP IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
16+
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
17+
DISCLAIMED.
18+
19+
==============================================================================
20+
*/
21+
22+
#include <gtest/gtest.h>
23+
#include <yup_graphics/yup_graphics.h>
24+
#include <tuple>
25+
26+
using namespace yup;
27+
28+
namespace
29+
{
30+
static constexpr float tol = 1e-5f;
31+
} // namespace
32+
33+
TEST (LineTests, DefaultConstructor)
34+
{
35+
Line<float> l;
36+
EXPECT_EQ (l.getStart(), Point<float> (0, 0));
37+
EXPECT_EQ (l.getEnd(), Point<float> (0, 0));
38+
EXPECT_FLOAT_EQ (l.length(), 0.0f);
39+
EXPECT_FLOAT_EQ (l.slope(), 0.0f);
40+
EXPECT_TRUE (l.contains (Point<float> (0, 0)));
41+
}
42+
43+
TEST (LineTests, ParameterizedConstructor)
44+
{
45+
Line<float> l (1.0f, 2.0f, 3.0f, 4.0f);
46+
EXPECT_EQ (l.getStart(), Point<float> (1.0f, 2.0f));
47+
EXPECT_EQ (l.getEnd(), Point<float> (3.0f, 4.0f));
48+
EXPECT_FLOAT_EQ (l.getStartX(), 1.0f);
49+
EXPECT_FLOAT_EQ (l.getStartY(), 2.0f);
50+
EXPECT_FLOAT_EQ (l.getEndX(), 3.0f);
51+
EXPECT_FLOAT_EQ (l.getEndY(), 4.0f);
52+
}
53+
54+
TEST (LineTests, SetAndWithStartEnd)
55+
{
56+
Line<float> l (1.0f, 2.0f, 3.0f, 4.0f);
57+
l.setStart (Point<float> (5.0f, 6.0f));
58+
EXPECT_EQ (l.getStart(), Point<float> (5.0f, 6.0f));
59+
auto l2 = l.withStart (Point<float> (7.0f, 8.0f));
60+
EXPECT_EQ (l2.getStart(), Point<float> (7.0f, 8.0f));
61+
l.setEnd (Point<float> (9.0f, 10.0f));
62+
EXPECT_EQ (l.getEnd(), Point<float> (9.0f, 10.0f));
63+
auto l3 = l.withEnd (Point<float> (11.0f, 12.0f));
64+
EXPECT_EQ (l3.getEnd(), Point<float> (11.0f, 12.0f));
65+
}
66+
67+
TEST (LineTests, Reverse)
68+
{
69+
Line<float> l (1.0f, 2.0f, 3.0f, 4.0f);
70+
auto rev = l.reversed();
71+
EXPECT_EQ (rev.getStart(), Point<float> (3.0f, 4.0f));
72+
EXPECT_EQ (rev.getEnd(), Point<float> (1.0f, 2.0f));
73+
l.reverse();
74+
EXPECT_EQ (l.getStart(), Point<float> (3.0f, 4.0f));
75+
EXPECT_EQ (l.getEnd(), Point<float> (1.0f, 2.0f));
76+
}
77+
78+
TEST (LineTests, LengthAndSlope)
79+
{
80+
Line<float> l (0.0f, 0.0f, 3.0f, 4.0f);
81+
EXPECT_FLOAT_EQ (l.length(), 5.0f);
82+
EXPECT_FLOAT_EQ (l.slope(), 4.0f / 3.0f);
83+
Line<float> v (1.0f, 1.0f, 1.0f, 5.0f);
84+
EXPECT_FLOAT_EQ (v.slope(), 0.0f);
85+
}
86+
87+
TEST (LineTests, Contains)
88+
{
89+
Line<float> l (0.0f, 0.0f, 10.0f, 10.0f);
90+
EXPECT_TRUE (l.contains (Point<float> (5.0f, 5.0f)));
91+
EXPECT_FALSE (l.contains (Point<float> (5.0f, 6.0f)));
92+
EXPECT_TRUE (l.contains (Point<float> (5.001f, 5.001f), 0.01f));
93+
}
94+
95+
TEST (LineTests, PointAlong)
96+
{
97+
Line<float> l (0.0f, 0.0f, 10.0f, 0.0f);
98+
EXPECT_EQ (l.pointAlong (0.0f), Point<float> (0, 0));
99+
EXPECT_EQ (l.pointAlong (0.5f), Point<float> (5, 0));
100+
EXPECT_EQ (l.pointAlong (1.0f), Point<float> (10, 0));
101+
EXPECT_EQ (l.pointAlong (1.5f), Point<float> (15, 0));
102+
}
103+
104+
TEST (LineTests, Translate)
105+
{
106+
Line<float> l (0.0f, 0.0f, 1.0f, 1.0f);
107+
auto t = l.translated (2.0f, 3.0f);
108+
EXPECT_EQ (t.getStart(), Point<float> (2.0f, 3.0f));
109+
EXPECT_EQ (t.getEnd(), Point<float> (3.0f, 4.0f));
110+
l.translate (1.0f, 1.0f);
111+
EXPECT_EQ (l.getStart(), Point<float> (1.0f, 1.0f));
112+
EXPECT_EQ (l.getEnd(), Point<float> (2.0f, 2.0f));
113+
}
114+
115+
TEST (LineTests, ExtendBeforeAfter)
116+
{
117+
Line<float> l (0.0f, 0.0f, 10.0f, 0.0f);
118+
auto eb = l.extendedBefore (5.0f);
119+
EXPECT_EQ (eb.getStart(), Point<float> (-5.0f, 0.0f));
120+
auto ea = l.extendedAfter (5.0f);
121+
EXPECT_EQ (ea.getEnd(), Point<float> (15.0f, 0.0f));
122+
}
123+
124+
TEST (LineTests, KeepOnlyStartAndEnd)
125+
{
126+
Line<float> l (0.0f, 0.0f, 10.0f, 0.0f);
127+
auto ks = l.keepOnlyStart (0.5f);
128+
EXPECT_EQ (ks.getEnd(), Point<float> (5.0f, 0.0f));
129+
auto ke = l.keepOnlyEnd (0.5f);
130+
EXPECT_EQ (ke.getStart(), Point<float> (5.0f, 0.0f));
131+
}
132+
133+
TEST (LineTests, RotateAtPoint)
134+
{
135+
Line<float> l (2.0f, 0.0f, 4.0f, 0.0f);
136+
auto rl = l.rotateAtPoint (Point<float> (2.0f, 0.0f), MathConstants<float>::halfPi);
137+
EXPECT_NEAR (rl.getStartX(), 2.0f, tol);
138+
EXPECT_NEAR (rl.getStartY(), 0.0f, tol);
139+
EXPECT_NEAR (rl.getEndX(), 2.0f, tol);
140+
EXPECT_NEAR (rl.getEndY(), 2.0f, tol);
141+
}
142+
143+
TEST (LineTests, ToAndRoundToInt)
144+
{
145+
Line<float> lf (1.2f, 2.3f, 3.4f, 4.5f);
146+
auto lint = lf.roundToInt();
147+
EXPECT_EQ (lint.getStart(), Point<int> (1, 2));
148+
EXPECT_EQ (lint.getEnd(), Point<int> (3, 4));
149+
auto toInt = lf.to<int>();
150+
EXPECT_EQ (toInt.getStart(), Point<int> (1, 2));
151+
EXPECT_EQ (toInt.getEnd(), Point<int> (3, 4));
152+
}
153+
154+
TEST (LineTests, UnaryMinus)
155+
{
156+
Line<float> l (1.0f, 2.0f, 3.0f, 4.0f);
157+
auto neg = -l;
158+
EXPECT_EQ (neg.getStart(), Point<float> (-1.0f, -2.0f));
159+
EXPECT_EQ (neg.getEnd(), Point<float> (-3.0f, -4.0f));
160+
}
161+
162+
TEST (LineTests, Equality)
163+
{
164+
Line<float> l1 (0.0f, 0.0f, 1.0f, 1.0f);
165+
Line<float> l2 (0.0f, 0.0f, 1.0f, 1.0f);
166+
Line<float> l3 (1.0f, 1.0f, 2.0f, 2.0f);
167+
EXPECT_TRUE (l1 == l2);
168+
EXPECT_FALSE (l1 != l2);
169+
EXPECT_FALSE (l1 == l3);
170+
EXPECT_TRUE (l1 != l3);
171+
}
172+
173+
TEST (LineTests, StructuredBinding)
174+
{
175+
Line<float> l (1.0f, 2.0f, 3.0f, 4.0f);
176+
auto [x1, y1, x2, y2] = l;
177+
EXPECT_EQ (x1, 1.0f);
178+
EXPECT_EQ (y1, 2.0f);
179+
EXPECT_EQ (x2, 3.0f);
180+
EXPECT_EQ (y2, 4.0f);
181+
}
182+
183+
TEST (LineTests, Accessors)
184+
{
185+
Line<float> l (1.0f, 2.0f, 3.0f, 4.0f);
186+
EXPECT_EQ (l.getStart(), Point<float> (1.0f, 2.0f));
187+
EXPECT_EQ (l.getEnd(), Point<float> (3.0f, 4.0f));
188+
}
189+
190+
TEST (LineTests, StreamOutput)
191+
{
192+
Line<float> l (1.0f, 2.0f, 3.0f, 4.0f);
193+
String str;
194+
str << l;
195+
EXPECT_EQ (str, "1, 2, 3, 4");
196+
}

0 commit comments

Comments
 (0)