diff options
Diffstat (limited to 'Libraries/LibGfx')
-rw-r--r-- | Libraries/LibGfx/FloatPoint.h | 34 | ||||
-rw-r--r-- | Libraries/LibGfx/Painter.cpp | 2 |
2 files changed, 34 insertions, 2 deletions
diff --git a/Libraries/LibGfx/FloatPoint.h b/Libraries/LibGfx/FloatPoint.h index ef50987e0b..59b10a06c0 100644 --- a/Libraries/LibGfx/FloatPoint.h +++ b/Libraries/LibGfx/FloatPoint.h @@ -30,6 +30,7 @@ #include <AK/String.h> #include <LibGfx/Orientation.h> #include <LibGfx/Point.h> +#include <LibM/math.h> namespace Gfx { @@ -38,12 +39,25 @@ class FloatRect; class FloatPoint { public: FloatPoint() { } + + FloatPoint(int x, int y) + : m_x(x) + , m_y(y) + { + } + FloatPoint(float x, float y) : m_x(x) , m_y(y) { } + FloatPoint(double x, double y) + : m_x(x) + , m_y(y) + { + } + explicit FloatPoint(const IntPoint& other) : m_x(other.x()) , m_y(other.y()) @@ -96,6 +110,7 @@ public: FloatPoint operator-() const { return { -m_x, -m_y }; } + FloatPoint operator-(float number) const { return { m_x - number, m_y - number }; } FloatPoint operator-(const FloatPoint& other) const { return { m_x - other.m_x, m_y - other.m_y }; } FloatPoint& operator-=(const FloatPoint& other) { @@ -104,14 +119,24 @@ public: return *this; } + FloatPoint operator+(float number) const { return { m_x + number, m_y + number }; } + FloatPoint operator+(const FloatPoint& other) const { return { m_x + other.m_x, m_y + other.m_y }; } FloatPoint& operator+=(const FloatPoint& other) { m_x += other.m_x; m_y += other.m_y; return *this; } - FloatPoint operator+(const FloatPoint& other) const { return { m_x + other.m_x, m_y + other.m_y }; } + FloatPoint operator*(float factor) const { return { m_x * factor, m_y * factor }; } + FloatPoint& operator*=(float factor) + { + m_x *= factor; + m_y *= factor; + return *this; + } + + FloatPoint operator/(float factor) const { return { m_x / factor, m_y / factor }; } FloatPoint& operator/=(float factor) { m_x /= factor; @@ -119,6 +144,13 @@ public: return *this; } + float distance_from(const FloatPoint& 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)); + } + String to_string() const { return String::format("[%g,%g]", x(), y()); } bool is_null() const { return !m_x && !m_y; } diff --git a/Libraries/LibGfx/Painter.cpp b/Libraries/LibGfx/Painter.cpp index c80356ad33..770f5f03de 100644 --- a/Libraries/LibGfx/Painter.cpp +++ b/Libraries/LibGfx/Painter.cpp @@ -1565,7 +1565,7 @@ void Painter::fill_path(Path& path, Color color, WindingRule winding_rule) #ifdef FILL_PATH_DEBUG size_t i { 0 }; for (auto& segment : segments) - draw_line(IntPoint(segment.from.x(), segment.from.y()), IntPoint(segment.to.x(), segment.to.y()), Color::from_hsv(++i / segments.size() * 255, 255, 255), 1); + draw_line(segment.from, segment.to, Color::from_hsv(++i / segments.size() * 255, 255, 255), 1); #endif } |