[core] UnitBezier ctor is now constexpr
This commit is contained in:
@@ -31,32 +31,31 @@ namespace mbgl {
|
||||
namespace util {
|
||||
|
||||
struct UnitBezier {
|
||||
UnitBezier(double p1x, double p1y, double p2x, double p2y) {
|
||||
// Calculate the polynomial coefficients, implicit first and last control points are (0,0) and (1,1).
|
||||
cx = 3.0 * p1x;
|
||||
bx = 3.0 * (p2x - p1x) - cx;
|
||||
ax = 1.0 - cx - bx;
|
||||
|
||||
cy = 3.0 * p1y;
|
||||
by = 3.0 * (p2y - p1y) - cy;
|
||||
ay = 1.0 - cy - by;
|
||||
// Calculate the polynomial coefficients, implicit first and last control points are (0,0) and (1,1).
|
||||
constexpr UnitBezier(double p1x, double p1y, double p2x, double p2y)
|
||||
: cx(3.0 * p1x)
|
||||
, bx(3.0 * (p2x - p1x) - cx)
|
||||
, ax(1.0 - cx - bx)
|
||||
, cy(3.0 * p1y)
|
||||
, by(3.0 * (p2y - p1y) - cy)
|
||||
, ay(1.0 - cy - by) {
|
||||
}
|
||||
|
||||
double sampleCurveX(double t) {
|
||||
double sampleCurveX(double t) const {
|
||||
// `ax t^3 + bx t^2 + cx t' expanded using Horner's rule.
|
||||
return ((ax * t + bx) * t + cx) * t;
|
||||
}
|
||||
|
||||
double sampleCurveY(double t) {
|
||||
double sampleCurveY(double t) const {
|
||||
return ((ay * t + by) * t + cy) * t;
|
||||
}
|
||||
|
||||
double sampleCurveDerivativeX(double t) {
|
||||
double sampleCurveDerivativeX(double t) const {
|
||||
return (3.0 * ax * t + 2.0 * bx) * t + cx;
|
||||
}
|
||||
|
||||
// Given an x value, find a parametric value it came from.
|
||||
double solveCurveX(double x, double epsilon) {
|
||||
double solveCurveX(double x, double epsilon) const {
|
||||
double t0;
|
||||
double t1;
|
||||
double t2;
|
||||
@@ -100,18 +99,18 @@ struct UnitBezier {
|
||||
return t2;
|
||||
}
|
||||
|
||||
double solve(double x, double epsilon) {
|
||||
double solve(double x, double epsilon) const {
|
||||
return sampleCurveY(solveCurveX(x, epsilon));
|
||||
}
|
||||
|
||||
private:
|
||||
double ax;
|
||||
double bx;
|
||||
double cx;
|
||||
const double cx;
|
||||
const double bx;
|
||||
const double ax;
|
||||
|
||||
double ay;
|
||||
double by;
|
||||
double cy;
|
||||
const double cy;
|
||||
const double by;
|
||||
const double ay;
|
||||
};
|
||||
|
||||
} // namespace util
|
||||
|
||||
@@ -889,7 +889,7 @@ void nativeSetVisibleCoordinateBounds(JNIEnv *env, jni::jobject* obj, jlong nati
|
||||
if (duration > 0) {
|
||||
animationOptions.duration.emplace(mbgl::Milliseconds(duration));
|
||||
// equivalent to kCAMediaTimingFunctionDefault in iOS
|
||||
animationOptions.easing = mbgl::util::UnitBezier(0.25, 0.1, 0.25, 0.1);
|
||||
animationOptions.easing.emplace(mbgl::util::UnitBezier { 0.25, 0.1, 0.25, 0.1 });
|
||||
}
|
||||
|
||||
nativeMapView->getMap().easeTo(cameraOptions, animationOptions);
|
||||
@@ -1054,7 +1054,7 @@ void nativeEaseTo(JNIEnv *env, jni::jobject* obj, jlong nativeMapViewPtr, jdoubl
|
||||
|
||||
if (!easing) {
|
||||
// add a linear interpolator instead of easing
|
||||
animationOptions.easing = mbgl::util::UnitBezier(0, 0, 1, 1);
|
||||
animationOptions.easing.emplace(mbgl::util::UnitBezier { 0, 0, 1, 1 });
|
||||
}
|
||||
|
||||
nativeMapView->getMap().easeTo(cameraOptions, animationOptions);
|
||||
|
||||
@@ -2196,8 +2196,8 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
|
||||
mbgl::AnimationOptions animationOptions;
|
||||
if (duration)
|
||||
{
|
||||
animationOptions.duration = MGLDurationInSeconds(duration);
|
||||
animationOptions.easing = MGLUnitBezierForMediaTimingFunction(function);
|
||||
animationOptions.duration.emplace(MGLDurationInSeconds(duration));
|
||||
animationOptions.easing.emplace(MGLUnitBezierForMediaTimingFunction(function));
|
||||
}
|
||||
if (completion)
|
||||
{
|
||||
@@ -2349,8 +2349,8 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
|
||||
mbgl::AnimationOptions animationOptions;
|
||||
if (duration > 0)
|
||||
{
|
||||
animationOptions.duration = MGLDurationInSeconds(duration);
|
||||
animationOptions.easing = MGLUnitBezierForMediaTimingFunction(function);
|
||||
animationOptions.duration.emplace(MGLDurationInSeconds(duration));
|
||||
animationOptions.easing.emplace(MGLUnitBezierForMediaTimingFunction(function));
|
||||
}
|
||||
if (completion)
|
||||
{
|
||||
@@ -2456,8 +2456,8 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration)
|
||||
mbgl::AnimationOptions animationOptions;
|
||||
if (duration > 0)
|
||||
{
|
||||
animationOptions.duration = MGLDurationInSeconds(duration);
|
||||
animationOptions.easing = MGLUnitBezierForMediaTimingFunction(function);
|
||||
animationOptions.duration.emplace(MGLDurationInSeconds(duration));
|
||||
animationOptions.easing.emplace(MGLUnitBezierForMediaTimingFunction(function));
|
||||
}
|
||||
if (completion)
|
||||
{
|
||||
|
||||
@@ -1037,8 +1037,8 @@ public:
|
||||
mbgl::CameraOptions cameraOptions = [self cameraOptionsObjectForAnimatingToCamera:camera];
|
||||
mbgl::AnimationOptions animationOptions;
|
||||
if (duration > 0) {
|
||||
animationOptions.duration = MGLDurationInSeconds(duration);
|
||||
animationOptions.easing = MGLUnitBezierForMediaTimingFunction(function);
|
||||
animationOptions.duration.emplace(MGLDurationInSeconds(duration));
|
||||
animationOptions.easing.emplace(MGLUnitBezierForMediaTimingFunction(function));
|
||||
}
|
||||
if (completion) {
|
||||
animationOptions.transitionFinishFn = [completion]() {
|
||||
|
||||
Reference in New Issue
Block a user