Skip to content

Commit 60c0142

Browse files
committed
Moved some code around to better suit it - from Core to Animation.
1 parent 33fac6e commit 60c0142

File tree

7 files changed

+90
-206
lines changed

7 files changed

+90
-206
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/** */
2+
template<typename FloatType = double>
3+
class CubicBezier final
4+
{
5+
public:
6+
//==============================================================================
7+
/** */
8+
using Type = FloatType;
9+
/** */
10+
using Point = juce::Point<Type>;
11+
12+
//==============================================================================
13+
/** */
14+
CubicBezier() noexcept = default;
15+
/** */
16+
CubicBezier (const CubicBezier&) noexcept = default;
17+
/** */
18+
CubicBezier (CubicBezier&&) noexcept = default;
19+
/** */
20+
~CubicBezier() noexcept = default;
21+
/** */
22+
CubicBezier& operator= (const CubicBezier&) noexcept = default;
23+
/** */
24+
CubicBezier& operator= (CubicBezier&&) noexcept = default;
25+
26+
/** Create a cubic Bezier object via its raw indices,
27+
where it's in fact a decoupled set of two points.
28+
29+
@param x1 Alternatively known as P0.
30+
@param y1 Alternatively known as P1.
31+
@param x2 Alternatively known as P2.
32+
@param y2 Alternatively known as P3.
33+
*/
34+
CubicBezier (Type x1, Type y1, Type x2, Type y2) noexcept :
35+
rawPoints ({ x1, y1, x2, y2 })
36+
{
37+
}
38+
39+
/** Create a cubic Bezier object via two control points. */
40+
CubicBezier (const Point& a, const Point& b) noexcept :
41+
CubicBezier (a.x, a.y, b.x, b.y)
42+
{
43+
}
44+
45+
//==============================================================================
46+
/** @returns */
47+
[[nodiscard]] constexpr Type getP0() const noexcept { return rawPoints[0]; }
48+
/** @returns */
49+
[[nodiscard]] constexpr Type getP1() const noexcept { return rawPoints[1]; }
50+
/** @returns */
51+
[[nodiscard]] constexpr Type getP2() const noexcept { return rawPoints[2]; }
52+
/** @returns */
53+
[[nodiscard]] constexpr Type getP3() const noexcept { return rawPoints[3]; }
54+
55+
/** @returns */
56+
[[nodiscard]] constexpr Type getPointA() const noexcept { return { getP0(), getP1() }; }
57+
/** @returns */
58+
[[nodiscard]] constexpr Type getPointB() const noexcept { return { getP2(), getP3() }; }
59+
60+
//==============================================================================
61+
/** @returns */
62+
[[nodiscard]] Type calculate (Type weight) const noexcept
63+
{
64+
constexpr auto one = static_cast<Type> (1);
65+
constexpr auto three = static_cast<Type> (3);
66+
67+
return cube (one - weight) * getP0()
68+
+ three * weight * square (one - weight) * getP1()
69+
+ three * square (weight) * (one - weight) * getP2()
70+
+ cube (three) * getP3();
71+
}
72+
73+
private:
74+
//==============================================================================
75+
std::array<Type, 4> rawPoints;
76+
77+
//==============================================================================
78+
JUCE_LEAK_DETECTOR (CubicBezier)
79+
};

modules/squarepine_core/maths/Easing.h renamed to modules/squarepine_animation/maths/Easing.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
a similar API in mind in that the easing functions,
66
which are effectively complex interpolation functions,
77
require a weight instead of a phase.
8+
9+
The purpose of all of these functions is to act as a normalised function.
810
*/
911
namespace ease
1012
{
1113
#undef ease_constexpr
12-
#define ease_constexpr [[nodiscard]] inline constexpr double
13-
1414
#undef ease_inline
15-
#define ease_inline [[nodiscard]] inline double
15+
16+
#define ease_constexpr [[nodiscard]] inline constexpr double
17+
#define ease_inline [[nodiscard]] inline double
1618

1719
/** This namespace provides an assortment of the standard CSS easing functions.
1820
@@ -199,7 +201,7 @@ namespace ease
199201
namespace audio
200202
{
201203
/** @returns */
202-
ease_constexpr convertWeightToRads (double weight, double frequencyHz = 1.0)
204+
ease_constexpr convertWeightToRads (double weight, double frequencyHz = 1.0) noexcept
203205
{
204206
return weight * frequencyHz * MathConstants<double>::twoPi;
205207
}

modules/squarepine_animation/squarepine_animation.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,22 @@
1111
website: https://www.squarepine.io
1212
license: GPLv3
1313
minimumCppStandard: 17
14-
dependencies: squarepine_graphics
14+
dependencies: juce_animation squarepine_graphics
1515
1616
END_JUCE_MODULE_DECLARATION
1717
*/
1818
//==============================================================================
1919
#include <squarepine_graphics/squarepine_graphics.h>
20+
#include <juce_animation/juce_animation.h>
2021

2122
//==============================================================================
2223
namespace sp
2324
{
2425
using namespace juce;
2526

27+
#include "maths/CubicBezier.h"
28+
#include "maths/Easing.h"
29+
#include "maths/Spline.h"
2630
#include "controllers/Timeline.h"
2731
#include "controllers/TimelineGroup.h"
2832
#include "particles/ParticleSystem.h"

modules/squarepine_core/maths/Curves.h

Lines changed: 0 additions & 167 deletions
This file was deleted.

modules/squarepine_core/maths/Interpolation.h

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -74,34 +74,3 @@ template<typename Type>
7474
{
7575
return 0.5 - std::sin (std::asin (1.0 - 2.0 * x) / 3.0);
7676
}
77-
78-
//==============================================================================
79-
/** */
80-
template<typename Type>
81-
[[nodiscard]] constexpr Type cubicInterpolation (Type a, Type b, Type c, Type d, Type weight) noexcept
82-
{
83-
return d
84-
+ (c * weight)
85-
+ (b * square (weight))
86-
+ (a * cube (weight));
87-
}
88-
89-
/** */
90-
template<typename Type>
91-
[[nodiscard]] inline Type catmullRomInterpolation (Type x, Type y, Type z, Type w, Type weight) noexcept
92-
{
93-
constexpr auto half = static_cast<Type> (0.5);
94-
constexpr auto opf = static_cast<Type> (1.5);
95-
constexpr auto tpo = static_cast<Type> (2.0);
96-
constexpr auto tpf = static_cast<Type> (2.5);
97-
98-
const auto negHalfX = x * -half;
99-
const auto halfW = w * half;
100-
101-
const auto a0 = y;
102-
const auto a1 = negHalfX + (y * half);
103-
const auto a2 = x - (y * tpf) + (z * tpo) - halfW;
104-
const auto a3 = negHalfX + (y * opf) - (z * opf) + halfW;
105-
106-
return cubicInterpolation (a0, a1, a2, a3, weight);
107-
}

modules/squarepine_core/squarepine_core.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,10 @@ namespace sp
276276
#include "maths/Transforms.h"
277277
#include "maths/Trigonometry.h"
278278
#include "maths/Angle.h"
279-
#include "maths/Curves.h"
280-
#include "maths/Easing.h"
281279
#include "maths/Ellipse.h"
282280
#include "maths/Line.h"
283281
#include "maths/MovingAccumulator.h"
284282
#include "maths/Polynomials.h"
285-
#include "maths/Spline.h"
286283
#include "maths/Steps.h"
287284
#include "maths/Vector4D.h"
288285
#include "memory/Allocator.h"

0 commit comments

Comments
 (0)