Skip to content

Commit 41e3a4a

Browse files
committed
More APIs
1 parent 70997c9 commit 41e3a4a

File tree

5 files changed

+481
-293
lines changed

5 files changed

+481
-293
lines changed

modules/yup_graphics/graphics/yup_Color.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,10 +550,10 @@ class YUP_API Color
550550
}
551551

552552
return {
553+
static_cast<uint8> (a * 255),
553554
static_cast<uint8> (r * 255),
554555
static_cast<uint8> (g * 255),
555-
static_cast<uint8> (b * 255),
556-
static_cast<uint8> (a * 255)
556+
static_cast<uint8> (b * 255)
557557
};
558558
}
559559

@@ -653,10 +653,10 @@ class YUP_API Color
653653
}
654654

655655
return {
656+
static_cast<uint8> (a * 255),
656657
static_cast<uint8> (r * 255),
657658
static_cast<uint8> (g * 255),
658659
static_cast<uint8> (b * 255),
659-
static_cast<uint8> (a * 255)
660660
};
661661
}
662662

modules/yup_graphics/primitives/yup_Line.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -534,17 +534,17 @@ class YUP_API Line
534534
*/
535535
constexpr Line& transform (const AffineTransform& t) noexcept
536536
{
537-
auto x1 = static_cast<float> (p1.x);
538-
auto y1 = static_cast<float> (p1.y);
539-
auto x2 = static_cast<float> (p2.x);
540-
auto y2 = static_cast<float> (p2.y);
537+
auto x1 = static_cast<float> (p1.getX());
538+
auto y1 = static_cast<float> (p1.getY());
539+
auto x2 = static_cast<float> (p2.getX());
540+
auto y2 = static_cast<float> (p2.getY());
541541

542542
t.transformPoints (x1, y1, x2, y2);
543543

544-
p1.x = static_cast<ValueType> (x1);
545-
p1.y = static_cast<ValueType> (y1);
546-
p2.x = static_cast<ValueType> (x2);
547-
p2.y = static_cast<ValueType> (y2);
544+
p1.setX (static_cast<ValueType> (x1));
545+
p1.setY (static_cast<ValueType> (y1));
546+
p2.setX (static_cast<ValueType> (x2));
547+
p2.setY (static_cast<ValueType> (y2));
548548

549549
return *this;
550550
}

modules/yup_graphics/primitives/yup_Rectangle.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -757,9 +757,12 @@ class YUP_API Rectangle
757757
758758
@return A reference to this rectangle to allow method chaining.
759759
*/
760-
constexpr Rectangle& setSize (const Size<ValueType>& newSize) noexcept
760+
template <class T = ValueType>
761+
constexpr Rectangle& setSize (const Size<T>& newSize) noexcept
761762
{
762-
size = newSize;
763+
static_assert (std::numeric_limits<ValueType>::max() >= std::numeric_limits<T>::max(), "Invalid narrow cast");
764+
765+
size = newSize.template to<ValueType>();
763766

764767
return *this;
765768
}
@@ -770,7 +773,7 @@ class YUP_API Rectangle
770773
771774
@return A reference to this rectangle to allow method chaining.
772775
*/
773-
template <class T>
776+
template <class T = ValueType>
774777
constexpr Rectangle& setSize (T width, T height) noexcept
775778
{
776779
static_assert (std::numeric_limits<ValueType>::max() >= std::numeric_limits<T>::max(), "Invalid narrow cast");
@@ -790,7 +793,7 @@ class YUP_API Rectangle
790793
791794
@return A new rectangle with the updated size.
792795
*/
793-
template <class T>
796+
template <class T = ValueType>
794797
[[nodiscard]] constexpr Rectangle withSize (const Size<T>& newSize) const noexcept
795798
{
796799
static_assert (std::numeric_limits<ValueType>::max() >= std::numeric_limits<T>::max(), "Invalid narrow cast");
@@ -809,7 +812,7 @@ class YUP_API Rectangle
809812
810813
@return A new rectangle with the updated size.
811814
*/
812-
template <class T>
815+
template <class T = ValueType>
813816
[[nodiscard]] constexpr Rectangle withSize (T width, T height) const noexcept
814817
{
815818
static_assert (std::numeric_limits<ValueType>::max() >= std::numeric_limits<T>::max(), "Invalid narrow cast");
@@ -827,7 +830,7 @@ class YUP_API Rectangle
827830
828831
@return A new rectangle with the size scaled.
829832
*/
830-
template <class T>
833+
template <class T = ValueType>
831834
[[nodiscard]] constexpr auto withScaledSize (T scaleFactor) const noexcept
832835
-> std::enable_if_t<std::is_floating_point_v<T>, Rectangle>
833836
{

modules/yup_graphics/primitives/yup_RectangleList.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class YUP_API RectangleList
161161
*/
162162
[[nodiscard]] bool contains (ValueType x, ValueType y, ValueType width, ValueType height) const
163163
{
164-
return rectangles.contains (x, y, width, height);
164+
return contains (RectangleType{ x, y, width, height });
165165
}
166166

167167
[[nodiscard]] bool contains (const RectangleType& rect) const
@@ -177,21 +177,21 @@ class YUP_API RectangleList
177177
@return true if the point is contained within any rectangle in the list, false otherwise.
178178
*/
179179
[[nodiscard]] bool contains (ValueType x, ValueType y) const
180+
{
181+
return contains (Point<ValueType>{ x, y });
182+
}
183+
184+
[[nodiscard]] bool contains (const Point<ValueType>& point) const
180185
{
181186
for (const auto& rect : rectangles)
182187
{
183-
if (rect.contains (x, y))
188+
if (rect.contains (point))
184189
return true;
185190
}
186191

187192
return false;
188193
}
189194

190-
[[nodiscard]] bool contains (const Point<ValueType>& point) const
191-
{
192-
return contains (point.getX(), point.getY());
193-
}
194-
195195
//==============================================================================
196196
/** Checks if the list intersects a specified rectangle.
197197
@@ -200,21 +200,21 @@ class YUP_API RectangleList
200200
@return True if the rectangle intersects the list, otherwise false.
201201
*/
202202
[[nodiscard]] bool intersects (ValueType x, ValueType y, ValueType width, ValueType height) const
203+
{
204+
return intersects (RectangleType{ x, y, width, height });
205+
}
206+
207+
[[nodiscard]] bool intersects (const RectangleType& rect) const
203208
{
204209
for (const auto& rect : rectangles)
205210
{
206-
if (rect.intersects (x, y, width, height))
211+
if (rect.intersects (rect))
207212
return true;
208213
}
209214

210215
return false;
211216
}
212217

213-
[[nodiscard]] bool intersects (const RectangleType& rect) const
214-
{
215-
return intersects (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
216-
}
217-
218218
//==============================================================================
219219
/** Returns the number of rectangles in the list.
220220

0 commit comments

Comments
 (0)