/src/serenity/Userland/Libraries/LibGfx/Point.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <AK/Format.h> |
10 | | #include <AK/Math.h> |
11 | | #include <AK/StdLibExtras.h> |
12 | | #include <LibGfx/AffineTransform.h> |
13 | | #include <LibGfx/Forward.h> |
14 | | #include <LibGfx/Orientation.h> |
15 | | #include <LibIPC/Forward.h> |
16 | | #include <math.h> |
17 | | |
18 | | namespace Gfx { |
19 | | |
20 | | template<typename T> |
21 | | class Point { |
22 | | public: |
23 | 351M | Point() = default; Line | Count | Source | 23 | 272M | Point() = default; |
Unexecuted instantiation: Gfx::Point<unsigned int>::Point() Gfx::Point<float>::Point() Line | Count | Source | 23 | 78.9M | Point() = default; |
Unexecuted instantiation: Gfx::Point<Web::CSSPixels>::Point() Unexecuted instantiation: Gfx::Point<double>::Point() Unexecuted instantiation: Gfx::Point<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::Point() |
24 | | |
25 | | constexpr Point(T x, T y) |
26 | 1.12G | : m_x(x) |
27 | 1.12G | , m_y(y) |
28 | 1.12G | { |
29 | 1.12G | } Unexecuted instantiation: Gfx::Point<Web::CSSPixels>::Point(Web::CSSPixels, Web::CSSPixels) Unexecuted instantiation: Gfx::Point<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::Point(AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment>, AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment>) Gfx::Point<int>::Point(int, int) Line | Count | Source | 26 | 371M | : m_x(x) | 27 | 371M | , m_y(y) | 28 | 371M | { | 29 | 371M | } |
Unexecuted instantiation: Gfx::Point<unsigned int>::Point(unsigned int, unsigned int) Gfx::Point<float>::Point(float, float) Line | Count | Source | 26 | 749M | : m_x(x) | 27 | 749M | , m_y(y) | 28 | 749M | { | 29 | 749M | } |
Unexecuted instantiation: Gfx::Point<double>::Point(double, double) |
30 | | |
31 | | template<typename U> |
32 | | constexpr Point(U x, U y) |
33 | 46.2M | : m_x(x) |
34 | 46.2M | , m_y(y) |
35 | 46.2M | { |
36 | 46.2M | } Unexecuted instantiation: Gfx::Point<Web::CSSPixels>::Point<int>(int, int) Unexecuted instantiation: Gfx::Point<Web::CSSPixels>::Point<double>(double, double) Unexecuted instantiation: Gfx::Point<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::Point<double>(double, double) Unexecuted instantiation: Gfx::Point<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::Point<float>(float, float) Gfx::Point<int>::Point<unsigned short>(unsigned short, unsigned short) Line | Count | Source | 33 | 14.3k | : m_x(x) | 34 | 14.3k | , m_y(y) | 35 | 14.3k | { | 36 | 14.3k | } |
Unexecuted instantiation: Gfx::Point<int>::Point<AK::BigEndian<unsigned int> >(AK::BigEndian<unsigned int>, AK::BigEndian<unsigned int>) Gfx::Point<int>::Point<unsigned int>(unsigned int, unsigned int) Line | Count | Source | 33 | 8.90M | : m_x(x) | 34 | 8.90M | , m_y(y) | 35 | 8.90M | { | 36 | 8.90M | } |
Gfx::Point<int>::Point<unsigned long>(unsigned long, unsigned long) Line | Count | Source | 33 | 28.6M | : m_x(x) | 34 | 28.6M | , m_y(y) | 35 | 28.6M | { | 36 | 28.6M | } |
Unexecuted instantiation: Gfx::Point<int>::Point<float>(float, float) Gfx::Point<float>::Point<int>(int, int) Line | Count | Source | 33 | 6.15M | : m_x(x) | 34 | 6.15M | , m_y(y) | 35 | 6.15M | { | 36 | 6.15M | } |
Gfx::Point<float>::Point<double>(double, double) Line | Count | Source | 33 | 2.48M | : m_x(x) | 34 | 2.48M | , m_y(y) | 35 | 2.48M | { | 36 | 2.48M | } |
|
37 | | |
38 | | template<typename U> |
39 | | explicit Point(Point<U> const& other) |
40 | 29.4M | : m_x(other.x()) |
41 | 29.4M | , m_y(other.y()) |
42 | 29.4M | { |
43 | 29.4M | } Unexecuted instantiation: Gfx::Point<Web::CSSPixels>::Point<float>(Gfx::Point<float> const&) Unexecuted instantiation: Gfx::Point<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::Point<double>(Gfx::Point<double> const&) Unexecuted instantiation: Gfx::Point<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::Point<int>(Gfx::Point<int> const&) Gfx::Point<float>::Point<int>(Gfx::Point<int> const&) Line | Count | Source | 40 | 29.4M | : m_x(other.x()) | 41 | 29.4M | , m_y(other.y()) | 42 | 29.4M | { | 43 | 29.4M | } |
Unexecuted instantiation: Gfx::Point<int>::Point<float>(Gfx::Point<float> const&) Unexecuted instantiation: Gfx::Point<int>::Point<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >(Gfx::Point<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> > const&) Unexecuted instantiation: Gfx::Point<float>::Point<double>(Gfx::Point<double> const&) Unexecuted instantiation: Gfx::Point<float>::Point<Web::CSSPixels>(Gfx::Point<Web::CSSPixels> const&) Unexecuted instantiation: Gfx::Point<double>::Point<Web::CSSPixels>(Gfx::Point<Web::CSSPixels> const&) |
44 | | |
45 | 2.33G | [[nodiscard]] constexpr ALWAYS_INLINE T x() const { return m_x; }Gfx::Point<int>::x() const Line | Count | Source | 45 | 1.44G | [[nodiscard]] constexpr ALWAYS_INLINE T x() const { return m_x; } |
Gfx::Point<float>::x() const Line | Count | Source | 45 | 895M | [[nodiscard]] constexpr ALWAYS_INLINE T x() const { return m_x; } |
Unexecuted instantiation: Gfx::Point<unsigned int>::x() const Unexecuted instantiation: Gfx::Point<Web::CSSPixels>::x() const Unexecuted instantiation: Gfx::Point<double>::x() const Unexecuted instantiation: Gfx::Point<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::x() const |
46 | 2.37G | [[nodiscard]] constexpr ALWAYS_INLINE T y() const { return m_y; }Gfx::Point<int>::y() const Line | Count | Source | 46 | 1.21G | [[nodiscard]] constexpr ALWAYS_INLINE T y() const { return m_y; } |
Gfx::Point<float>::y() const Line | Count | Source | 46 | 1.16G | [[nodiscard]] constexpr ALWAYS_INLINE T y() const { return m_y; } |
Unexecuted instantiation: Gfx::Point<unsigned int>::y() const Unexecuted instantiation: Gfx::Point<Web::CSSPixels>::y() const Unexecuted instantiation: Gfx::Point<double>::y() const Unexecuted instantiation: Gfx::Point<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::y() const |
47 | | |
48 | 23.6M | ALWAYS_INLINE void set_x(T x) { m_x = x; }Gfx::Point<int>::set_x(int) Line | Count | Source | 48 | 23.6M | ALWAYS_INLINE void set_x(T x) { m_x = x; } |
Gfx::Point<float>::set_x(float) Line | Count | Source | 48 | 414 | ALWAYS_INLINE void set_x(T x) { m_x = x; } |
Unexecuted instantiation: Gfx::Point<double>::set_x(double) Unexecuted instantiation: Gfx::Point<Web::CSSPixels>::set_x(Web::CSSPixels) Unexecuted instantiation: Gfx::Point<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::set_x(AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment>) |
49 | 23.6M | ALWAYS_INLINE void set_y(T y) { m_y = y; }Gfx::Point<int>::set_y(int) Line | Count | Source | 49 | 23.6M | ALWAYS_INLINE void set_y(T y) { m_y = y; } |
Gfx::Point<float>::set_y(float) Line | Count | Source | 49 | 414 | ALWAYS_INLINE void set_y(T y) { m_y = y; } |
Unexecuted instantiation: Gfx::Point<double>::set_y(double) Unexecuted instantiation: Gfx::Point<Web::CSSPixels>::set_y(Web::CSSPixels) Unexecuted instantiation: Gfx::Point<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::set_y(AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment>) |
50 | | |
51 | 0 | [[nodiscard]] ALWAYS_INLINE bool is_zero() const { return m_x == 0 && m_y == 0; } |
52 | | |
53 | | void translate_by(T dx, T dy) |
54 | 30.7M | { |
55 | 30.7M | m_x += dx; |
56 | 30.7M | m_y += dy; |
57 | 30.7M | } Gfx::Point<int>::translate_by(int, int) Line | Count | Source | 54 | 29.4M | { | 55 | 29.4M | m_x += dx; | 56 | 29.4M | m_y += dy; | 57 | 29.4M | } |
Gfx::Point<float>::translate_by(float, float) Line | Count | Source | 54 | 1.25M | { | 55 | 1.25M | m_x += dx; | 56 | 1.25M | m_y += dy; | 57 | 1.25M | } |
Unexecuted instantiation: Gfx::Point<Web::CSSPixels>::translate_by(Web::CSSPixels, Web::CSSPixels) Unexecuted instantiation: Gfx::Point<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::translate_by(AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment>, AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment>) |
58 | | |
59 | | ALWAYS_INLINE void translate_by(T dboth) { translate_by(dboth, dboth); } |
60 | 30.5M | ALWAYS_INLINE void translate_by(Point<T> const& delta) { translate_by(delta.x(), delta.y()); }Gfx::Point<int>::translate_by(Gfx::Point<int> const&) Line | Count | Source | 60 | 29.4M | ALWAYS_INLINE void translate_by(Point<T> const& delta) { translate_by(delta.x(), delta.y()); } |
Gfx::Point<float>::translate_by(Gfx::Point<float> const&) Line | Count | Source | 60 | 1.10M | ALWAYS_INLINE void translate_by(Point<T> const& delta) { translate_by(delta.x(), delta.y()); } |
Unexecuted instantiation: Gfx::Point<Web::CSSPixels>::translate_by(Gfx::Point<Web::CSSPixels> const&) |
61 | | |
62 | | void scale_by(T dx, T dy) |
63 | 174M | { |
64 | 174M | m_x *= dx; |
65 | 174M | m_y *= dy; |
66 | 174M | } |
67 | | |
68 | 0 | ALWAYS_INLINE void scale_by(T dboth) { scale_by(dboth, dboth); } |
69 | | ALWAYS_INLINE void scale_by(Point<T> const& delta) { scale_by(delta.x(), delta.y()); } |
70 | | |
71 | 0 | void transform_by(AffineTransform const& transform) { *this = transform.map(*this); } |
72 | | |
73 | | [[nodiscard]] Point<T> translated(Point<T> const& delta) const |
74 | 28.3M | { |
75 | 28.3M | Point<T> point = *this; |
76 | 28.3M | point.translate_by(delta); |
77 | 28.3M | return point; |
78 | 28.3M | } Gfx::Point<int>::translated(Gfx::Point<int> const&) const Line | Count | Source | 74 | 28.3M | { | 75 | 28.3M | Point<T> point = *this; | 76 | 28.3M | point.translate_by(delta); | 77 | 28.3M | return point; | 78 | 28.3M | } |
Unexecuted instantiation: Gfx::Point<Web::CSSPixels>::translated(Gfx::Point<Web::CSSPixels> const&) const Unexecuted instantiation: Gfx::Point<float>::translated(Gfx::Point<float> const&) const |
79 | | |
80 | | [[nodiscard]] Point<T> translated(T dx, T dy) const |
81 | 0 | { |
82 | 0 | Point<T> point = *this; |
83 | 0 | point.translate_by(dx, dy); |
84 | 0 | return point; |
85 | 0 | } Unexecuted instantiation: Gfx::Point<float>::translated(float, float) const Unexecuted instantiation: Gfx::Point<int>::translated(int, int) const Unexecuted instantiation: Gfx::Point<Web::CSSPixels>::translated(Web::CSSPixels, Web::CSSPixels) const Unexecuted instantiation: Gfx::Point<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::translated(AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment>, AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment>) const |
86 | | |
87 | | [[nodiscard]] Point<T> translated(T dboth) const |
88 | 0 | { |
89 | 0 | Point<T> point = *this; |
90 | 0 | point.translate_by(dboth, dboth); |
91 | 0 | return point; |
92 | 0 | } Unexecuted instantiation: Gfx::Point<int>::translated(int) const Unexecuted instantiation: Gfx::Point<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::translated(AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment>) const |
93 | | |
94 | | [[nodiscard]] Point<T> scaled(T dboth) const |
95 | 0 | { |
96 | 0 | Point<T> point = *this; |
97 | 0 | point.scale_by(dboth); |
98 | 0 | return point; |
99 | 0 | } |
100 | | |
101 | | [[nodiscard]] Point<T> scaled(Point<T> const& delta) const |
102 | | { |
103 | | Point<T> point = *this; |
104 | | point.scale_by(delta); |
105 | | return point; |
106 | | } |
107 | | |
108 | | [[nodiscard]] Point<T> scaled(T sx, T sy) const |
109 | 39.5M | { |
110 | 39.5M | Point<T> point = *this; |
111 | 39.5M | point.scale_by(sx, sy); |
112 | 39.5M | return point; |
113 | 39.5M | } |
114 | | |
115 | | [[nodiscard]] Point<T> transformed(AffineTransform const& transform) const |
116 | | { |
117 | | Point<T> point = *this; |
118 | | point.transform_by(transform); |
119 | | return point; |
120 | | } |
121 | | |
122 | | void constrain(Rect<T> const&); |
123 | | [[nodiscard]] Point<T> constrained(Rect<T> const& rect) const |
124 | | { |
125 | | Point<T> point = *this; |
126 | | point.constrain(rect); |
127 | | return point; |
128 | | } |
129 | | |
130 | 0 | [[nodiscard]] Point<T> moved_left(T amount) const { return { x() - amount, y() }; }Unexecuted instantiation: Gfx::Point<int>::moved_left(int) const Unexecuted instantiation: Gfx::Point<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::moved_left(AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment>) const |
131 | 0 | [[nodiscard]] Point<T> moved_right(T amount) const { return { x() + amount, y() }; } |
132 | 0 | [[nodiscard]] Point<T> moved_up(T amount) const { return { x(), y() - amount }; }Unexecuted instantiation: Gfx::Point<int>::moved_up(int) const Unexecuted instantiation: Gfx::Point<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::moved_up(AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment>) const |
133 | 0 | [[nodiscard]] Point<T> moved_down(T amount) const { return { x(), y() + amount }; } |
134 | | |
135 | | template<class U> |
136 | | [[nodiscard]] bool operator==(Point<U> const& other) const |
137 | 92.7M | { |
138 | 92.7M | return x() == other.x() && y() == other.y(); |
139 | 92.7M | } bool Gfx::Point<int>::operator==<int>(Gfx::Point<int> const&) const Line | Count | Source | 137 | 56.7k | { | 138 | 56.7k | return x() == other.x() && y() == other.y(); | 139 | 56.7k | } |
bool Gfx::Point<float>::operator==<float>(Gfx::Point<float> const&) const Line | Count | Source | 137 | 92.6M | { | 138 | 92.6M | return x() == other.x() && y() == other.y(); | 139 | 92.6M | } |
Unexecuted instantiation: bool Gfx::Point<float>::operator==<int>(Gfx::Point<int> const&) const Unexecuted instantiation: bool Gfx::Point<int>::operator==<float>(Gfx::Point<float> const&) const Unexecuted instantiation: bool Gfx::Point<Web::CSSPixels>::operator==<Web::CSSPixels>(Gfx::Point<Web::CSSPixels> const&) const |
140 | | |
141 | 324M | [[nodiscard]] Point<T> operator+(Point<T> const& other) const { return { m_x + other.m_x, m_y + other.m_y }; }Gfx::Point<int>::operator+(Gfx::Point<int> const&) const Line | Count | Source | 141 | 79.6M | [[nodiscard]] Point<T> operator+(Point<T> const& other) const { return { m_x + other.m_x, m_y + other.m_y }; } |
Gfx::Point<float>::operator+(Gfx::Point<float> const&) const Line | Count | Source | 141 | 245M | [[nodiscard]] Point<T> operator+(Point<T> const& other) const { return { m_x + other.m_x, m_y + other.m_y }; } |
Unexecuted instantiation: Gfx::Point<Web::CSSPixels>::operator+(Gfx::Point<Web::CSSPixels> const&) const Unexecuted instantiation: Gfx::Point<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::operator+(Gfx::Point<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> > const&) const |
142 | | |
143 | | Point<T>& operator+=(Point<T> const& other) |
144 | 348 | { |
145 | 348 | m_x += other.m_x; |
146 | 348 | m_y += other.m_y; |
147 | 348 | return *this; |
148 | 348 | } Unexecuted instantiation: Gfx::Point<int>::operator+=(Gfx::Point<int> const&) Gfx::Point<float>::operator+=(Gfx::Point<float> const&) Line | Count | Source | 144 | 348 | { | 145 | 348 | m_x += other.m_x; | 146 | 348 | m_y += other.m_y; | 147 | 348 | return *this; | 148 | 348 | } |
|
149 | | |
150 | 414 | [[nodiscard]] Point<T> operator-() const { return { -m_x, -m_y }; }Unexecuted instantiation: Gfx::Point<int>::operator-() const Gfx::Point<float>::operator-() const Line | Count | Source | 150 | 414 | [[nodiscard]] Point<T> operator-() const { return { -m_x, -m_y }; } |
Unexecuted instantiation: Gfx::Point<Web::CSSPixels>::operator-() const |
151 | | |
152 | 202M | [[nodiscard]] Point<T> operator-(Point<T> const& other) const { return { m_x - other.m_x, m_y - other.m_y }; }Unexecuted instantiation: Gfx::Point<int>::operator-(Gfx::Point<int> const&) const Gfx::Point<float>::operator-(Gfx::Point<float> const&) const Line | Count | Source | 152 | 202M | [[nodiscard]] Point<T> operator-(Point<T> const& other) const { return { m_x - other.m_x, m_y - other.m_y }; } |
Unexecuted instantiation: Gfx::Point<Web::CSSPixels>::operator-(Gfx::Point<Web::CSSPixels> const&) const |
153 | | |
154 | | Point<T>& operator-=(Point<T> const& other) |
155 | | { |
156 | | m_x -= other.m_x; |
157 | | m_y -= other.m_y; |
158 | | return *this; |
159 | | } |
160 | | |
161 | 341 | [[nodiscard]] Point<T> operator*(T factor) const { return { m_x * factor, m_y * factor }; }Gfx::Point<int>::operator*(int) const Line | Count | Source | 161 | 341 | [[nodiscard]] Point<T> operator*(T factor) const { return { m_x * factor, m_y * factor }; } |
Unexecuted instantiation: Gfx::Point<float>::operator*(float) const Unexecuted instantiation: Gfx::Point<double>::operator*(double) const |
162 | | |
163 | | Point<T>& operator*=(T factor) |
164 | 166 | { |
165 | 166 | m_x *= factor; |
166 | 166 | m_y *= factor; |
167 | 166 | return *this; |
168 | 166 | } Gfx::Point<int>::operator*=(int) Line | Count | Source | 164 | 166 | { | 165 | 166 | m_x *= factor; | 166 | 166 | m_y *= factor; | 167 | 166 | return *this; | 168 | 166 | } |
Unexecuted instantiation: Gfx::Point<double>::operator*=(double) |
169 | | |
170 | 142M | [[nodiscard]] Point<T> operator/(T factor) const { return { m_x / factor, m_y / factor }; }Gfx::Point<float>::operator/(float) const Line | Count | Source | 170 | 142M | [[nodiscard]] Point<T> operator/(T factor) const { return { m_x / factor, m_y / factor }; } |
Unexecuted instantiation: Gfx::Point<int>::operator/(int) const |
171 | | |
172 | | Point<T>& operator/=(T factor) |
173 | 52.8M | { |
174 | 52.8M | m_x /= factor; |
175 | 52.8M | m_y /= factor; |
176 | 52.8M | return *this; |
177 | 52.8M | } Gfx::Point<int>::operator/=(int) Line | Count | Source | 173 | 3.30M | { | 174 | 3.30M | m_x /= factor; | 175 | 3.30M | m_y /= factor; | 176 | 3.30M | return *this; | 177 | 3.30M | } |
Gfx::Point<float>::operator/=(float) Line | Count | Source | 173 | 49.5M | { | 174 | 49.5M | m_x /= factor; | 175 | 49.5M | m_y /= factor; | 176 | 49.5M | return *this; | 177 | 49.5M | } |
|
178 | | |
179 | | [[nodiscard]] T primary_offset_for_orientation(Orientation orientation) const |
180 | | { |
181 | | return orientation == Orientation::Vertical ? y() : x(); |
182 | | } |
183 | | |
184 | | void set_primary_offset_for_orientation(Orientation orientation, T value) |
185 | | { |
186 | | if (orientation == Orientation::Vertical) { |
187 | | set_y(value); |
188 | | } else { |
189 | | set_x(value); |
190 | | } |
191 | | } |
192 | | |
193 | | [[nodiscard]] T secondary_offset_for_orientation(Orientation orientation) const |
194 | | { |
195 | | return orientation == Orientation::Vertical ? x() : y(); |
196 | | } |
197 | | |
198 | | void set_secondary_offset_for_orientation(Orientation orientation, T value) |
199 | | { |
200 | | if (orientation == Orientation::Vertical) { |
201 | | set_x(value); |
202 | | } else { |
203 | | set_y(value); |
204 | | } |
205 | | } |
206 | | |
207 | | [[nodiscard]] T dx_relative_to(Point<T> const& other) const |
208 | 0 | { |
209 | 0 | return x() - other.x(); |
210 | 0 | } |
211 | | |
212 | | [[nodiscard]] T dy_relative_to(Point<T> const& other) const |
213 | 0 | { |
214 | 0 | return y() - other.y(); |
215 | 0 | } |
216 | | |
217 | | // Returns pixels moved from other in either direction |
218 | | [[nodiscard]] T pixels_moved(Point<T> const& other) const |
219 | | { |
220 | | return max(AK::abs(dx_relative_to(other)), AK::abs(dy_relative_to(other))); |
221 | | } |
222 | | |
223 | | [[nodiscard]] float distance_from(Point<T> const& other) const |
224 | 19.1M | { |
225 | 19.1M | if (*this == other) |
226 | 35.6k | return 0; |
227 | 19.0M | return AK::hypot<float>(m_x - other.m_x, m_y - other.m_y); |
228 | 19.1M | } |
229 | | |
230 | | [[nodiscard]] Point absolute_relative_distance_to(Point const& other) const |
231 | | { |
232 | | return { AK::abs(dx_relative_to(other)), AK::abs(dy_relative_to(other)) }; |
233 | | } |
234 | | |
235 | | [[nodiscard]] Point end_point_for_aspect_ratio(Point const& previous_end_point, float aspect_ratio) const; |
236 | | |
237 | | template<typename U> |
238 | | requires(!IsSame<T, U>) |
239 | | [[nodiscard]] Point<U> to_type() const |
240 | 29.4M | { |
241 | 29.4M | return Point<U>(*this); |
242 | 29.4M | } _ZNK3Gfx5PointIiE7to_typeIfQnt6IsSameIT_TL0__EEENS0_IS3_EEv Line | Count | Source | 240 | 29.4M | { | 241 | 29.4M | return Point<U>(*this); | 242 | 29.4M | } |
Unexecuted instantiation: _ZNK3Gfx5PointIfE7to_typeIiQnt6IsSameIT_TL0__EEENS0_IS3_EEv Unexecuted instantiation: _ZNK3Gfx5PointIN2AK15DistinctNumericIiN3Web18__DevicePixels_tagEJNS1_22DistinctNumericFeature10ArithmeticENS5_16CastToUnderlyingENS5_10ComparisonENS5_9IncrementEEEEE7to_typeIiQnt6IsSameIT_TL0__EEENS0_ISD_EEv Unexecuted instantiation: _ZNK3Gfx5PointIN3Web9CSSPixelsEE7to_typeIfQnt6IsSameIT_TL0__EEENS0_IS5_EEv Unexecuted instantiation: _ZNK3Gfx5PointIfE7to_typeIN3Web9CSSPixelsEQnt6IsSameIT_TL0__EEENS0_IS5_EEv Unexecuted instantiation: _ZNK3Gfx5PointIN3Web9CSSPixelsEE7to_typeIdQnt6IsSameIT_TL0__EEENS0_IS5_EEv |
243 | | |
244 | | template<typename U> |
245 | | [[nodiscard]] Point<U> to_rounded() const |
246 | 0 | { |
247 | 0 | return Point<U>(roundf(x()), roundf(y())); |
248 | 0 | } |
249 | | |
250 | | template<typename U> |
251 | | requires FloatingPoint<T> |
252 | | [[nodiscard]] Point<U> to_ceiled() const |
253 | | { |
254 | | return Point<U>(ceil(x()), ceil(y())); |
255 | | } |
256 | | |
257 | | template<typename U> |
258 | | requires FloatingPoint<T> |
259 | | [[nodiscard]] Point<U> to_floored() const |
260 | | { |
261 | | return Point<U>(AK::floor(x()), AK::floor(y())); |
262 | | } |
263 | | |
264 | | [[nodiscard]] ByteString to_byte_string() const; |
265 | | |
266 | | private: |
267 | | T m_x { 0 }; |
268 | | T m_y { 0 }; |
269 | | }; |
270 | | |
271 | | template<typename T> |
272 | | [[nodiscard]] Point<T> operator*(T factor, Point<T> const& p) { return { factor * p.x(), factor * p.y() }; } |
273 | | |
274 | | using IntPoint = Point<int>; |
275 | | using FloatPoint = Point<float>; |
276 | | |
277 | | } |
278 | | |
279 | | namespace AK { |
280 | | |
281 | | template<typename T> |
282 | | struct Formatter<Gfx::Point<T>> : Formatter<FormatString> { |
283 | | ErrorOr<void> format(FormatBuilder& builder, Gfx::Point<T> const& value) |
284 | 0 | { |
285 | 0 | return Formatter<FormatString>::format(builder, "[{},{}]"sv, value.x(), value.y()); |
286 | 0 | } |
287 | | }; |
288 | | |
289 | | } |
290 | | |
291 | | namespace IPC { |
292 | | |
293 | | template<> |
294 | | ErrorOr<void> encode(Encoder&, Gfx::IntPoint const&); |
295 | | template<> |
296 | | ErrorOr<void> encode(Encoder&, Gfx::FloatPoint const&); |
297 | | |
298 | | template<> |
299 | | ErrorOr<Gfx::IntPoint> decode(Decoder&); |
300 | | template<> |
301 | | ErrorOr<Gfx::FloatPoint> decode(Decoder&); |
302 | | |
303 | | } |
304 | | |
305 | | template<typename T> |
306 | | struct AK::Traits<Gfx::Point<T>> : public AK::DefaultTraits<Gfx::Point<T>> { |
307 | 0 | static constexpr bool is_trivial() { return false; }Unexecuted instantiation: AK::Traits<Gfx::Point<int> >::is_trivial() Unexecuted instantiation: AK::Traits<Gfx::Point<float> >::is_trivial() Unexecuted instantiation: AK::Traits<Gfx::Point<unsigned int> >::is_trivial() |
308 | | static unsigned hash(Gfx::Point<T> const& point) |
309 | | { |
310 | | return pair_int_hash(AK::Traits<T>::hash(point.x()), AK::Traits<T>::hash(point.y())); |
311 | | } |
312 | | }; |