CVB++ 15.0
size_2d.hpp
1#pragma once
2
3#include <cmath>
4
5#include "global.hpp"
6
7namespace Cvb
8{
9
10CVB_BEGIN_INLINE_NS
11
13
18template< class T, class ENABLE = void>
19class Size2D final
20{
21
22#ifndef CVB_DOXYGEN
23 static_assert (IsNumeric<T>::value, "CVB: Unsupported data type - must be numeric!");
24};
25
26
27template <class T>
28class Size2D<T,
29 typename EnableIfNumeric<T>::type> final
30{
31
32#endif
33 public:
34
35 using ValueType = T;
36
38
41 Size2D() noexcept = default;
42
44
49 Size2D(T width, T height) noexcept
50 : width_(width)
51 , height_(height)
52 {
53 }
54
56
60 T Width() const noexcept
61 {
62 return width_;
63 }
64
66
70 void SetWidth(T width) noexcept
71 {
72 width_ = width;
73 }
74
76
80 T Height() const noexcept
81 {
82 return height_;
83 }
84
86
90 void SetHeight(T height) noexcept
91 {
92 height_ = height;
93 }
94
95
97
102 bool operator==(const Size2D<T>& size) const noexcept
103 {
104 return (width_ == size.width_ && height_ == size.height_);
105 }
106
108
113 bool operator!=(const Size2D<T>& size) const noexcept
114 {
115 return !(*this == size);
116 }
117
119 template <class C>
120 explicit operator Size2D<C>() const noexcept
121 {
122 static_assert(std::is_floating_point<C>::value, "CVB: Unsupported data type - must be floating point!");
123 return Size2D<C>(static_cast<C>(Width()), static_cast<C>(Height()));
124 }
125
126 private:
127
128 T width_ = static_cast<T>(0);
129 T height_ = static_cast<T>(0);
130};
131
132
134
141template <class T>
142inline Size2D<int> Round(const Size2D<T> & rhs) noexcept
143{
144 static_assert(IsNumeric<T>::value, "CVB: Unsupported data type - must be numeric!");
145 return Size2D<int>(static_cast<int>(std::round(rhs.Width())), static_cast<int>(std::round(rhs.Height())));
146}
147
148CVB_END_INLINE_NS
149
150}
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:80
bool operator==(const Size2D< T > &size) const noexcept
Compares to an other size.
Definition: size_2d.hpp:102
void SetWidth(T width) noexcept
Sets the horizontal component of the size.
Definition: size_2d.hpp:70
Size2D() noexcept=default
Creates a default, empty size.
void SetHeight(T height) noexcept
Sets the vertical component of the size.
Definition: size_2d.hpp:90
T Width() const noexcept
Gets the horizontal component of the size.
Definition: size_2d.hpp:60
bool operator!=(const Size2D< T > &size) const noexcept
Compares to an other size.
Definition: size_2d.hpp:113
Root namespace for the Image Manager interface.
Definition: c_barcode.h:15
Point2D< int > Round(const Point2D< T > &rhs) noexcept
Round to an integer point.
Definition: point_2d.hpp:382