1/*
2 * Copyright 2012, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef LINEAR_REGRESSION_H_
18
19#define LINEAR_REGRESSION_H_
20
21#include <sys/types.h>
22#include <media/stagefright/foundation/ABase.h>
23
24namespace android {
25
26// Helper class to fit a line to a set of points minimizing the sum of
27// squared (orthogonal) distances from line to individual points.
28struct LinearRegression {
29    LinearRegression(size_t historySize);
30    ~LinearRegression();
31
32    void addPoint(float x, float y);
33
34    bool approxLine(float *n1, float *n2, float *b) const;
35
36private:
37    struct Point {
38        float mX, mY;
39    };
40
41    size_t mHistorySize;
42    size_t mCount;
43    Point *mHistory;
44
45    float mSumX, mSumY;
46
47    DISALLOW_EVIL_CONSTRUCTORS(LinearRegression);
48};
49
50}  // namespace android
51
52#endif  // LINEAR_REGRESSION_H_
53