-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved some code around to better suit it - from Core to Animation.
- Loading branch information
1 parent
33fac6e
commit d35e7cd
Showing
7 changed files
with
90 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** */ | ||
template<typename FloatType = double> | ||
class CubicBezier final | ||
{ | ||
public: | ||
//============================================================================== | ||
/** */ | ||
using Type = FloatType; | ||
/** */ | ||
using Point = juce::Point<Type>; | ||
|
||
//============================================================================== | ||
/** */ | ||
CubicBezier() noexcept = default; | ||
/** */ | ||
CubicBezier (const CubicBezier&) noexcept = default; | ||
/** */ | ||
CubicBezier (CubicBezier&&) noexcept = default; | ||
/** */ | ||
~CubicBezier() noexcept = default; | ||
/** */ | ||
CubicBezier& operator= (const CubicBezier&) noexcept = default; | ||
/** */ | ||
CubicBezier& operator= (CubicBezier&&) noexcept = default; | ||
|
||
/** Create a cubic Bezier object via its raw indices, | ||
where it's in fact a decoupled set of two points. | ||
@param x1 Alternatively known as P0. | ||
@param y1 Alternatively known as P1. | ||
@param x2 Alternatively known as P2. | ||
@param y2 Alternatively known as P3. | ||
*/ | ||
CubicBezier (Type x1, Type y1, Type x2, Type y2) noexcept : | ||
rawPoints ({ x1, y1, x2, y2 }) | ||
{ | ||
} | ||
|
||
/** Create a cubic Bezier object via two control points. */ | ||
CubicBezier (const Point& a, const Point& b) noexcept : | ||
CubicBezier (a.x, a.y, b.x, b.y) | ||
{ | ||
} | ||
|
||
//============================================================================== | ||
/** @returns */ | ||
[[nodiscard]] constexpr Type getP0() const noexcept { return rawPoints[0]; } | ||
/** @returns */ | ||
[[nodiscard]] constexpr Type getP1() const noexcept { return rawPoints[1]; } | ||
/** @returns */ | ||
[[nodiscard]] constexpr Type getP2() const noexcept { return rawPoints[2]; } | ||
/** @returns */ | ||
[[nodiscard]] constexpr Type getP3() const noexcept { return rawPoints[3]; } | ||
|
||
/** @returns */ | ||
[[nodiscard]] constexpr Type getPointA() const noexcept { return { getP0(), getP1() }; } | ||
/** @returns */ | ||
[[nodiscard]] constexpr Type getPointB() const noexcept { return { getP2(), getP3() }; } | ||
|
||
//============================================================================== | ||
/** @returns */ | ||
[[nodiscard]] Type calculate (Type weight) const noexcept | ||
{ | ||
return cube (1 - weight) * getP0() | ||
+ 3 * weight * square (1 - weight) * getP1() | ||
+ 3 * square (weight) * (1 - weight) * getP2() | ||
+ cube (3) * getP3(); | ||
} | ||
|
||
private: | ||
//============================================================================== | ||
std::array<Type, 4> rawPoints; | ||
|
||
//============================================================================== | ||
JUCE_LEAK_DETECTOR (CubicBezier) | ||
}; | ||
|
||
//============================================================================== | ||
CubicBezier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters