CVB++ 15.0
size_2d.hpp
1#pragma once
2
3#include <cmath>
4
5#include "global.hpp"
6
7namespace Cvb
8{
9
10 CVB_BEGIN_INLINE_NS
11
13
18 template <class T, class ENABLE = void>
19 class Size2D final
20 {
21
22#ifndef CVB_DOXYGEN
23 static_assert(IsNumeric<T>::value, "CVB: Unsupported data type - must be numeric!");
24 };
25
26 template <class T>
27 class Size2D<T, typename EnableIfNumeric<T>::type> final
28 {
29
30#endif
31 public:
32 using ValueType = T;
33
35
38 Size2D() noexcept = default;
39
41
46 Size2D(T width, T height) noexcept
47 : width_(width)
48 , height_(height)
49 {
50 }
51
53
57 T Width() const noexcept
58 {
59 return width_;
60 }
61
63
67 void SetWidth(T width) noexcept
68 {
69 width_ = width;
70 }
71
73
77 T Height() const noexcept
78 {
79 return height_;
80 }
81
83
87 void SetHeight(T height) noexcept
88 {
89 height_ = height;
90 }
91
93
98 bool operator==(const Size2D<T> &size) const noexcept
99 {
100 return (width_ == size.width_ && height_ == size.height_);
101 }
102
104
109 bool operator!=(const Size2D<T> &size) const noexcept
110 {
111 return !(*this == size);
112 }
113
115 template <class C>
116 explicit operator Size2D<C>() const noexcept
117 {
118 static_assert(std::is_floating_point<C>::value, "CVB: Unsupported data type - must be floating point!");
119 return Size2D<C>(static_cast<C>(Width()), static_cast<C>(Height()));
120 }
121
122 private:
123 T width_ = static_cast<T>(0);
124 T height_ = static_cast<T>(0);
125 };
126
128
135 template <class T>
136 inline Size2D<int> Round(const Size2D<T> &rhs) noexcept
137 {
138 static_assert(IsNumeric<T>::value, "CVB: Unsupported data type - must be numeric!");
139 return Size2D<int>(static_cast<int>(std::round(rhs.Width())), static_cast<int>(std::round(rhs.Height())));
140 }
141
142 CVB_END_INLINE_NS
143
144} // namespace Cvb
Stores a pair of numbers that represents the width and the height of a subject, typically a rectangle...
Definition size_2d.hpp:20
T Height() const noexcept
Gets the vertical component of the size.
Definition size_2d.hpp:77
bool operator==(const Size2D< T > &size) const noexcept
Compares to an other size.
Definition size_2d.hpp:98
void SetWidth(T width) noexcept
Sets the horizontal component of the size.
Definition size_2d.hpp:67
Size2D() noexcept=default
Creates a default, empty size.
void SetHeight(T height) noexcept
Sets the vertical component of the size.
Definition size_2d.hpp:87
T Width() const noexcept
Gets the horizontal component of the size.
Definition size_2d.hpp:57
bool operator!=(const Size2D< T > &size) const noexcept
Compares to an other size.
Definition size_2d.hpp:109
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
Point2D< int > Round(const Point2D< T > &rhs) noexcept
Round to an integer point.
Definition point_2d.hpp:371
T round(T... args)