1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2 
3 #include "System/float3.h"
4 #include "System/creg/creg_cond.h"
5 #include "System/myMath.h"
6 #include <cmath> // std::min, std::max, std::fabs
7 
8 CR_BIND(float3, )
9 CR_REG_METADATA(float3, (CR_MEMBER(x), CR_MEMBER(y), CR_MEMBER(z)))
10 
11 //! gets initialized later when the map is loaded
12 float float3::maxxpos = -1.0f;
13 float float3::maxzpos = -1.0f;
14 
15 #if (__cplusplus <= 199711L) && !defined(__GXX_EXPERIMENTAL_CXX0X__) && (!defined(__GNUC__) || defined (__clang__))
16 const float float3::CMP_EPS = 1e-4f;
17 const float float3::NORMALIZE_EPS = 1e-12f;
18 #endif
19 
IsInBounds() const20 bool float3::IsInBounds() const
21 {
22 	assert(maxxpos > 0.0f); // check if initialized
23 
24 	return ((x >= 0.0f && x <= maxxpos) && (z >= 0.0f && z <= maxzpos));
25 }
26 
27 
ClampInBounds()28 void float3::ClampInBounds()
29 {
30 	assert(maxxpos > 0.0f); // check if initialized
31 
32 	x = Clamp(x, 0.0f, maxxpos);
33 	z = Clamp(z, 0.0f, maxzpos);
34 }
35 
36 
IsInMap() const37 bool float3::IsInMap() const
38 {
39 	assert(maxxpos > 0.0f); // check if initialized
40 
41 	return ((x >= 0.0f && x <= maxxpos + 1) && (z >= 0.0f && z <= maxzpos + 1));
42 }
43 
44 
ClampInMap()45 void float3::ClampInMap()
46 {
47 	assert(maxxpos > 0.0f); // check if initialized
48 
49 	x = Clamp(x, 0.0f, maxxpos + 1);
50 	z = Clamp(z, 0.0f, maxzpos + 1);
51 }
52 
53 
min(const float3 v1,const float3 v2)54 float3 float3::min(const float3 v1, const float3 v2)
55 {
56 	return float3(std::min(v1.x, v2.x), std::min(v1.y, v2.y), std::min(v1.z, v2.z));
57 }
58 
max(const float3 v1,const float3 v2)59 float3 float3::max(const float3 v1, const float3 v2)
60 {
61 	return float3(std::max(v1.x, v2.x), std::max(v1.y, v2.y), std::max(v1.z, v2.z));
62 }
63 
fabs(const float3 v)64 float3 float3::fabs(const float3 v)
65 {
66 	return float3(std::fabs(v.x), std::fabs(v.y), std::fabs(v.z));
67 }
68 
69