Przeglądaj źródła

LibDraw: Add dx/dy_relative_to() helper functions for Points

Shannon Booth 5 lat temu
rodzic
commit
70a2355963
1 zmienionych plików z 13 dodań i 7 usunięć
  1. 13 7
      Libraries/LibDraw/Point.h

+ 13 - 7
Libraries/LibDraw/Point.h

@@ -1,7 +1,7 @@
 #pragma once
 #pragma once
 
 
-#include <AK/String.h>
 #include <AK/LogStream.h>
 #include <AK/LogStream.h>
+#include <AK/String.h>
 #include <LibDraw/Orientation.h>
 #include <LibDraw/Orientation.h>
 
 
 class Rect;
 class Rect;
@@ -107,14 +107,20 @@ public:
             set_y(value);
             set_y(value);
     }
     }
 
 
+    int dx_relative_to(const Point& other) const
+    {
+        return x() - other.x();
+    }
+
+    int dy_relative_to(const Point& other) const
+    {
+        return y() - other.y();
+    }
+
     // Returns pixels moved from other in either direction
     // Returns pixels moved from other in either direction
-    int pixels_moved(const Point &other) const
+    int pixels_moved(const Point& other) const
     {
     {
-        auto pixels_moved = max(
-            abs(other.x() - x()),
-            abs(other.y() - y())
-        );
-        return pixels_moved;
+        return max(abs(dx_relative_to(other)), abs(dy_relative_to(other)));
     }
     }
 
 
 private:
 private: