CVB++ 14.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
37
40 Size2D() noexcept = default;
41
43
48 Size2D(T width, T height) noexcept
49 : width_(width)
50 , height_(height)
51 {
52 }
53
55
59 T Width() const noexcept
60 {
61 return width_;
62 }
63
65
69 void SetWidth(T width) noexcept
70 {
71 width_ = width;
72 }
73
75
79 T Height() const noexcept
80 {
81 return height_;
82 }
83
85
89 void SetHeight(T height) noexcept
90 {
91 height_ = height;
92 }
93
94
96
101 bool operator==(const Size2D<T>& size) const noexcept
102 {
103 return (width_ == size.width_ && height_ == size.height_);
104 }
105
107
112 bool operator!=(const Size2D<T>& size) const noexcept
113 {
114 return !(*this == size);
115 }
116
118 template <class C>
119 explicit operator Size2D<C>() const noexcept
120 {
121 static_assert(std::is_floating_point<C>::value, "CVB: Unsupported data type - must be floating point!");
122 return Size2D<C>(static_cast<C>(std::round(Width())), static_cast<C>(std::round(Height())));
123 }
124
125 private:
126
127 T width_ = static_cast<T>(0);
128 T height_ = static_cast<T>(0);
129};
130
131
133
140template <class T>
141inline Size2D<int> Round(const Size2D<T> & rhs) noexcept
142{
143 static_assert(IsNumeric<T>::value, "CVB: Unsupported data type - must be numeric!");
144 return Size2D<int>(static_cast<int>(std::round(rhs.Width())), static_cast<int>(std::round(rhs.Height())));
145}
146
147CVB_END_INLINE_NS
148
149}
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:79
bool operator==(const Size2D< T > &size) const noexcept
Compares to an other size.
Definition: size_2d.hpp:101
void SetWidth(T width) noexcept
Sets the horizontal component of the size.
Definition: size_2d.hpp:69
Size2D() noexcept=default
Creates a default, empty size.
void SetHeight(T height) noexcept
Sets the vertical component of the size.
Definition: size_2d.hpp:89
T Width() const noexcept
Gets the horizontal component of the size.
Definition: size_2d.hpp:59
bool operator!=(const Size2D< T > &size) const noexcept
Compares to an other size.
Definition: size_2d.hpp:112
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24
Point2D< int > Round(const Point2D< T > &rhs) noexcept
Round to an integer point.
Definition: point_2d.hpp:380