Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/nsSMILKeySpline.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef NS_SMILKEYSPLINE_H_
8
#define NS_SMILKEYSPLINE_H_
9
10
#include "mozilla/ArrayUtils.h"
11
#include "mozilla/PodOperations.h"
12
13
/**
14
 * Utility class to provide scaling defined in a keySplines element.
15
 */
16
class nsSMILKeySpline
17
{
18
public:
19
  nsSMILKeySpline()
20
    : mX1(0)
21
    , mY1(0)
22
    , mX2(0)
23
    , mY2(0)
24
0
  {
25
0
    /* caller must call Init later */\
26
0
  }
27
28
  /**
29
   * Creates a new key spline control point description.
30
   *
31
   * aX1, etc. are the x1, y1, x2, y2 cubic Bezier control points as defined by
32
   * SMILANIM 3.2.3. They must each be in the range 0.0 <= x <= 1.0
33
   */
34
  nsSMILKeySpline(double aX1, double aY1,
35
                  double aX2, double aY2)
36
    : mX1(0)
37
    , mY1(0)
38
    , mX2(0)
39
    , mY2(0)
40
0
  {
41
0
    Init(aX1, aY1, aX2, aY2);
42
0
  }
43
44
0
  double X1() const { return mX1; }
45
0
  double Y1() const { return mY1; }
46
0
  double X2() const { return mX2; }
47
0
  double Y2() const { return mY2; }
48
49
  void Init(double aX1, double aY1,
50
            double aX2, double aY2);
51
52
  /**
53
   * Gets the output (y) value for an input (x).
54
   *
55
   * @param aX  The input x value. A floating-point number between 0 and
56
   *            1 (inclusive).
57
   */
58
  double GetSplineValue(double aX) const;
59
60
  void GetSplineDerivativeValues(double aX, double& aDX, double& aDY) const;
61
62
0
  bool operator==(const nsSMILKeySpline& aOther) const {
63
0
    return mX1 == aOther.mX1 &&
64
0
           mY1 == aOther.mY1 &&
65
0
           mX2 == aOther.mX2 &&
66
0
           mY2 == aOther.mY2;
67
0
  }
68
0
  bool operator!=(const nsSMILKeySpline& aOther) const {
69
0
    return !(*this == aOther);
70
0
  }
71
0
  int32_t Compare(const nsSMILKeySpline& aRhs) const {
72
0
    if (mX1 != aRhs.mX1) return mX1 < aRhs.mX1 ? -1 : 1;
73
0
    if (mY1 != aRhs.mY1) return mY1 < aRhs.mY1 ? -1 : 1;
74
0
    if (mX2 != aRhs.mX2) return mX2 < aRhs.mX2 ? -1 : 1;
75
0
    if (mY2 != aRhs.mY2) return mY2 < aRhs.mY2 ? -1 : 1;
76
0
    return 0;
77
0
  }
78
79
private:
80
  void
81
  CalcSampleValues();
82
83
  /**
84
   * Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
85
   */
86
  static double
87
  CalcBezier(double aT, double aA1, double aA2);
88
89
  /**
90
   * Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
91
   */
92
  static double
93
  GetSlope(double aT, double aA1, double aA2);
94
95
  double
96
  GetTForX(double aX) const;
97
98
  double
99
  NewtonRaphsonIterate(double aX, double aGuessT) const;
100
101
  double
102
  BinarySubdivide(double aX, double aA, double aB) const;
103
104
  static double
105
  A(double aA1, double aA2)
106
  {
107
    return 1.0 - 3.0 * aA2 + 3.0 * aA1;
108
  }
109
110
  static double
111
  B(double aA1, double aA2)
112
  {
113
    return 3.0 * aA2 - 6.0 * aA1;
114
  }
115
116
  static double
117
  C(double aA1)
118
  {
119
    return 3.0 * aA1;
120
  }
121
122
  double               mX1;
123
  double               mY1;
124
  double               mX2;
125
  double               mY2;
126
127
  enum { kSplineTableSize = 11 };
128
  double               mSampleValues[kSplineTableSize];
129
130
  static const double  kSampleStepSize;
131
};
132
133
#endif // NS_SMILKEYSPLINE_H_