• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef GEOMETRY_LEAST_SQUARE_IMPL_H
17 #define GEOMETRY_LEAST_SQUARE_IMPL_H
18 
19 #include <vector>
20 
21 #ifdef LINUX_PLATFORM
22 #include <cstdint>
23 #endif
24 namespace OHOS::uitest {
25 /**
26  * @brief Least square method of four parametres.
27  * the function template is a3 * x^3 + a2 * x^2 + a1 * x + a0 = y with four;
28  * the function template is 0 * x^3 + a2 * x^2 + a1 * x + a0 = y with three.
29  */
30 class LeastSquareImpl {
31 public:
32     /**
33      * @brief Construct a new Least Square Impl object.
34      * @param paramsNum the right number is 4 or 3.
35      */
LeastSquareImpl(int32_t paramsNum)36     explicit LeastSquareImpl(int32_t paramsNum) : paramsNum_(paramsNum) {}
37 
38     /**
39      * @brief Construct a new Least Square Impl object.
40      * @param paramsNum the right number is 4 or 3.
41      */
LeastSquareImpl(int32_t paramsNum,int32_t countNum)42     LeastSquareImpl(int32_t paramsNum, int32_t countNum) : paramsNum_(paramsNum), countNum_(countNum) {}
43 
44     LeastSquareImpl() = default;
45     ~LeastSquareImpl() = default;
46 
UpdatePoint(double tVal,double pVal)47     void UpdatePoint(double tVal, double pVal)
48     {
49         isResolved_ = false;
50         tVals_.emplace_back(tVal);
51         pVals_.emplace_back(pVal);
52     }
53 
54     /**
55      * @brief Set the Count Num which to compute.
56      *
57      * @param countNum the compute number.
58      */
SetCountNum(int32_t countNum)59     void SetCountNum(int32_t countNum)
60     {
61         countNum_ = countNum;
62     }
63 
64     /**
65      * @brief Get the Least Square Params object
66      *
67      * @param params the four values of vector.
68      * @return true get the least square result.
69      * @return false failed to get the least square result.
70      */
71     bool GetLSMParams(std::vector<double>& params);
72 
GetTVals()73     inline const std::vector<double>& GetTVals() const
74     {
75         return tVals_;
76     }
77 
GetPVals()78     inline const std::vector<double>& GetPVals() const
79     {
80         return pVals_;
81     }
82 
GetTrackNum()83     inline int32_t GetTrackNum() const
84     {
85         return tVals_.size();
86     }
87 
Resets()88     void Resets()
89     {
90         tVals_.clear();
91         pVals_.clear();
92         params_.clear();
93         isResolved_ = false;
94     }
95 
96 private:
97     std::vector<double> tVals_;
98     std::vector<double> pVals_;
99     std::vector<double> params_;
100     int32_t paramsNum_ = 4;
101     int32_t countNum_ = 4;
102     bool isResolved_ = false;
103 };
104 } // namespace OHOS::uitest
105 
106 #endif // GEOMETRY_LEAST_SQUARE_IMPL_H