-
Notifications
You must be signed in to change notification settings - Fork 2
/
Spline.h
56 lines (43 loc) · 1.13 KB
/
Spline.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once
#include <QPointF>
#include <QVector>
class Spline
{
public:
struct Knot : public QPointF
{
Knot(QPointF pos) :
QPointF(pos)
{}
Knot(qreal x = 0.0f, qreal y = 0.0f) :
QPointF(x, y)
{}
Knot(qreal x, qreal y, float t, float b, float c) :
QPointF(x, y),
t(t),
b(b),
c(c)
{}
float t = 0.0f; // tension
float b = 0.0f; // bias
float c = 0.0f; // continuity
};
Spline();
void add(const Knot &knot);
void insert(int i, const Knot &knot);
void replace(int i, const Knot &knot);
void remove(int i);
int size() const;
const Knot & getKnot(int index) const;
const QVector<Knot> & getKnots() const;
/*
* @return closest knot index or -1 if spline is empty
*/
int findClosest(QPointF pos, qreal & distance) const;
QVector<QPointF> getCurve() const;
static void interpolate(QVector<QPointF> & curve, const QVector<Knot> & knots);
private:
QVector<Knot> knots;
mutable QVector<QPointF> curve;
mutable bool dirty = false;
};