-
Notifications
You must be signed in to change notification settings - Fork 6
average_position
Alexandre Marcireau edited this page May 31, 2018
·
5 revisions
In header "../third_party/tarsier/source/average_position.hpp"
tarsier::average_position
calculates the average position of the given events. An exponential event-wise decay is used as weight.
namespace tarsier {
template <typename Event, typename Position, typename EventToPosition, typename HandlePosition>
class average_position {
public:
average_position(
float x,
float y,
float inertia,
EventToPosition event_to_position,
HandlePosition handle_position);
/// operator() handles an event.
virtual void operator()(Event event);
};
}
-
Event
is the input type. It must have at least the propertiesx
andy
. -
Position
is the output type. - The expression
event_to_position(event, x, y)
, whereevent
is anEvent
object andx
andy
are floats, must be valid and return aPosition
object. - The expression
handle_position(position)
, whereposition
is aPosition
object, must be valid. -
x
andy
are the initial averaged coordinates. -
inertia
must be in the range[0, 1]
. The mean position's coordinates are updated with the rulenew_coordinate = inertia * old_coordinate + (1 - inertia) * event_coordinate
.
Event
and Position
must be specified when using make_average_position
:
struct event {
uint16_t x;
uint16_t y;
};
struct position {
float x;
float y;
};
auto average_position = tarsier::make_average_position<event, position>(
160,
120,
0.9,
[](event event, float x, float y) -> position {
return {x, y};
},
[](position position) {
// do something with position
});