From 44b3e4cc0be781c78cc12bae79947748b1bd9804 Mon Sep 17 00:00:00 2001 From: benb365 Date: Mon, 4 Mar 2024 18:58:47 +0800 Subject: [PATCH] Avoid inversible matrix. Signed-off-by: benb365 Change-Id: I59d19af4bea9e10e2d0a660eee36e15143f08d66 --- frameworks/base/geometry/least_square_impl.cpp | 2 +- frameworks/core/gestures/velocity_tracker.cpp | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/frameworks/base/geometry/least_square_impl.cpp b/frameworks/base/geometry/least_square_impl.cpp index bfe3f162329..f0217894a09 100644 --- a/frameworks/base/geometry/least_square_impl.cpp +++ b/frameworks/base/geometry/least_square_impl.cpp @@ -21,7 +21,7 @@ namespace OHOS::Ace { bool LeastSquareImpl::GetLeastSquareParams(std::vector& params) { - if (xVals_.size() <= 1 || ((paramsNum_ != Matrix3::DIMENSION) && (paramsNum_ != Matrix4::DIMENSION))) { + if (xVals_.size() < paramsNum_ || ((paramsNum_ != Matrix3::DIMENSION) && (paramsNum_ != Matrix4::DIMENSION))) { return false; } params.resize(paramsNum_, 0); diff --git a/frameworks/core/gestures/velocity_tracker.cpp b/frameworks/core/gestures/velocity_tracker.cpp index e066bcb0341..5e43000d523 100644 --- a/frameworks/core/gestures/velocity_tracker.cpp +++ b/frameworks/core/gestures/velocity_tracker.cpp @@ -65,7 +65,10 @@ inline double GetLinearSlope(const LeastSquareImpl& axis) const auto& x = axis.GetXVals(); const auto& y = axis.GetYVals(); auto count = axis.GetTrackNum(); - return (y[count - 1] - y[count - 2]) / (x[count - 1] - x[count - 2]); // 2: const + double velocity = (y[count - 1] - y[count - 2]) / (x[count - 1] - x[count - 2]); // 2: const + LOGI("Linear velocity:%{public}f, startY:%{public}f, endY:%{public}f, startX:%{public}f, endX:%{public}f", + velocity, y[count - 2], y[count - 1], x[count - 2], x[count - 1]); + return velocity; } void CorrectMonotonicAxisVelocity(const LeastSquareImpl& axis, double& v, double extremX) -- Gitee