From 3f57037ee71e7cd9e94ec78980520d83f64f56aa Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 16 Jun 2021 19:18:01 +0200 Subject: [PATCH] LibGfx: Convert Rect to east-const style --- Userland/Libraries/LibGfx/Rect.cpp | 14 ++++---- Userland/Libraries/LibGfx/Rect.h | 58 +++++++++++++++--------------- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/Userland/Libraries/LibGfx/Rect.cpp b/Userland/Libraries/LibGfx/Rect.cpp index 96d986ad7c..7fbf5022c7 100644 --- a/Userland/Libraries/LibGfx/Rect.cpp +++ b/Userland/Libraries/LibGfx/Rect.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2018-2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -14,7 +14,7 @@ namespace Gfx { template -void Rect::intersect(const Rect& other) +void Rect::intersect(Rect const& other) { T l = max(left(), other.left()); T r = min(right(), other.right()); @@ -34,7 +34,7 @@ void Rect::intersect(const Rect& other) } template -Rect Rect::united(const Rect& other) const +Rect Rect::united(Rect const& other) const { if (is_null()) return other; @@ -49,7 +49,7 @@ Rect Rect::united(const Rect& other) const } template -Vector, 4> Rect::shatter(const Rect& hammer) const +Vector, 4> Rect::shatter(Rect const& hammer) const { Vector, 4> pieces; if (!intersects(hammer)) { @@ -93,7 +93,7 @@ Vector, 4> Rect::shatter(const Rect& hammer) const } template -void Rect::align_within(const Rect& other, TextAlignment alignment) +void Rect::align_within(Rect const& other, TextAlignment alignment) { switch (alignment) { case TextAlignment::Center: @@ -126,7 +126,7 @@ void Rect::align_within(const Rect& other, TextAlignment alignment) } template -void Rect::set_size_around(const Size& new_size, const Point& fixed_point) +void Rect::set_size_around(Size const& new_size, Point const& fixed_point) { const T new_x = fixed_point.x() - (T)(new_size.width() * ((float)(fixed_point.x() - x()) / width())); const T new_y = fixed_point.y() - (T)(new_size.height() * ((float)(fixed_point.y() - y()) / height())); @@ -151,7 +151,7 @@ String FloatRect::to_string() const namespace IPC { -bool encode(Encoder& encoder, const Gfx::IntRect& rect) +bool encode(Encoder& encoder, Gfx::IntRect const& rect) { encoder << rect.location() << rect.size(); return true; diff --git a/Userland/Libraries/LibGfx/Rect.h b/Userland/Libraries/LibGfx/Rect.h index 268b52e0d9..347d415705 100644 --- a/Userland/Libraries/LibGfx/Rect.h +++ b/Userland/Libraries/LibGfx/Rect.h @@ -40,21 +40,21 @@ public: { } - Rect(const Point& location, const Size& size) + Rect(Point const& location, Size const& size) : m_location(location) , m_size(size) { } template - Rect(const Point& location, const Size& size) + Rect(Point const& location, Size const& size) : m_location(location) , m_size(size) { } template - explicit Rect(const Rect& other) + explicit Rect(Rect const& other) : m_location(other.location()) , m_size(other.size()) { @@ -70,15 +70,15 @@ public: ALWAYS_INLINE void set_width(T width) { m_size.set_width(width); } ALWAYS_INLINE void set_height(T height) { m_size.set_height(height); } - [[nodiscard]] ALWAYS_INLINE const Point& location() const { return m_location; } - [[nodiscard]] ALWAYS_INLINE const Size& size() const { return m_size; } + [[nodiscard]] ALWAYS_INLINE Point const& location() const { return m_location; } + [[nodiscard]] ALWAYS_INLINE Size const& size() const { return m_size; } [[nodiscard]] ALWAYS_INLINE bool is_null() const { return width() == 0 && height() == 0; } [[nodiscard]] ALWAYS_INLINE bool is_empty() const { return width() <= 0 || height() <= 0; } ALWAYS_INLINE void translate_by(T dx, T dy) { m_location.translate_by(dx, dy); } ALWAYS_INLINE void translate_by(T dboth) { m_location.translate_by(dboth); } - ALWAYS_INLINE void translate_by(const Point& delta) { m_location.translate_by(delta); } + ALWAYS_INLINE void translate_by(Point const& delta) { m_location.translate_by(delta); } ALWAYS_INLINE void scale_by(T dx, T dy) { @@ -86,26 +86,26 @@ public: m_size.scale_by(dx, dy); } ALWAYS_INLINE void scale_by(T dboth) { scale_by(dboth, dboth); } - ALWAYS_INLINE void scale_by(const Point& delta) { scale_by(delta.x(), delta.y()); } + ALWAYS_INLINE void scale_by(Point const& delta) { scale_by(delta.x(), delta.y()); } - void transform_by(const AffineTransform& transform) { *this = transform.map(*this); } + void transform_by(AffineTransform const& transform) { *this = transform.map(*this); } [[nodiscard]] Point center() const { return { x() + width() / 2, y() + height() / 2 }; } - ALWAYS_INLINE void set_location(const Point& location) + ALWAYS_INLINE void set_location(Point const& location) { m_location = location; } - ALWAYS_INLINE void set_size(const Size& size) + ALWAYS_INLINE void set_size(Size const& size) { m_size = size; } - void set_size_around(const Size&, const Point& fixed_point); + void set_size_around(Size const&, Point const& fixed_point); void set_size(T width, T height) { @@ -121,7 +121,7 @@ public: set_height(height() + h); } - void inflate(const Size& size) + void inflate(Size const& size) { set_x(x() - size.width() / 2); set_width(width() + size.width()); @@ -137,7 +137,7 @@ public: set_height(height() - h); } - void shrink(const Size& size) + void shrink(Size const& size) { set_x(x() + size.width() / 2); set_width(width() - size.width()); @@ -267,12 +267,12 @@ public: return x >= m_location.x() && x <= right() && y >= m_location.y() && y <= bottom(); } - [[nodiscard]] ALWAYS_INLINE bool contains(const Point& point) const + [[nodiscard]] ALWAYS_INLINE bool contains(Point const& point) const { return contains(point.x(), point.y()); } - [[nodiscard]] bool contains(const Rect& other) const + [[nodiscard]] bool contains(Rect const& other) const { return left() <= other.left() && right() >= other.right() @@ -281,10 +281,10 @@ public: } template - [[nodiscard]] bool contains(const Container& others) const + [[nodiscard]] bool contains(Container const& others) const { bool have_any = false; - for (const auto& other : others) { + for (auto const& other : others) { if (!contains(other)) return false; have_any = true; @@ -374,7 +374,7 @@ public: template [[nodiscard]] bool intersects(Container const& others) const { - for (const auto& other : others) { + for (auto const& other : others) { if (intersects(other)) return true; } @@ -382,11 +382,11 @@ public: } template - IterationDecision for_each_intersected(const Container& others, Function f) const + IterationDecision for_each_intersected(Container const& others, Function f) const { if (is_empty()) return IterationDecision::Continue; - for (const auto& other : others) { + for (auto const& other : others) { auto intersected_rect = intersected(other); if (!intersected_rect.is_empty()) { IterationDecision decision = f(intersected_rect); @@ -406,7 +406,7 @@ public: } template - [[nodiscard]] bool operator!=(const Rect& other) const + [[nodiscard]] bool operator!=(Rect const& other) const { return !(*this == other); } @@ -420,14 +420,14 @@ public: return *this; } - void intersect(const Rect&); + void intersect(Rect const&); - [[nodiscard]] static Rect centered_on(const Point& center, const Size& size) + [[nodiscard]] static Rect centered_on(Point const& center, Size const& size) { return { { center.x() - size.width() / 2, center.y() - size.height() / 2 }, size }; } - [[nodiscard]] static Rect from_two_points(const Point& a, const Point& b) + [[nodiscard]] static Rect from_two_points(Point const& a, Point const& b) { return { min(a.x(), b.x()), min(a.y(), b.y()), abst(a.x() - b.x()), abst(a.y() - b.y()) }; } @@ -444,27 +444,27 @@ public: return intersection(*this, other); } - [[nodiscard]] Rect united(const Rect&) const; + [[nodiscard]] Rect united(Rect const&) const; [[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); + void align_within(Rect const&, TextAlignment); - void center_within(const Rect& other) + void center_within(Rect const& other) { center_horizontally_within(other); center_vertically_within(other); } - void center_horizontally_within(const Rect& other) + void center_horizontally_within(Rect const& other) { set_x(other.center().x() - width() / 2); } - void center_vertically_within(const Rect& other) + void center_vertically_within(Rect const& other) { set_y(other.center().y() - height() / 2); }