curvedraw

view src/curve.h @ 0:8e524989c904

getting there
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 15 Dec 2015 07:15:53 +0200
parents
children ce7aa9a0594c
line source
1 #ifndef CURVE_H_
2 #define CURVE_H_
4 #include <vector>
5 #include <vmath/vmath.h>
7 enum CurveType {
8 CURVE_LINEAR,
9 CURVE_HERMITE,
10 CURVE_BSPLINE
11 };
13 class Curve {
14 private:
15 std::vector<Vector3> cp;
16 CurveType type;
18 float map_param(float x) const;
20 public:
21 Curve(CurveType type = CURVE_HERMITE);
23 void set_type(CurveType type);
24 CurveType get_type() const;
26 void add_point(const Vector2 &p, float weight = 1.0f);
27 bool remove_point(int idx);
29 int nearest_point(const Vector2 &p);
31 int get_point_count() const;
32 const Vector3 &get_homo_point(int idx) const; // homogeneous point
33 Vector2 get_point(int idx) const;
34 float get_weight(int idx) const;
36 bool set_point(int idx, const Vector2 &p, float weight = 1.0f);
37 bool set_weight(int idx, float weight);
39 Vector2 interpolate(float t, CurveType type) const;
40 Vector2 interpolate(float t) const;
41 Vector2 operator ()(float t) const;
42 };
44 #endif // CURVE_H_