summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-06-10 21:56:24 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-06-20 13:01:59 +0300
commit22aa22c99c63b8a52746db1b757885e7feea7e26 (patch)
tree1ade0d12eef5a0d79d1a5c57428c1ef0875d95c3 /include
parent350d015cc2f70d96c08285ee358def8f0a24419e (diff)
downloadqtlocation-mapboxgl-22aa22c99c63b8a52746db1b757885e7feea7e26.tar.gz
[core] UnitBezier ctor is now constexpr
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/util/unitbezier.hpp39
1 files changed, 19 insertions, 20 deletions
diff --git a/include/mbgl/util/unitbezier.hpp b/include/mbgl/util/unitbezier.hpp
index ce3e78f3cc..3a4994917b 100644
--- a/include/mbgl/util/unitbezier.hpp
+++ b/include/mbgl/util/unitbezier.hpp
@@ -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