Nirtcpp 2.1.0
Nirtcpp is a high-performance c++ graphics engine.
Loading...
Searching...
No Matches
dimension2d.hpp
1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in nirtcpp/nirtcpp.hpp
4
5#ifndef NIRT_DIMENSION2D_HPP_INCLUDED
6#define NIRT_DIMENSION2D_HPP_INCLUDED
7
8#include <nirtcpp/core/engine/nirt_types.hpp>
9#include <nirtcpp/core/engine/irrMath.hpp> // for nirt::core::equals()
10
11namespace nirt
12{
13namespace core
14{
15 template <class T>
16 class vector2d;
17
19 template <class T>
21 {
22 public:
24 dimension2d() : Width(0), Height(0) {}
26 dimension2d(const T& width, const T& height)
27 : Width(width), Height(height) {}
28
29 dimension2d(const vector2d<T>& other); // Defined in vector2d.h
30
32 template <class U>
35
36 template <class U>
37 dimension2d<T>& operator=(const dimension2d<U>& other)
38 {
39 Width = (T) other.Width;
40 Height = (T) other.Height;
41 return *this;
42 }
43
44
46 bool operator==(const dimension2d<T>& other) const
47 {
48 return core::equals(Width, other.Width) &&
49 core::equals(Height, other.Height);
50 }
51
53 bool operator!=(const dimension2d<T>& other) const
54 {
55 return ! (*this == other);
56 }
57
58 bool operator==(const vector2d<T>& other) const; // Defined in vector2d.h
59
60 bool operator!=(const vector2d<T>& other) const
61 {
62 return !(*this == other);
63 }
64
66 dimension2d<T>& set(const T& width, const T& height)
67 {
68 Width = width;
69 Height = height;
70 return *this;
71 }
72
75 {
76 Width /= scale;
77 Height /= scale;
78 return *this;
79 }
80
82 dimension2d<T> operator/(const T& scale) const
83 {
84 return dimension2d<T>(Width/scale, Height/scale);
85 }
86
89 {
90 Width *= scale;
91 Height *= scale;
92 return *this;
93 }
94
96 dimension2d<T> operator*(const T& scale) const
97 {
98 return dimension2d<T>(Width*scale, Height*scale);
99 }
100
103 {
104 Width += other.Width;
105 Height += other.Height;
106 return *this;
107 }
108
111 {
112 return dimension2d<T>(Width+other.Width, Height+other.Height);
113 }
114
117 {
118 Width -= other.Width;
119 Height -= other.Height;
120 return *this;
121 }
122
125 {
126 return dimension2d<T>(Width-other.Width, Height-other.Height);
127 }
128
130 T getArea() const
131 {
132 return Width*Height;
133 }
134
136
151 bool requirePowerOfTwo=true,
152 bool requireSquare=false,
153 bool larger=true,
154 u32 maxValue = 0) const
155 {
156 u32 i=1;
157 u32 j=1;
159 {
160 while (i<(u32)Width)
161 i<<=1;
162 if (!larger && i!=1 && i!=(u32)Width)
163 i>>=1;
164 while (j<(u32)Height)
165 j<<=1;
166 if (!larger && j!=1 && j!=(u32)Height)
167 j>>=1;
168 }
169 else
170 {
171 i=(u32)Width;
172 j=(u32)Height;
173 }
174
175 if (requireSquare)
176 {
177 if ((larger && (i>j)) || (!larger && (i<j)))
178 j=i;
179 else
180 i=j;
181 }
182
183 if ( maxValue > 0 && i > maxValue)
184 i = maxValue;
185
186 if ( maxValue > 0 && j > maxValue)
187 j = maxValue;
188
189 return dimension2d<T>((T)i,(T)j);
190 }
191
193
197 {
198 f32 inv = (1.0f - d);
199 return dimension2d<T>( (T)(other.Width*inv + Width*d), (T)(other.Height*inv + Height*d));
200 }
201
202
207 };
208
213
215
218
219
220} // end namespace core
221} // end namespace nirt
222
223#endif
224
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.hpp:22
Specifies a 2 dimensional size.
Definition dimension2d.hpp:21
dimension2d< T > operator-(const dimension2d< T > &other) const
Subtract one dimension from another.
Definition dimension2d.hpp:124
dimension2d< T > operator+(const dimension2d< T > &other) const
Add two dimensions.
Definition dimension2d.hpp:110
dimension2d< T > & operator*=(const T &scale)
Multiply width and height by scalar.
Definition dimension2d.hpp:88
dimension2d< T > & operator/=(const T &scale)
Divide width and height by scalar.
Definition dimension2d.hpp:74
T getArea() const
Get area.
Definition dimension2d.hpp:130
dimension2d< T > operator/(const T &scale) const
Divide width and height by scalar.
Definition dimension2d.hpp:82
T Height
Height of the dimension.
Definition dimension2d.hpp:206
bool operator!=(const dimension2d< T > &other) const
Inequality operator.
Definition dimension2d.hpp:53
bool operator==(const dimension2d< T > &other) const
Equality operator.
Definition dimension2d.hpp:46
dimension2d< T > & operator-=(const dimension2d< T > &other)
Subtract a dimension from this one.
Definition dimension2d.hpp:116
dimension2d()
Default constructor for empty dimension.
Definition dimension2d.hpp:24
dimension2d< T > operator*(const T &scale) const
Multiply width and height by scalar.
Definition dimension2d.hpp:96
T Width
Width of the dimension.
Definition dimension2d.hpp:204
dimension2d(const dimension2d< U > &other)
Use this constructor only where you are sure that the conversion is valid.
Definition dimension2d.hpp:33
dimension2d< T > & set(const T &width, const T &height)
Set to new values.
Definition dimension2d.hpp:66
dimension2d< T > & operator+=(const dimension2d< T > &other)
Add another dimension to this one.
Definition dimension2d.hpp:102
dimension2d(const T &width, const T &height)
Constructor with width and height.
Definition dimension2d.hpp:26
dimension2d< T > getOptimalSize(bool requirePowerOfTwo=true, bool requireSquare=false, bool larger=true, u32 maxValue=0) const
Get the optimal size according to some properties.
Definition dimension2d.hpp:150
dimension2d< T > getInterpolated(const dimension2d< T > &other, f32 d) const
Get the interpolated dimension.
Definition dimension2d.hpp:196
bool equals(const T a, const T b, const T tolerance=roundingError< T >())
returns if a equals b, taking possible rounding errors into account
Definition irrMath.hpp:243
As of Nirtcpp 1.6, position2d is a synonym for vector2d.
Definition vector3d.hpp:11
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.hpp:64
float f32
32 bit floating point variable.
Definition irrTypes.hpp:110

Nirtcpp    @cppfx.xyz

Utxcpp    utx::print