Qualia
0.2
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
src
qualia
plugins
bt
FloatCondition.h
Go to the documentation of this file.
1
#include "
Common.h
"
2
#include "
FPCompare.h
"
3
namespace
BehaviorTree
4
{
6
7
enum
FLOAT_TEST
{
LESS_THAN_FP
,
GREATER_THAN_FP
,
LESS_OR_CLOSE
,
GREATER_OR_CLOSE
,
CLOSE
,
NOT_CLOSE
};
8
9
template
<
class
T = NoClass>
11
22
class
FloatCondition
:
public
BehaviorTreeNode
23
{
24
public
:
26
BEHAVIOR_STATUS
execute
(
void
* agent)
27
{
28
float
objVal =
getObjVal
(agent);
29
bool
status;
30
switch
(
test
)
31
{
32
case
LESS_THAN_FP
: status = (objVal <
val
) && !
AlmostEqual2sComplement
(objVal,
val
,
ulps
);
break
;
33
case
GREATER_THAN_FP
: status = (objVal >
val
) && !
AlmostEqual2sComplement
(objVal,
val
,
ulps
);
break
;
34
case
LESS_OR_CLOSE
: status = (objVal <=
val
)||
AlmostEqual2sComplement
(objVal,
val
,
ulps
);
break
;
35
case
GREATER_OR_CLOSE
: status = (objVal >=
val
)||
AlmostEqual2sComplement
(objVal,
val
,
ulps
);
break
;
36
case
CLOSE
: status =
AlmostEqual2sComplement
(objVal,
val
,
ulps
);
break
;
37
case
NOT_CLOSE
: status = !
AlmostEqual2sComplement
(objVal,
val
,
ulps
);
break
;
38
}
39
40
if
(status)
41
return
BT_SUCCESS
;
42
else
43
return
BT_FAILURE
;
44
};
45
46
void
init
(
void
* agent)
47
{
48
};
49
55
FloatCondition
(
float
(T::*
const
_func)()
const
,
FLOAT_TEST
_test,
float
_val,
int
_ulps = 2^22) :
func
(reinterpret_cast<float(T::* const)()>(_func)),
func2
(NULL)
56
{
57
test
= _test;
58
val
= _val;
59
ulps
= _ulps;
60
}
61
67
FloatCondition
(
float
(T::*_func)(),
FLOAT_TEST
_test,
float
_val,
int
_ulps = 2^22):
func
(_func),
func2
(NULL)
68
{
69
test
= _test;
70
val
= _val;
71
ulps
= _ulps;
72
73
}
79
FloatCondition
(
float
(*_func)(),
FLOAT_TEST
_test,
float
_val,
int
_ulps = 2^22) :
func2
(_func),
func
(NULL)
80
{
81
test
= _test;
82
val
= _val;
83
ulps
= _ulps;
84
}
85
86
87
private
:
88
float (T::*
const
func
)();
89
float (*
const
func2
)();
90
FLOAT_TEST
test
;
91
float
val
;
92
int
ulps
;
93
float
getObjVal
(
void
* agent)
94
{
95
T* obj = (T*) agent;
96
return
(obj->*
func
)();
97
}
98
};
99
}
Generated on Fri Oct 11 2013 19:01:21 for Qualia by
1.8.3.1