Skip to content

Commit 9f63d3c

Browse files
committed
More tests
1 parent 0004068 commit 9f63d3c

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

modules/yup_graphics/primitives/yup_Size.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ class YUP_API Size
480480
481481
@return A new Point object with the converted dimensions.
482482
*/
483-
template <class T>
483+
template <class T = ValueType>
484484
[[nodiscard]] constexpr Point<T> toPoint() const noexcept
485485
{
486486
return { static_cast<T> (width), static_cast<T> (height) };
@@ -494,7 +494,7 @@ class YUP_API Size
494494
495495
@return A new Rectangle object with the converted dimensions.
496496
*/
497-
template <class T>
497+
template <class T = ValueType>
498498
[[nodiscard]] constexpr Rectangle<T> toRectangle() const noexcept;
499499

500500
/** Convert Size to Rectangle with specified coordinates
@@ -508,7 +508,7 @@ class YUP_API Size
508508
509509
@return A new Rectangle object with the converted dimensions.
510510
*/
511-
template <class T>
511+
template <class T = ValueType>
512512
[[nodiscard]] constexpr Rectangle<T> toRectangle (T x, T y) const noexcept;
513513

514514
/** Convert Size to Rectangle with specified coordinates
@@ -521,7 +521,7 @@ class YUP_API Size
521521
522522
@return A new Rectangle object with the converted dimensions.
523523
*/
524-
template <class T>
524+
template <class T = ValueType>
525525
[[nodiscard]] constexpr Rectangle<T> toRectangle (Point<T> xy) const noexcept;
526526

527527
//==============================================================================

tests/yup_graphics/yup_Size.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,33 @@ TEST (SizeTests, ConvertAndRound)
143143
EXPECT_EQ (rounded.getHeight(), 4);
144144
}
145145

146+
TEST (SizeTests, PrimitiveConversions)
147+
{
148+
Size<float> s (3.7f, 4.2f);
149+
150+
auto toPoint = s.toPoint();
151+
EXPECT_FLOAT_EQ (toPoint.getX(), 3.7f);
152+
EXPECT_FLOAT_EQ (toPoint.getY(), 4.2f);
153+
154+
auto toRectangle1 = s.toRectangle();
155+
EXPECT_FLOAT_EQ (toRectangle1.getX(), 0.0f);
156+
EXPECT_FLOAT_EQ (toRectangle1.getY(), 0.0f);
157+
EXPECT_FLOAT_EQ (toRectangle1.getWidth(), 3.7f);
158+
EXPECT_FLOAT_EQ (toRectangle1.getHeight(), 4.2f);
159+
160+
auto toRectangle2 = s.toRectangle (1.2f, 2.9f);
161+
EXPECT_FLOAT_EQ (toRectangle2.getX(), 1.2f);
162+
EXPECT_FLOAT_EQ (toRectangle2.getY(), 2.9f);
163+
EXPECT_FLOAT_EQ (toRectangle2.getWidth(), 3.7f);
164+
EXPECT_FLOAT_EQ (toRectangle2.getHeight(), 4.2f);
165+
166+
auto toRectangle3 = s.toRectangle (Point<float> { 1.2f, 2.9f });
167+
EXPECT_FLOAT_EQ (toRectangle3.getX(), 1.2f);
168+
EXPECT_FLOAT_EQ (toRectangle3.getY(), 2.9f);
169+
EXPECT_FLOAT_EQ (toRectangle3.getWidth(), 3.7f);
170+
EXPECT_FLOAT_EQ (toRectangle3.getHeight(), 4.2f);
171+
}
172+
146173
TEST (SizeTests, ArithmeticOperators)
147174
{
148175
Size<float> s (2.0f, 3.0f);
@@ -175,4 +202,4 @@ TEST (SizeTests, StructuredBinding)
175202
auto [w, h] = s;
176203
EXPECT_EQ (w, 1);
177204
EXPECT_EQ (h, 2);
178-
}
205+
}

0 commit comments

Comments
 (0)