Irrlicht 3D Engine
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
dimension2d.h
Go to the documentation of this file.
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 irrlicht.h
4
5
#ifndef __IRR_DIMENSION2D_H_INCLUDED__
6
#define __IRR_DIMENSION2D_H_INCLUDED__
7
8
#include "
irrTypes.h
"
9
#include "
irrMath.h
"
// for irr::core::equals()
10
11
namespace
irr
12
{
13
namespace
core
14
{
15
template
<
class
T>
16
class
vector2d;
17
19
template
<
class
T>
20
class
dimension2d
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>
33
explicit
dimension2d
(
const
dimension2d<U>
& other) :
34
Width
((T)other.
Width
),
Height
((T)other.
Height
) { }
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
74
dimension2d<T>
&
operator/=
(
const
T& scale)
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
88
dimension2d<T>
&
operator*=
(
const
T& scale)
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
102
dimension2d<T>
&
operator+=
(
const
dimension2d<T>
& other)
103
{
104
Width
+= other.
Width
;
105
Height
+= other.
Height
;
106
return
*
this
;
107
}
108
110
dimension2d<T>
operator+
(
const
dimension2d<T>
& other)
const
111
{
112
return
dimension2d<T>
(
Width
+other.
Width
,
Height
+other.
Height
);
113
}
114
116
dimension2d<T>
&
operator-=
(
const
dimension2d<T>
& other)
117
{
118
Width
-= other.
Width
;
119
Height
-= other.
Height
;
120
return
*
this
;
121
}
122
124
dimension2d<T>
operator-
(
const
dimension2d<T>
& other)
const
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
150
dimension2d<T>
getOptimalSize
(
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;
158
if
(requirePowerOfTwo)
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
196
dimension2d<T>
getInterpolated
(
const
dimension2d<T>
& other,
f32
d)
const
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
204
T
Width
;
206
T
Height
;
207
};
208
210
typedef
dimension2d<f32>
dimension2df
;
212
typedef
dimension2d<u32>
dimension2du
;
213
215
217
typedef
dimension2d<s32>
dimension2di
;
218
219
220
}
// end namespace core
221
}
// end namespace irr
222
223
#endif
224
Irrlicht Engine
Documentation © 2003-2012 by Nikolaus Gebhardt. Generated on Sat Apr 20 2019 06:56:49 for Irrlicht 3D Engine by
Doxygen
1.8.1.2