Etterna 0.74.4
Loading...
Searching...
No Matches
CubicSpline.h
1#ifndef CUBIC_SPLINE_H
2#define CUBIC_SPLINE_H
3
4#include <vector>
5using std::vector;
6#include "RageUtil/Misc/RageTypes.h"
7struct lua_State;
8
10{
11 CubicSpline() = default;
12 void solve_looped();
13 void solve_straight();
14 void solve_polygonal();
15 void p_and_tfrac_from_t(float t, bool loop, size_t& p, float& tfrac) const;
16 [[nodiscard]] auto evaluate(float t, bool loop) const -> float;
17 [[nodiscard]] auto evaluate_derivative(float t, bool loop) const -> float;
18 [[nodiscard]] auto evaluate_second_derivative(float t, bool loop) const
19 -> float;
20 [[nodiscard]] auto evaluate_third_derivative(float t, bool loop) const
21 -> float;
22 void set_point(size_t i, float v);
23 void set_coefficients(size_t i, float b, float c, float d);
24 void get_coefficients(size_t i, float& b, float& c, float& d) const;
25 void set_point_and_coefficients(size_t i,
26 float a,
27 float b,
28 float c,
29 float d);
30 void get_point_and_coefficients(size_t i,
31 float& a,
32 float& b,
33 float& c,
34 float& d) const;
35 void resize(size_t s);
36 [[nodiscard]] auto size() const -> size_t;
37 [[nodiscard]] auto empty() const -> bool;
38 float m_spatial_extent{ 0.0F };
39
40 private:
41 auto check_minimum_size() -> bool;
42 void prep_inner(size_t last, std::vector<float>& results);
43 void set_results(size_t last,
44 std::vector<float>& diagonals,
45 std::vector<float>& results);
46
47 struct SplinePoint
48 {
49 float a, b, c, d;
50 };
51 std::vector<SplinePoint> m_points;
52};
53
55{
57
58 = default;
59 static void weighted_average(CubicSplineN& out,
60 const CubicSplineN& from,
61 const CubicSplineN& to,
62 float between);
63 void solve();
64 void evaluate(float t, std::vector<float>& v) const;
65 void evaluate_derivative(float t, std::vector<float>& v) const;
66 void evaluate_second_derivative(float t, std::vector<float>& v) const;
67 void evaluate_third_derivative(float t, std::vector<float>& v) const;
68 void evaluate(float t, RageVector3& v) const;
69 void evaluate_derivative(float t, RageVector3& v) const;
70 void set_point(size_t i, const std::vector<float>& v);
71 void set_coefficients(size_t i,
72 const std::vector<float>& b,
73 const std::vector<float>& c,
74 const std::vector<float>& d);
75 void get_coefficients(size_t i,
76 std::vector<float>& b,
77 std::vector<float>& c,
78 std::vector<float>& d);
79 void set_spatial_extent(size_t i, float extent);
80 auto get_spatial_extent(size_t i) -> float;
81 void resize(size_t s);
82 [[nodiscard]] auto size() const -> size_t;
83 void redimension(size_t d);
84 [[nodiscard]] auto dimension() const -> size_t;
85 [[nodiscard]] auto empty() const -> bool;
86
87 [[nodiscard]] auto get_max_t() const -> float
88 {
89 if (m_loop) {
90 return static_cast<float>(size());
91 }
92 return static_cast<float>(size() - 1);
93 }
94 using spline_cont_t = std::vector<CubicSpline>;
95 void set_loop(bool l);
96 [[nodiscard]] auto get_loop() const -> bool;
97 void set_polygonal(bool p);
98 [[nodiscard]] auto get_polygonal() const -> bool;
99 void set_dirty(bool d);
100 [[nodiscard]] auto get_dirty() const -> bool;
101 bool m_owned_by_actor{ false };
102
103 void PushSelf(lua_State* L);
104
105 private:
106 bool m_loop{ false };
107 bool m_polygonal{ false };
108 bool m_dirty{ true };
109 spline_cont_t m_splines;
110};
111
112#endif
Definition CubicSpline.h:55
Definition CubicSpline.h:10
Definition RageTypes.h:172