Add more assertions.
[tagua/yd.git] / src / movement.h
blob4817294f63703d6383408620d14b4fcc824f0f52
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #ifndef MOVEMENT_H
12 #define MOVEMENT_H
14 #include <QPoint>
15 #include <iostream>
17 /**
18 * Abstract class representing a parameterization of a curve
19 * in a plane and a rotation angle.
20 * The parameter @a t for both the position and the rotation
21 * is assumed to lie in the closed interval [0,1].
23 class Movement {
24 public:
25 virtual ~Movement() { }
26 virtual QPoint pos(double t) const = 0;
27 virtual double rotation(double /*t*/) const { return 0.0; }
29 static double sigmoid(double t);
30 static double half_sigmoid(double t);
33 /**
34 * A straight path, no rotation.
36 class LinearMovement : public Movement {
37 QPoint m_from;
38 QPoint m_velocity;
39 public:
40 /// create a path from @a from to @a to.
41 LinearMovement(const QPoint& from, const QPoint& to, bool /*rotate*/);
43 virtual QPoint pos(double t) const;
46 /**
47 * An L-shaped path. First along the shortest side, then along the other.
48 * Use an exponential parameterization for the longest side.
50 class LMovement : public Movement {
51 QPoint m_from;
52 QPoint m_velocity;
53 bool m_rotate;
54 double (*m_x)(double);
55 double (*m_y)(double);
57 static double linear(double t) { return t; }
58 static double nonlinear(double t);
59 public:
60 /// create an L-path from @a from to @a to.
61 LMovement(const QPoint& from, const QPoint& to, bool rotate = false);
63 virtual QPoint pos(double t) const;
64 virtual double rotation(double t) const;
67 /**
68 * Movement mixin: apply to a Movement to get a sigmoidal
69 * variant of it.
71 template <typename Mov>
72 class SigmoidalMovement : public Mov {
73 public:
74 SigmoidalMovement(const QPoint& from, const QPoint& to, bool rotate = false)
75 : Mov(from, to, rotate) { }
77 virtual QPoint pos(double t) const {
78 return Mov::pos(Movement::sigmoid(t));
82 template <typename Mov>
83 class HalfSigmoidalMovement : public Mov {
84 public:
85 HalfSigmoidalMovement(const QPoint& from, const QPoint& to, bool rotate = false)
86 : Mov(from, to, rotate) { }
88 virtual QPoint pos(double t) const {
89 return Mov::pos(Movement::half_sigmoid(t));
93 #endif // MOVEMENT_H