浏览代码

LibGfx: Add a bunch of [[nodiscard]] to Point

Andreas Kling 4 年之前
父节点
当前提交
20fb30d857
共有 1 个文件被更改,包括 27 次插入27 次删除
  1. 27 27
      Userland/Libraries/LibGfx/Point.h

+ 27 - 27
Userland/Libraries/LibGfx/Point.h

@@ -71,42 +71,42 @@ public:
 
     void transform_by(AffineTransform const& transform) { *this = transform.map(*this); }
 
-    Point<T> translated(Point<T> const& delta) const
+    [[nodiscard]] Point<T> translated(Point<T> const& delta) const
     {
         Point<T> point = *this;
         point.translate_by(delta);
         return point;
     }
 
-    Point<T> translated(T dx, T dy) const
+    [[nodiscard]] Point<T> translated(T dx, T dy) const
     {
         Point<T> point = *this;
         point.translate_by(dx, dy);
         return point;
     }
 
-    Point<T> translated(T dboth) const
+    [[nodiscard]] Point<T> translated(T dboth) const
     {
         Point<T> point = *this;
         point.translate_by(dboth, dboth);
         return point;
     }
 
-    Point<T> scaled(Point<T> const& delta) const
+    [[nodiscard]] Point<T> scaled(Point<T> const& delta) const
     {
         Point<T> point = *this;
         point.scale_by(delta);
         return point;
     }
 
-    Point<T> scaled(T sx, T sy) const
+    [[nodiscard]] Point<T> scaled(T sx, T sy) const
     {
         Point<T> point = *this;
         point.scale_by(sx, sy);
         return point;
     }
 
-    Point<T> transformed(AffineTransform const& transform) const
+    [[nodiscard]] Point<T> transformed(AffineTransform const& transform) const
     {
         Point<T> point = *this;
         point.transform_by(transform);
@@ -114,31 +114,31 @@ public:
     }
 
     void constrain(Rect<T> const&);
-    Point<T> constrained(Rect<T> const& rect) const
+    [[nodiscard]] Point<T> constrained(Rect<T> const& rect) const
     {
         Point<T> point = *this;
         point.constrain(rect);
         return point;
     }
 
-    Point<T> moved_left(T amount) const { return { x() - amount, y() }; }
-    Point<T> moved_right(T amount) const { return { x() + amount, y() }; }
-    Point<T> moved_up(T amount) const { return { x(), y() - amount }; }
-    Point<T> moved_down(T amount) const { return { x(), y() + amount }; }
+    [[nodiscard]] Point<T> moved_left(T amount) const { return { x() - amount, y() }; }
+    [[nodiscard]] Point<T> moved_right(T amount) const { return { x() + amount, y() }; }
+    [[nodiscard]] Point<T> moved_up(T amount) const { return { x(), y() - amount }; }
+    [[nodiscard]] Point<T> moved_down(T amount) const { return { x(), y() + amount }; }
 
     template<class U>
-    bool operator==(Point<U> const& other) const
+    [[nodiscard]] bool operator==(Point<U> const& other) const
     {
         return x() == other.x() && y() == other.y();
     }
 
     template<class U>
-    bool operator!=(Point<U> const& other) const
+    [[nodiscard]] bool operator!=(Point<U> const& other) const
     {
         return !(*this == other);
     }
 
-    Point<T> operator+(Point<T> const& other) const { return { m_x + other.m_x, m_y + other.m_y }; }
+    [[nodiscard]] Point<T> operator+(Point<T> const& other) const { return { m_x + other.m_x, m_y + other.m_y }; }
 
     Point<T>& operator+=(Point<T> const& other)
     {
@@ -147,9 +147,9 @@ public:
         return *this;
     }
 
-    Point<T> operator-() const { return { -m_x, -m_y }; }
+    [[nodiscard]] Point<T> operator-() const { return { -m_x, -m_y }; }
 
-    Point<T> operator-(Point<T> const& other) const { return { m_x - other.m_x, m_y - other.m_y }; }
+    [[nodiscard]] Point<T> operator-(Point<T> const& other) const { return { m_x - other.m_x, m_y - other.m_y }; }
 
     Point<T>& operator-=(Point<T> const& other)
     {
@@ -158,7 +158,7 @@ public:
         return *this;
     }
 
-    Point<T> operator*(T factor) const { return { m_x * factor, m_y * factor }; }
+    [[nodiscard]] Point<T> operator*(T factor) const { return { m_x * factor, m_y * factor }; }
 
     Point<T>& operator*=(T factor)
     {
@@ -167,7 +167,7 @@ public:
         return *this;
     }
 
-    Point<T> operator/(T factor) const { return { m_x / factor, m_y / factor }; }
+    [[nodiscard]] Point<T> operator/(T factor) const { return { m_x / factor, m_y / factor }; }
 
     Point<T>& operator/=(T factor)
     {
@@ -176,7 +176,7 @@ public:
         return *this;
     }
 
-    T primary_offset_for_orientation(Orientation orientation) const
+    [[nodiscard]] T primary_offset_for_orientation(Orientation orientation) const
     {
         return orientation == Orientation::Vertical ? y() : x();
     }
@@ -190,7 +190,7 @@ public:
         }
     }
 
-    T secondary_offset_for_orientation(Orientation orientation) const
+    [[nodiscard]] T secondary_offset_for_orientation(Orientation orientation) const
     {
         return orientation == Orientation::Vertical ? x() : y();
     }
@@ -204,41 +204,41 @@ public:
         }
     }
 
-    T dx_relative_to(Point<T> const& other) const
+    [[nodiscard]] T dx_relative_to(Point<T> const& other) const
     {
         return x() - other.x();
     }
 
-    T dy_relative_to(Point<T> const& other) const
+    [[nodiscard]] T dy_relative_to(Point<T> const& other) const
     {
         return y() - other.y();
     }
 
     // Returns pixels moved from other in either direction
-    T pixels_moved(Point<T> const& other) const
+    [[nodiscard]] T pixels_moved(Point<T> const& other) const
     {
         return max(abs(dx_relative_to(other)), abs(dy_relative_to(other)));
     }
 
-    float distance_from(Point<T> const& other) const
+    [[nodiscard]] float distance_from(Point<T> const& other) const
     {
         if (*this == other)
             return 0;
         return sqrtf(powf(m_x - other.m_x, 2.0f) + powf(m_y - other.m_y, 2.0f));
     }
 
-    Point absolute_relative_distance_to(Point const& other) const
+    [[nodiscard]] Point absolute_relative_distance_to(Point const& other) const
     {
         return { abs(dx_relative_to(other)), abs(dy_relative_to(other)) };
     }
 
     template<typename U>
-    Point<U> to_type() const
+    [[nodiscard]] Point<U> to_type() const
     {
         return Point<U>(*this);
     }
 
-    String to_string() const;
+    [[nodiscard]] String to_string() const;
 
 private:
     T m_x { 0 };