LibDraw: Add dx/dy_relative_to() helper functions for Points
This commit is contained in:
parent
f0a82e1bcc
commit
70a2355963
Notes:
sideshowbarker
2024-07-19 10:39:05 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/70a23559638 Pull-request: https://github.com/SerenityOS/serenity/pull/920
1 changed files with 14 additions and 8 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns pixels moved from other in either direction
|
int dx_relative_to(const Point& other) const
|
||||||
int pixels_moved(const Point &other) const
|
|
||||||
{
|
{
|
||||||
auto pixels_moved = max(
|
return x() - other.x();
|
||||||
abs(other.x() - x()),
|
}
|
||||||
abs(other.y() - y())
|
|
||||||
);
|
int dy_relative_to(const Point& other) const
|
||||||
return pixels_moved;
|
{
|
||||||
|
return y() - other.y();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns pixels moved from other in either direction
|
||||||
|
int pixels_moved(const Point& other) const
|
||||||
|
{
|
||||||
|
return max(abs(dx_relative_to(other)), abs(dy_relative_to(other)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Reference in a new issue