/src/serenity/Userland/Libraries/LibGfx/Size.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 <LibGfx/Orientation.h> |
11 | | #include <LibGfx/Point.h> |
12 | | #include <LibIPC/Forward.h> |
13 | | |
14 | | namespace Gfx { |
15 | | |
16 | | template<typename T> |
17 | | class Size { |
18 | | public: |
19 | 57.9M | constexpr Size() = default; Line | Count | Source | 19 | 57.9M | constexpr Size() = default; |
Unexecuted instantiation: Gfx::Size<float>::Size() Unexecuted instantiation: Gfx::Size<Web::CSSPixels>::Size() Unexecuted instantiation: Gfx::Size<double>::Size() Unexecuted instantiation: Gfx::Size<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::Size() Gfx::Size<unsigned int>::Size() Line | Count | Source | 19 | 4.32k | constexpr Size() = default; |
|
20 | | |
21 | | constexpr Size(T w, T h) |
22 | 4.18G | : m_width(w) |
23 | 4.18G | , m_height(h) |
24 | 4.18G | { |
25 | 4.18G | } Unexecuted instantiation: Gfx::Size<Web::CSSPixels>::Size(Web::CSSPixels, Web::CSSPixels) Unexecuted instantiation: Gfx::Size<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::Size(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::Size<int>::Size(int, int) Line | Count | Source | 22 | 4.14G | : m_width(w) | 23 | 4.14G | , m_height(h) | 24 | 4.14G | { | 25 | 4.14G | } |
Gfx::Size<float>::Size(float, float) Line | Count | Source | 22 | 5.72M | : m_width(w) | 23 | 5.72M | , m_height(h) | 24 | 5.72M | { | 25 | 5.72M | } |
Unexecuted instantiation: Gfx::Size<double>::Size(double, double) Gfx::Size<unsigned int>::Size(unsigned int, unsigned int) Line | Count | Source | 22 | 28.6M | : m_width(w) | 23 | 28.6M | , m_height(h) | 24 | 28.6M | { | 25 | 28.6M | } |
Gfx::Size<unsigned short>::Size(unsigned short, unsigned short) Line | Count | Source | 22 | 2.14k | : m_width(w) | 23 | 2.14k | , m_height(h) | 24 | 2.14k | { | 25 | 2.14k | } |
Gfx::Size<unsigned char>::Size(unsigned char, unsigned char) Line | Count | Source | 22 | 4.61M | : m_width(w) | 23 | 4.61M | , m_height(h) | 24 | 4.61M | { | 25 | 4.61M | } |
|
26 | | |
27 | | template<typename U> |
28 | | constexpr Size(U width, U height) |
29 | 1.55M | : m_width(width) |
30 | 1.55M | , m_height(height) |
31 | 1.55M | { |
32 | 1.55M | } Unexecuted instantiation: Gfx::Size<Web::CSSPixels>::Size<double>(double, double) Unexecuted instantiation: Gfx::Size<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::Size<double>(double, double) Unexecuted instantiation: Gfx::Size<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::Size<float>(float, float) Unexecuted instantiation: Gfx::Size<Web::CSSPixels>::Size<int>(int, int) Gfx::Size<int>::Size<unsigned int>(unsigned int, unsigned int) Line | Count | Source | 29 | 10.6k | : m_width(width) | 30 | 10.6k | , m_height(height) | 31 | 10.6k | { | 32 | 10.6k | } |
Gfx::Size<int>::Size<unsigned long>(unsigned long, unsigned long) Line | Count | Source | 29 | 1.81k | : m_width(width) | 30 | 1.81k | , m_height(height) | 31 | 1.81k | { | 32 | 1.81k | } |
Gfx::Size<int>::Size<unsigned short>(unsigned short, unsigned short) Line | Count | Source | 29 | 24.0k | : m_width(width) | 30 | 24.0k | , m_height(height) | 31 | 24.0k | { | 32 | 24.0k | } |
Gfx::Size<int>::Size<AK::BigEndian<unsigned short> >(AK::BigEndian<unsigned short>, AK::BigEndian<unsigned short>) Line | Count | Source | 29 | 255 | : m_width(width) | 30 | 255 | , m_height(height) | 31 | 255 | { | 32 | 255 | } |
Unexecuted instantiation: Gfx::Size<int>::Size<AK::BigEndian<unsigned int> >(AK::BigEndian<unsigned int>, AK::BigEndian<unsigned int>) Gfx::Size<unsigned int>::Size<int>(int, int) Line | Count | Source | 29 | 11.4k | : m_width(width) | 30 | 11.4k | , m_height(height) | 31 | 11.4k | { | 32 | 11.4k | } |
Unexecuted instantiation: Gfx::Size<int>::Size<unsigned char>(unsigned char, unsigned char) Gfx::Size<float>::Size<double>(double, double) Line | Count | Source | 29 | 1.50M | : m_width(width) | 30 | 1.50M | , m_height(height) | 31 | 1.50M | { | 32 | 1.50M | } |
Unexecuted instantiation: Gfx::Size<float>::Size<int>(int, int) Gfx::Size<unsigned long>::Size<unsigned int>(unsigned int, unsigned int) Line | Count | Source | 29 | 1.11k | : m_width(width) | 30 | 1.11k | , m_height(height) | 31 | 1.11k | { | 32 | 1.11k | } |
Gfx::Size<unsigned int>::Size<unsigned long>(unsigned long, unsigned long) Line | Count | Source | 29 | 3.19k | : m_width(width) | 30 | 3.19k | , m_height(height) | 31 | 3.19k | { | 32 | 3.19k | } |
Gfx::Size<unsigned short>::Size<int>(int, int) Line | Count | Source | 29 | 2.20k | : m_width(width) | 30 | 2.20k | , m_height(height) | 31 | 2.20k | { | 32 | 2.20k | } |
|
33 | | |
34 | | template<typename U> |
35 | | requires(IsConstructible<T, U>) explicit constexpr Size(Size<U> const& other) |
36 | 4.46k | : m_width(other.width()) |
37 | 4.46k | , m_height(other.height()) |
38 | 4.46k | { |
39 | 4.46k | } Unexecuted instantiation: _ZN3Gfx4SizeIN3Web9CSSPixelsEEC2IfQ15IsConstructibleIT_TL0__EEERKNS0_IS5_EE Unexecuted instantiation: _ZN3Gfx4SizeIN2AK15DistinctNumericIiN3Web18__DevicePixels_tagEJNS1_22DistinctNumericFeature10ArithmeticENS5_16CastToUnderlyingENS5_10ComparisonENS5_9IncrementEEEEEC2IdQ15IsConstructibleIT_TL0__EEERKNS0_ISD_EE Unexecuted instantiation: _ZN3Gfx4SizeIN2AK15DistinctNumericIiN3Web18__DevicePixels_tagEJNS1_22DistinctNumericFeature10ArithmeticENS5_16CastToUnderlyingENS5_10ComparisonENS5_9IncrementEEEEEC2IiQ15IsConstructibleIT_TL0__EEERKNS0_ISD_EE Unexecuted instantiation: _ZN3Gfx4SizeIN3Web9CSSPixelsEEC2IiQ15IsConstructibleIT_TL0__EEERKNS0_IS5_EE _ZN3Gfx4SizeIfEC2IiQ15IsConstructibleIT_TL0__EEERKNS0_IS3_EE Line | Count | Source | 36 | 1.11k | : m_width(other.width()) | 37 | 1.11k | , m_height(other.height()) | 38 | 1.11k | { | 39 | 1.11k | } |
Unexecuted instantiation: _ZN3Gfx4SizeIiEC2IN2AK15DistinctNumericIiN3Web18__DevicePixels_tagEJNS3_22DistinctNumericFeature10ArithmeticENS7_16CastToUnderlyingENS7_10ComparisonENS7_9IncrementEEEEQ15IsConstructibleIT_TL0__EEERKNS0_ISD_EE Unexecuted instantiation: _ZN3Gfx4SizeIiEC2IN3Web9CSSPixelsEQ15IsConstructibleIT_TL0__EEERKNS0_IS5_EE Unexecuted instantiation: _ZN3Gfx4SizeIfEC2IdQ15IsConstructibleIT_TL0__EEERKNS0_IS3_EE Unexecuted instantiation: _ZN3Gfx4SizeIfEC2IN3Web9CSSPixelsEQ15IsConstructibleIT_TL0__EEERKNS0_IS5_EE Unexecuted instantiation: _ZN3Gfx4SizeIdEC2IN3Web9CSSPixelsEQ15IsConstructibleIT_TL0__EEERKNS0_IS5_EE Unexecuted instantiation: _ZN3Gfx4SizeIiEC2IfQ15IsConstructibleIT_TL0__EEERKNS0_IS3_EE _ZN3Gfx4SizeImEC2IjQ15IsConstructibleIT_TL0__EEERKNS0_IS3_EE Line | Count | Source | 36 | 3.35k | : m_width(other.width()) | 37 | 3.35k | , m_height(other.height()) | 38 | 3.35k | { | 39 | 3.35k | } |
|
40 | | |
41 | 7.11G | [[nodiscard]] ALWAYS_INLINE constexpr T width() const { return m_width; }Gfx::Size<int>::width() const Line | Count | Source | 41 | 4.15G | [[nodiscard]] ALWAYS_INLINE constexpr T width() const { return m_width; } |
Gfx::Size<float>::width() const Line | Count | Source | 41 | 105M | [[nodiscard]] ALWAYS_INLINE constexpr T width() const { return m_width; } |
Gfx::Size<unsigned int>::width() const Line | Count | Source | 41 | 2.31G | [[nodiscard]] ALWAYS_INLINE constexpr T width() const { return m_width; } |
Unexecuted instantiation: Gfx::Size<Web::CSSPixels>::width() const Unexecuted instantiation: Gfx::Size<double>::width() const Unexecuted instantiation: Gfx::Size<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::width() const Gfx::Size<unsigned long>::width() const Line | Count | Source | 41 | 496M | [[nodiscard]] ALWAYS_INLINE constexpr T width() const { return m_width; } |
Gfx::Size<unsigned char>::width() const Line | Count | Source | 41 | 48.6M | [[nodiscard]] ALWAYS_INLINE constexpr T width() const { return m_width; } |
Gfx::Size<unsigned short>::width() const Line | Count | Source | 41 | 6.71k | [[nodiscard]] ALWAYS_INLINE constexpr T width() const { return m_width; } |
|
42 | 4.74G | [[nodiscard]] ALWAYS_INLINE constexpr T height() const { return m_height; }Gfx::Size<int>::height() const Line | Count | Source | 42 | 4.59G | [[nodiscard]] ALWAYS_INLINE constexpr T height() const { return m_height; } |
Gfx::Size<float>::height() const Line | Count | Source | 42 | 105M | [[nodiscard]] ALWAYS_INLINE constexpr T height() const { return m_height; } |
Gfx::Size<unsigned int>::height() const Line | Count | Source | 42 | 28.6M | [[nodiscard]] ALWAYS_INLINE constexpr T height() const { return m_height; } |
Unexecuted instantiation: Gfx::Size<Web::CSSPixels>::height() const Unexecuted instantiation: Gfx::Size<double>::height() const Unexecuted instantiation: Gfx::Size<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::height() const Gfx::Size<unsigned long>::height() const Line | Count | Source | 42 | 3.41M | [[nodiscard]] ALWAYS_INLINE constexpr T height() const { return m_height; } |
Gfx::Size<unsigned char>::height() const Line | Count | Source | 42 | 11.6M | [[nodiscard]] ALWAYS_INLINE constexpr T height() const { return m_height; } |
Gfx::Size<unsigned short>::height() const Line | Count | Source | 42 | 6.71k | [[nodiscard]] ALWAYS_INLINE constexpr T height() const { return m_height; } |
|
43 | 2.23k | [[nodiscard]] ALWAYS_INLINE constexpr T area() const { return width() * height(); }Unexecuted instantiation: Gfx::Size<float>::area() const Unexecuted instantiation: Gfx::Size<int>::area() const Gfx::Size<unsigned long>::area() const Line | Count | Source | 43 | 2.23k | [[nodiscard]] ALWAYS_INLINE constexpr T area() const { return width() * height(); } |
|
44 | | |
45 | 24.6M | ALWAYS_INLINE constexpr void set_width(T w) { m_width = w; }Gfx::Size<int>::set_width(int) Line | Count | Source | 45 | 24.6M | ALWAYS_INLINE constexpr void set_width(T w) { m_width = w; } |
Unexecuted instantiation: Gfx::Size<float>::set_width(float) Unexecuted instantiation: Gfx::Size<double>::set_width(double) Unexecuted instantiation: Gfx::Size<Web::CSSPixels>::set_width(Web::CSSPixels) Unexecuted instantiation: Gfx::Size<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::set_width(AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment>) |
46 | 24.6M | ALWAYS_INLINE constexpr void set_height(T h) { m_height = h; }Gfx::Size<int>::set_height(int) Line | Count | Source | 46 | 24.6M | ALWAYS_INLINE constexpr void set_height(T h) { m_height = h; } |
Unexecuted instantiation: Gfx::Size<float>::set_height(float) Unexecuted instantiation: Gfx::Size<double>::set_height(double) Unexecuted instantiation: Gfx::Size<Web::CSSPixels>::set_height(Web::CSSPixels) Unexecuted instantiation: Gfx::Size<AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment> >::set_height(AK::DistinctNumeric<int, Web::__DevicePixels_tag, AK::DistinctNumericFeature::Arithmetic, AK::DistinctNumericFeature::CastToUnderlying, AK::DistinctNumericFeature::Comparison, AK::DistinctNumericFeature::Increment>) |
47 | | |
48 | 1.69M | [[nodiscard]] ALWAYS_INLINE constexpr bool is_empty() const { return m_width <= 0 || m_height <= 0; }Gfx::Size<int>::is_empty() const Line | Count | Source | 48 | 1.69M | [[nodiscard]] ALWAYS_INLINE constexpr bool is_empty() const { return m_width <= 0 || m_height <= 0; } |
Unexecuted instantiation: Gfx::Size<float>::is_empty() const Unexecuted instantiation: Gfx::Size<Web::CSSPixels>::is_empty() const |
49 | | |
50 | | constexpr void scale_by(T dx, T dy) |
51 | 8.25k | { |
52 | 8.25k | m_width *= dx; |
53 | 8.25k | m_height *= dy; |
54 | 8.25k | } Gfx::Size<unsigned int>::scale_by(unsigned int, unsigned int) Line | Count | Source | 51 | 7.70k | { | 52 | 7.70k | m_width *= dx; | 53 | 7.70k | m_height *= dy; | 54 | 7.70k | } |
Unexecuted instantiation: Gfx::Size<int>::scale_by(int, int) Gfx::Size<float>::scale_by(float, float) Line | Count | Source | 51 | 556 | { | 52 | 556 | m_width *= dx; | 53 | 556 | m_height *= dy; | 54 | 556 | } |
Unexecuted instantiation: Gfx::Size<Web::CSSPixels>::scale_by(Web::CSSPixels, Web::CSSPixels) |
55 | | |
56 | 0 | constexpr void transform_by(AffineTransform const& transform) { *this = transform.map(*this); }Unexecuted instantiation: Gfx::Size<int>::transform_by(Gfx::AffineTransform const&) Unexecuted instantiation: Gfx::Size<float>::transform_by(Gfx::AffineTransform const&) |
57 | | |
58 | 8.25k | ALWAYS_INLINE constexpr void scale_by(T dboth) { scale_by(dboth, dboth); }Gfx::Size<unsigned int>::scale_by(unsigned int) Line | Count | Source | 58 | 7.70k | ALWAYS_INLINE constexpr void scale_by(T dboth) { scale_by(dboth, dboth); } |
Unexecuted instantiation: Gfx::Size<int>::scale_by(int) Gfx::Size<float>::scale_by(float) Line | Count | Source | 58 | 556 | ALWAYS_INLINE constexpr void scale_by(T dboth) { scale_by(dboth, dboth); } |
Unexecuted instantiation: Gfx::Size<Web::CSSPixels>::scale_by(Web::CSSPixels) |
59 | 0 | ALWAYS_INLINE constexpr void scale_by(Point<T> const& s) { scale_by(s.x(), s.y()); }Unexecuted instantiation: Gfx::Size<int>::scale_by(Gfx::Point<int> const&) Unexecuted instantiation: Gfx::Size<float>::scale_by(Gfx::Point<float> const&) |
60 | | |
61 | | [[nodiscard]] constexpr Size scaled(T dx, T dy) const |
62 | 0 | { |
63 | 0 | Size<T> size = *this; |
64 | 0 | size.scale_by(dx, dy); |
65 | 0 | return size; |
66 | 0 | } Unexecuted instantiation: Gfx::Size<int>::scaled(int, int) const Unexecuted instantiation: Gfx::Size<float>::scaled(float, float) const |
67 | | |
68 | | [[nodiscard]] constexpr Size scaled(T dboth) const |
69 | 8.25k | { |
70 | 8.25k | Size<T> size = *this; |
71 | 8.25k | size.scale_by(dboth); |
72 | 8.25k | return size; |
73 | 8.25k | } Gfx::Size<unsigned int>::scaled(unsigned int) const Line | Count | Source | 69 | 7.70k | { | 70 | 7.70k | Size<T> size = *this; | 71 | 7.70k | size.scale_by(dboth); | 72 | 7.70k | return size; | 73 | 7.70k | } |
Unexecuted instantiation: Gfx::Size<int>::scaled(int) const Gfx::Size<float>::scaled(float) const Line | Count | Source | 69 | 556 | { | 70 | 556 | Size<T> size = *this; | 71 | 556 | size.scale_by(dboth); | 72 | 556 | return size; | 73 | 556 | } |
Unexecuted instantiation: Gfx::Size<Web::CSSPixels>::scaled(Web::CSSPixels) const |
74 | | |
75 | | [[nodiscard]] constexpr Size scaled(Point<T> const& s) const |
76 | 0 | { |
77 | 0 | Size<T> size = *this; |
78 | 0 | size.scale_by(s); |
79 | 0 | return size; |
80 | 0 | } Unexecuted instantiation: Gfx::Size<int>::scaled(Gfx::Point<int> const&) const Unexecuted instantiation: Gfx::Size<float>::scaled(Gfx::Point<float> const&) const |
81 | | |
82 | | [[nodiscard]] constexpr Size transformed_by(AffineTransform const& transform) const |
83 | 0 | { |
84 | 0 | Size<T> size = *this; |
85 | 0 | size.transform_by(transform); |
86 | 0 | return size; |
87 | 0 | } Unexecuted instantiation: Gfx::Size<int>::transformed_by(Gfx::AffineTransform const&) const Unexecuted instantiation: Gfx::Size<float>::transformed_by(Gfx::AffineTransform const&) const |
88 | | |
89 | | [[nodiscard]] constexpr float aspect_ratio() const |
90 | 0 | { |
91 | 0 | VERIFY(height() != 0); |
92 | 0 | return static_cast<float>(width()) / static_cast<float>(height()); |
93 | 0 | } Unexecuted instantiation: Gfx::Size<int>::aspect_ratio() const Unexecuted instantiation: Gfx::Size<float>::aspect_ratio() const |
94 | | |
95 | | // Horizontal means preserve the width, Vertical means preserve the height. |
96 | | [[nodiscard]] constexpr Size<T> match_aspect_ratio(float aspect_ratio, Orientation side_to_preserve) const |
97 | 0 | { |
98 | 0 | VERIFY(aspect_ratio != 0.0f); |
99 | 0 | auto matched = *this; |
100 | 0 | auto height_corresponding_to_width = static_cast<T>(static_cast<float>(width()) / aspect_ratio); |
101 | 0 | auto width_corresponding_to_height = static_cast<T>(static_cast<float>(height()) * aspect_ratio); |
102 | |
|
103 | 0 | switch (side_to_preserve) { |
104 | 0 | case Orientation::Vertical: |
105 | 0 | matched.m_width = width_corresponding_to_height; |
106 | 0 | break; |
107 | 0 | case Orientation::Horizontal: |
108 | 0 | matched.m_height = height_corresponding_to_width; |
109 | 0 | break; |
110 | 0 | } |
111 | 0 | return matched; |
112 | 0 | } Unexecuted instantiation: Gfx::Size<int>::match_aspect_ratio(float, Gfx::Orientation) const Unexecuted instantiation: Gfx::Size<float>::match_aspect_ratio(float, Gfx::Orientation) const |
113 | | |
114 | | template<typename U> |
115 | | [[nodiscard]] constexpr bool contains(Size<U> const& other) const |
116 | 3.84k | { |
117 | 3.84k | return other.m_width <= m_width && other.m_height <= m_height; |
118 | 3.84k | } |
119 | | |
120 | | template<class U> |
121 | | [[nodiscard]] constexpr bool operator==(Size<U> const& other) const |
122 | 1.14M | { |
123 | 1.14M | return width() == other.width() && height() == other.height(); |
124 | 1.14M | } bool Gfx::Size<int>::operator==<int>(Gfx::Size<int> const&) const Line | Count | Source | 122 | 1.14M | { | 123 | 1.14M | return width() == other.width() && height() == other.height(); | 124 | 1.14M | } |
Unexecuted instantiation: bool Gfx::Size<float>::operator==<int>(Gfx::Size<int> const&) const Unexecuted instantiation: bool Gfx::Size<int>::operator==<float>(Gfx::Size<float> const&) const Unexecuted instantiation: bool Gfx::Size<Web::CSSPixels>::operator==<Web::CSSPixels>(Gfx::Size<Web::CSSPixels> const&) const Unexecuted instantiation: bool Gfx::Size<float>::operator==<float>(Gfx::Size<float> const&) const bool Gfx::Size<unsigned int>::operator==<unsigned int>(Gfx::Size<unsigned int> const&) const Line | Count | Source | 122 | 2.14k | { | 123 | 2.14k | return width() == other.width() && height() == other.height(); | 124 | 2.14k | } |
|
125 | | |
126 | | constexpr Size<T>& operator-=(Size<T> const& other) |
127 | 0 | { |
128 | 0 | m_width -= other.m_width; |
129 | 0 | m_height -= other.m_height; |
130 | 0 | return *this; |
131 | 0 | } Unexecuted instantiation: Gfx::Size<int>::operator-=(Gfx::Size<int> const&) Unexecuted instantiation: Gfx::Size<float>::operator-=(Gfx::Size<float> const&) |
132 | | |
133 | | Size<T>& operator+=(Size<T> const& other) |
134 | 0 | { |
135 | 0 | m_width += other.m_width; |
136 | 0 | m_height += other.m_height; |
137 | 0 | return *this; |
138 | 0 | } Unexecuted instantiation: Gfx::Size<int>::operator+=(Gfx::Size<int> const&) Unexecuted instantiation: Gfx::Size<float>::operator+=(Gfx::Size<float> const&) |
139 | | |
140 | 3.91G | [[nodiscard]] constexpr Size<T> operator*(T factor) const { return { m_width * factor, m_height * factor }; }Gfx::Size<int>::operator*(int) const Line | Count | Source | 140 | 3.91G | [[nodiscard]] constexpr Size<T> operator*(T factor) const { return { m_width * factor, m_height * factor }; } |
Unexecuted instantiation: Gfx::Size<float>::operator*(float) const Unexecuted instantiation: Gfx::Size<double>::operator*(double) const |
141 | | |
142 | | constexpr Size<T>& operator*=(T factor) |
143 | 166 | { |
144 | 166 | m_width *= factor; |
145 | 166 | m_height *= factor; |
146 | 166 | return *this; |
147 | 166 | } Gfx::Size<int>::operator*=(int) Line | Count | Source | 143 | 166 | { | 144 | 166 | m_width *= factor; | 145 | 166 | m_height *= factor; | 146 | 166 | return *this; | 147 | 166 | } |
Unexecuted instantiation: Gfx::Size<float>::operator*=(float) |
148 | | |
149 | 0 | [[nodiscard]] Size<T> operator/(T factor) const { return { m_width / factor, m_height / factor }; }Unexecuted instantiation: Gfx::Size<int>::operator/(int) const Unexecuted instantiation: Gfx::Size<float>::operator/(float) const |
150 | | |
151 | | Size<T>& operator/=(T factor) |
152 | 0 | { |
153 | 0 | m_width /= factor; |
154 | 0 | m_height /= factor; |
155 | 0 | return *this; |
156 | 0 | } Unexecuted instantiation: Gfx::Size<int>::operator/=(int) Unexecuted instantiation: Gfx::Size<float>::operator/=(float) |
157 | | |
158 | | [[nodiscard]] constexpr T primary_size_for_orientation(Orientation orientation) const |
159 | 0 | { |
160 | 0 | return orientation == Orientation::Vertical ? height() : width(); |
161 | 0 | } Unexecuted instantiation: Gfx::Size<int>::primary_size_for_orientation(Gfx::Orientation) const Unexecuted instantiation: Gfx::Size<float>::primary_size_for_orientation(Gfx::Orientation) const |
162 | | |
163 | | constexpr void set_primary_size_for_orientation(Orientation orientation, T value) |
164 | 0 | { |
165 | 0 | if (orientation == Orientation::Vertical) { |
166 | 0 | set_height(value); |
167 | 0 | } else { |
168 | 0 | set_width(value); |
169 | 0 | } |
170 | 0 | } Unexecuted instantiation: Gfx::Size<int>::set_primary_size_for_orientation(Gfx::Orientation, int) Unexecuted instantiation: Gfx::Size<float>::set_primary_size_for_orientation(Gfx::Orientation, float) |
171 | | |
172 | | [[nodiscard]] constexpr T secondary_size_for_orientation(Orientation orientation) const |
173 | 0 | { |
174 | 0 | return orientation == Orientation::Vertical ? width() : height(); |
175 | 0 | } Unexecuted instantiation: Gfx::Size<int>::secondary_size_for_orientation(Gfx::Orientation) const Unexecuted instantiation: Gfx::Size<float>::secondary_size_for_orientation(Gfx::Orientation) const |
176 | | |
177 | | constexpr void set_secondary_size_for_orientation(Orientation orientation, T value) |
178 | 0 | { |
179 | 0 | if (orientation == Orientation::Vertical) { |
180 | 0 | set_width(value); |
181 | 0 | } else { |
182 | 0 | set_height(value); |
183 | 0 | } |
184 | 0 | } Unexecuted instantiation: Gfx::Size<int>::set_secondary_size_for_orientation(Gfx::Orientation, int) Unexecuted instantiation: Gfx::Size<float>::set_secondary_size_for_orientation(Gfx::Orientation, float) |
185 | | |
186 | | template<typename U> |
187 | | requires(!IsSame<T, U>) |
188 | | [[nodiscard]] ALWAYS_INLINE constexpr Size<U> to_type() const |
189 | 3.35k | { |
190 | 3.35k | return Size<U>(*this); |
191 | 3.35k | } Unexecuted instantiation: _ZNK3Gfx4SizeIN2AK15DistinctNumericIiN3Web18__DevicePixels_tagEJNS1_22DistinctNumericFeature10ArithmeticENS5_16CastToUnderlyingENS5_10ComparisonENS5_9IncrementEEEEE7to_typeIiQnt6IsSameIT_TL0__EEENS0_ISD_EEv Unexecuted instantiation: _ZNK3Gfx4SizeIN3Web9CSSPixelsEE7to_typeIiQnt6IsSameIT_TL0__EEENS0_IS5_EEv Unexecuted instantiation: _ZNK3Gfx4SizeIN3Web9CSSPixelsEE7to_typeIdQnt6IsSameIT_TL0__EEENS0_IS5_EEv Unexecuted instantiation: _ZNK3Gfx4SizeIN3Web9CSSPixelsEE7to_typeIfQnt6IsSameIT_TL0__EEENS0_IS5_EEv Unexecuted instantiation: _ZNK3Gfx4SizeIiE7to_typeIN3Web9CSSPixelsEQnt6IsSameIT_TL0__EEENS0_IS5_EEv _ZNK3Gfx4SizeIjE7to_typeImQnt6IsSameIT_TL0__EEENS0_IS3_EEv Line | Count | Source | 189 | 3.35k | { | 190 | 3.35k | return Size<U>(*this); | 191 | 3.35k | } |
|
192 | | |
193 | | [[nodiscard]] ByteString to_byte_string() const; |
194 | | |
195 | | template<Integral I> |
196 | | [[nodiscard]] Size<I> to_rounded() const |
197 | | { |
198 | | return Size<I>(round_to<I>(width()), round_to<I>(height())); |
199 | | } |
200 | | |
201 | | private: |
202 | | T m_width { 0 }; |
203 | | T m_height { 0 }; |
204 | | }; |
205 | | |
206 | | using IntSize = Size<int>; |
207 | | using FloatSize = Size<float>; |
208 | | |
209 | | } |
210 | | |
211 | | namespace AK { |
212 | | |
213 | | template<typename T> |
214 | | struct Formatter<Gfx::Size<T>> : Formatter<FormatString> { |
215 | | ErrorOr<void> format(FormatBuilder& builder, Gfx::Size<T> const& value) |
216 | 0 | { |
217 | 0 | return Formatter<FormatString>::format(builder, "[{}x{}]"sv, value.width(), value.height()); |
218 | 0 | } |
219 | | }; |
220 | | |
221 | | } |
222 | | |
223 | | namespace IPC { |
224 | | |
225 | | template<> |
226 | | ErrorOr<void> encode(Encoder&, Gfx::IntSize const&); |
227 | | |
228 | | template<> |
229 | | ErrorOr<Gfx::IntSize> decode(Decoder&); |
230 | | |
231 | | } |
232 | | |
233 | | template<typename T> |
234 | | struct AK::Traits<Gfx::Size<T>> : public AK::DefaultTraits<Gfx::Size<T>> { |
235 | | static constexpr bool is_trivial() { return false; } |
236 | | static unsigned hash(Gfx::Size<T> const& size) |
237 | 0 | { |
238 | 0 | return pair_int_hash(AK::Traits<T>::hash(size.width()), AK::Traits<T>::hash(size.height())); |
239 | 0 | } |
240 | | }; |