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.
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].
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
);
34 * A straight path, no rotation.
36 class LinearMovement
: public Movement
{
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;
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
{
54 double (*m_x
)(double);
55 double (*m_y
)(double);
57 static double linear(double t
) { return t
; }
58 static double nonlinear(double t
);
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;
68 * Movement mixin: apply to a Movement to get a sigmoidal
71 template <typename Mov
>
72 class SigmoidalMovement
: public Mov
{
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
{
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
));