Skip to content

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 properties x and y.
  • Position is the output type.
  • The expression event_to_position(event, x, y), where event is an Event object and x and y are floats, must be valid and return a Position object.
  • The expression handle_position(position), where position is a Position object, must be valid.
  • x and y are the initial averaged coordinates.
  • inertia must be in the range [0, 1]. The mean position's coordinates are updated with the rule new_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
    });
Clone this wiki locally