diff --git a/Userland/Libraries/LibGfx/Rect.h b/Userland/Libraries/LibGfx/Rect.h index 77e58a827d..268b52e0d9 100644 --- a/Userland/Libraries/LibGfx/Rect.h +++ b/Userland/Libraries/LibGfx/Rect.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2018-2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -90,7 +90,7 @@ public: void transform_by(const AffineTransform& transform) { *this = transform.map(*this); } - Point center() const + [[nodiscard]] Point center() const { return { x() + width() / 2, y() + height() / 2 }; } @@ -145,63 +145,63 @@ public: set_height(height() - size.height()); } - Rect translated(T dx, T dy) const + [[nodiscard]] Rect translated(T dx, T dy) const { Rect rect = *this; rect.translate_by(dx, dy); return rect; } - Rect translated(const Point& delta) const + [[nodiscard]] Rect translated(Point const& delta) const { Rect rect = *this; rect.translate_by(delta); return rect; } - Rect scaled(T sx, T sy) const + [[nodiscard]] Rect scaled(T sx, T sy) const { Rect rect = *this; rect.scale_by(sx, sy); return rect; } - Rect scaled(const Point& s) const + [[nodiscard]] Rect scaled(Point const& s) const { Rect rect = *this; rect.scale_by(s); return rect; } - Rect transformed(const AffineTransform& transform) const + [[nodiscard]] Rect transformed(AffineTransform const& transform) const { Rect rect = *this; rect.transform_by(transform); return rect; } - Rect shrunken(T w, T h) const + [[nodiscard]] Rect shrunken(T w, T h) const { Rect rect = *this; rect.shrink(w, h); return rect; } - Rect shrunken(const Size& size) const + [[nodiscard]] Rect shrunken(Size const& size) const { Rect rect = *this; rect.shrink(size); return rect; } - Rect inflated(T w, T h) const + [[nodiscard]] Rect inflated(T w, T h) const { Rect rect = *this; rect.inflate(w, h); return rect; } - Rect inflated(const Size& size) const + [[nodiscard]] Rect inflated(Size const& size) const { Rect rect = *this; rect.inflate(size); @@ -252,27 +252,27 @@ public: return rect; } - bool contains_vertically(T y) const + [[nodiscard]] bool contains_vertically(T y) const { return y >= top() && y <= bottom(); } - bool contains_horizontally(T x) const + [[nodiscard]] bool contains_horizontally(T x) const { return x >= left() && x <= right(); } - bool contains(T x, T y) const + [[nodiscard]] bool contains(T x, T y) const { return x >= m_location.x() && x <= right() && y >= m_location.y() && y <= bottom(); } - ALWAYS_INLINE bool contains(const Point& point) const + [[nodiscard]] ALWAYS_INLINE bool contains(const Point& point) const { return contains(point.x(), point.y()); } - bool contains(const Rect& other) const + [[nodiscard]] bool contains(const Rect& other) const { return left() <= other.left() && right() >= other.right() @@ -281,7 +281,7 @@ public: } template - bool contains(const Container& others) const + [[nodiscard]] bool contains(const Container& others) const { bool have_any = false; for (const auto& other : others) { @@ -292,24 +292,24 @@ public: return have_any; } - ALWAYS_INLINE int primary_offset_for_orientation(Orientation orientation) const { return m_location.primary_offset_for_orientation(orientation); } + [[nodiscard]] ALWAYS_INLINE int primary_offset_for_orientation(Orientation orientation) const { return m_location.primary_offset_for_orientation(orientation); } ALWAYS_INLINE void set_primary_offset_for_orientation(Orientation orientation, int value) { m_location.set_primary_offset_for_orientation(orientation, value); } - ALWAYS_INLINE int secondary_offset_for_orientation(Orientation orientation) const { return m_location.secondary_offset_for_orientation(orientation); } + [[nodiscard]] ALWAYS_INLINE int secondary_offset_for_orientation(Orientation orientation) const { return m_location.secondary_offset_for_orientation(orientation); } ALWAYS_INLINE void set_secondary_offset_for_orientation(Orientation orientation, int value) { m_location.set_secondary_offset_for_orientation(orientation, value); } - ALWAYS_INLINE int primary_size_for_orientation(Orientation orientation) const { return m_size.primary_size_for_orientation(orientation); } - ALWAYS_INLINE int secondary_size_for_orientation(Orientation orientation) const { return m_size.secondary_size_for_orientation(orientation); } + [[nodiscard]] ALWAYS_INLINE int primary_size_for_orientation(Orientation orientation) const { return m_size.primary_size_for_orientation(orientation); } + [[nodiscard]] ALWAYS_INLINE int secondary_size_for_orientation(Orientation orientation) const { return m_size.secondary_size_for_orientation(orientation); } ALWAYS_INLINE void set_primary_size_for_orientation(Orientation orientation, int value) { m_size.set_primary_size_for_orientation(orientation, value); } ALWAYS_INLINE void set_secondary_size_for_orientation(Orientation orientation, int value) { m_size.set_secondary_size_for_orientation(orientation, value); } - T first_edge_for_orientation(Orientation orientation) const + [[nodiscard]] T first_edge_for_orientation(Orientation orientation) const { if (orientation == Orientation::Vertical) return top(); return left(); } - T last_edge_for_orientation(Orientation orientation) const + [[nodiscard]] T last_edge_for_orientation(Orientation orientation) const { if (orientation == Orientation::Vertical) return bottom(); @@ -353,17 +353,17 @@ public: translate_by(0, delta); } - bool intersects_vertically(const Rect& other) const + [[nodiscard]] bool intersects_vertically(Rect const& other) const { return top() <= other.bottom() && other.top() <= bottom(); } - bool intersects_horizontally(const Rect& other) const + [[nodiscard]] bool intersects_horizontally(Rect const& other) const { return left() <= other.right() && other.left() <= right(); } - bool intersects(const Rect& other) const + [[nodiscard]] bool intersects(Rect const& other) const { return left() <= other.right() && other.left() <= right() @@ -372,7 +372,7 @@ public: } template - bool intersects(const Container& others) const + [[nodiscard]] bool intersects(Container const& others) const { for (const auto& other : others) { if (intersects(other)) @@ -397,21 +397,21 @@ public: return IterationDecision::Continue; } - Vector, 4> shatter(const Rect& hammer) const; + [[nodiscard]] Vector, 4> shatter(Rect const& hammer) const; template - bool operator==(const Rect& other) const + [[nodiscard]] bool operator==(Rect const& other) const { return location() == other.location() && size() == other.size(); } template - bool operator!=(const Rect& other) const + [[nodiscard]] bool operator!=(const Rect& other) const { return !(*this == other); } - Rect operator*(T factor) const { return { m_location * factor, m_size * factor }; } + [[nodiscard]] Rect operator*(T factor) const { return { m_location * factor, m_size * factor }; } Rect& operator*=(T factor) { @@ -422,34 +422,34 @@ public: void intersect(const Rect&); - static Rect centered_on(const Point& center, const Size& size) + [[nodiscard]] static Rect centered_on(const Point& center, const Size& size) { return { { center.x() - size.width() / 2, center.y() - size.height() / 2 }, size }; } - static Rect from_two_points(const Point& a, const Point& b) + [[nodiscard]] static Rect from_two_points(const Point& a, const Point& b) { return { min(a.x(), b.x()), min(a.y(), b.y()), abst(a.x() - b.x()), abst(a.y() - b.y()) }; } - static Rect intersection(const Rect& a, const Rect& b) + [[nodiscard]] static Rect intersection(Rect const& a, Rect const& b) { Rect r = a; r.intersect(b); return r; } - ALWAYS_INLINE Rect intersected(const Rect& other) const + [[nodiscard]] ALWAYS_INLINE Rect intersected(Rect const& other) const { return intersection(*this, other); } - Rect united(const Rect&) const; + [[nodiscard]] Rect united(const Rect&) const; - Point top_left() const { return { left(), top() }; } - Point top_right() const { return { right(), top() }; } - Point bottom_left() const { return { left(), bottom() }; } - Point bottom_right() const { return { right(), bottom() }; } + [[nodiscard]] Point top_left() const { return { left(), top() }; } + [[nodiscard]] Point top_right() const { return { right(), top() }; } + [[nodiscard]] Point bottom_left() const { return { left(), bottom() }; } + [[nodiscard]] Point bottom_right() const { return { right(), bottom() }; } void align_within(const Rect&, TextAlignment); @@ -470,12 +470,12 @@ public: } template - ALWAYS_INLINE Rect to_type() const + [[nodiscard]] ALWAYS_INLINE Rect to_type() const { return Rect(*this); } - String to_string() const; + [[nodiscard]] String to_string() const; private: Point m_location; @@ -485,7 +485,7 @@ private: using IntRect = Rect; using FloatRect = Rect; -ALWAYS_INLINE IntRect enclosing_int_rect(const FloatRect& float_rect) +[[nodiscard]] ALWAYS_INLINE IntRect enclosing_int_rect(FloatRect const& float_rect) { return { (int)float_rect.x(),