LibGfx: Prevent calling to_type<T>()
on Line/Point/Rect/Size<T>
Also, add `Line::to_type<T>()` since that was missing. Calling to_type() with the same type as the existing object accomplishes nothing except wasting some cycles and making the code more verbose, and it is hard to spot. Nobody does this in the code currently (yay!) but I made this mistake repeatedly when doing my step-by-step CSS Pixels conversion, so let's make it easier to catch them.
This commit is contained in:
parent
34fd5cb206
commit
234bc0c237
Notes:
sideshowbarker
2024-07-17 17:49:11 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/234bc0c237 Pull-request: https://github.com/SerenityOS/serenity/pull/16171 Reviewed-by: https://github.com/linusg
4 changed files with 13 additions and 3 deletions
|
@ -134,6 +134,13 @@ public:
|
|||
void set_a(Point<T> const& a) { m_a = a; }
|
||||
void set_b(Point<T> const& b) { m_b = b; }
|
||||
|
||||
template<typename U>
|
||||
requires(!IsSame<T, U>)
|
||||
[[nodiscard]] ALWAYS_INLINE constexpr Line<U> to_type() const
|
||||
{
|
||||
return Line<U>(*this);
|
||||
}
|
||||
|
||||
String to_string() const;
|
||||
|
||||
private:
|
||||
|
|
|
@ -229,7 +229,8 @@ public:
|
|||
[[nodiscard]] Point end_point_for_aspect_ratio(Point const& previous_end_point, float aspect_ratio) const;
|
||||
|
||||
template<typename U>
|
||||
[[nodiscard]] Point<U> to_type() const
|
||||
requires(!IsSame<T, U>)
|
||||
[[nodiscard]] Point<U> to_type() const
|
||||
{
|
||||
return Point<U>(*this);
|
||||
}
|
||||
|
|
|
@ -949,7 +949,8 @@ public:
|
|||
}
|
||||
|
||||
template<typename U>
|
||||
[[nodiscard]] ALWAYS_INLINE Rect<U> to_type() const
|
||||
requires(!IsSame<T, U>)
|
||||
[[nodiscard]] ALWAYS_INLINE Rect<U> to_type() const
|
||||
{
|
||||
return Rect<U>(*this);
|
||||
}
|
||||
|
|
|
@ -176,7 +176,8 @@ public:
|
|||
}
|
||||
|
||||
template<typename U>
|
||||
[[nodiscard]] ALWAYS_INLINE constexpr Size<U> to_type() const
|
||||
requires(!IsSame<T, U>)
|
||||
[[nodiscard]] ALWAYS_INLINE constexpr Size<U> to_type() const
|
||||
{
|
||||
return Size<U>(*this);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue