libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
size2d.h
Go to the documentation of this file.
1
8#pragma once
9
11#include <promeki/core/string.h>
12#include <promeki/core/point.h>
13
15
34template<typename T> class Size2DTemplate {
35 public:
37 Size2DTemplate(const T & width = 0, const T & height = 0) : _width(width), _height(height) {}
38
41
43 bool isValid() const {
44 return (_width > 0) && (_height > 0);
45 }
46
48 void set(const T & w, const T & h) {
49 _width = w;
50 _height = h;
51 return;
52 }
53
55 void setWidth(const T & val) {
56 _width = val;
57 return;
58 }
59
61 const T &width() const {
62 return _width;
63 }
64
66 void setHeight(const T & val) {
67 _height = val;
68 return;
69 }
70
72 const T &height() const {
73 return _height;
74 }
75
77 T area() const {
78 return _width * _height;
79 }
80
82 String toString() const {
83 return std::to_string(_width) + "x" + std::to_string(_height);
84 }
85
87 operator String() const {
88 return toString();
89 }
90
92 template <typename N> bool pointIsInside(const Point<N, 2> &p) const {
93 return p.x() >= 0 &&
94 p.x() < _width &&
95 p.y() >= 0 &&
96 p.y() < _height;
97 }
98
99 private:
100 T _width = 0;
101 T _height = 0;
102};
103
112
114
Dynamic array container wrapping std::vector.
Definition list.h:40
Two-dimensional size (width and height).
Definition size2d.h:34
void setHeight(const T &val)
Sets the height.
Definition size2d.h:66
T area() const
Returns the area (width * height).
Definition size2d.h:77
const T & height() const
Returns the height.
Definition size2d.h:72
void set(const T &w, const T &h)
Sets both width and height.
Definition size2d.h:48
const T & width() const
Returns the width.
Definition size2d.h:61
~Size2DTemplate()
Destructor.
Definition size2d.h:40
String toString() const
Returns the size as a string in "WxH" format.
Definition size2d.h:82
Size2DTemplate(const T &width=0, const T &height=0)
Constructs a 2D size with the given width and height, defaulting to 0x0.
Definition size2d.h:37
void setWidth(const T &val)
Sets the width.
Definition size2d.h:55
bool pointIsInside(const Point< N, 2 > &p) const
Returns true if the given 2D point lies within the size bounds.
Definition size2d.h:92
bool isValid() const
Returns true if both width and height are greater than zero.
Definition size2d.h:43
Encoding-aware string class with copy-on-write semantics.
Definition string.h:35
#define PROMEKI_NAMESPACE_BEGIN
Starts a promeki namespace block.
Definition namespace.h:14
#define PROMEKI_NAMESPACE_END
Ends a promeki namespace block.
Definition namespace.h:19