diff --git a/frameworks/core/gestures/velocity_tracker.cpp b/frameworks/core/gestures/velocity_tracker.cpp index 270aa750018b710fd247e5f66543d8d64df83af7..eb3509e30f16161809c3839bdd48147c22db4493 100644 --- a/frameworks/core/gestures/velocity_tracker.cpp +++ b/frameworks/core/gestures/velocity_tracker.cpp @@ -131,7 +131,7 @@ double VelocityTracker::UpdateAxisVelocity(LeastSquareImpl& axisRaw) void VelocityTracker::UpdateTouchPoint(const TouchEvent& event, bool end, float range) { - if (end && SystemProperties::IsVelocityWithoutUpPoint()) { + if (end && event.sourceType == SourceType::TOUCH && SystemProperties::IsVelocityWithoutUpPoint()) { return; } if (isFirstPoint_) { diff --git a/test/unittest/core/pipeline/velocity_tracker_test.cpp b/test/unittest/core/pipeline/velocity_tracker_test.cpp index 74c37caeb7f78fa0e598d56910b0bee8212ab950..14af70f7a260b96936cdd38442c074c943220b53 100644 --- a/test/unittest/core/pipeline/velocity_tracker_test.cpp +++ b/test/unittest/core/pipeline/velocity_tracker_test.cpp @@ -462,6 +462,7 @@ HWTEST_F(VelocityTrackerTest, sampleDatas2, TestSize.Level1) std::chrono::microseconds microseconds(point[0] * RATIO_MS_TO_US); TimeStamp timeStamp(microseconds); TouchEvent touchEvent; + touchEvent.sourceType == SourceType::TOUCH; touchEvent.x = point[1] / TO_TRUE_DATA; touchEvent.y = point[2] / TO_TRUE_DATA; touchEvent.time = timeStamp; @@ -526,6 +527,7 @@ HWTEST_F(VelocityTrackerTest, justPanDatas, TestSize.Level1) std::chrono::microseconds microseconds(static_cast(point[0] / RATIO_NS_TO_US)); TimeStamp timeStamp(microseconds); TouchEvent touchEvent; + touchEvent.sourceType == SourceType::TOUCH; touchEvent.x = point[1]; touchEvent.y = point[2]; touchEvent.time = timeStamp; @@ -540,5 +542,33 @@ HWTEST_F(VelocityTrackerTest, justPanDatas, TestSize.Level1) EXPECT_NE(velocityTracker.velocity_.GetVelocityX(), 0.0); } - +/** + * @tc.name: velcoityTrackerEndPointTest001 + * @tc.desc: Test UpdateTouchPoint + * @tc.type: FUNC + */ +HWTEST_F(VelocityTrackerTest, velcoityTrackerEndTest001, TestSize.Level1) +{ + SystemProperties::velocityTrackerPointNumber_ = 20; + SystemProperties::isVelocityWithinTimeWindow_ = false; + SystemProperties::isVelocityWithoutUpPoint_ = false; + VelocityTracker velocityTracker; + std::vector timeStampList = { 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000 }; + std::vector sourceTypeList = { SourceType::TOUCH, SourceType::TOUCH, SourceType::NONE, + SourceType::NONE, SourceType::TOUCH, SourceType::TOUCH, SourceType::NONE, SourceType::NONE }; + std::vector isEndList = { false, true, false, true, false, true, false, true }; + for (auto i = 0; i < timeStampList.size(); ++i) { + if (i == 4) { + SystemProperties::isVelocityWithoutUpPoint_ = true; + } + std::chrono::microseconds microseconds(static_cast(timeStampList[i] * RATIO_MS_TO_US)); + TimeStamp timeStamp(microseconds); + TouchEvent touchEvent; + touchEvent.id = i; + touchEvent.time = timeStamp; + touchEvent.sourceType = sourceTypeList[i]; + velocityTracker.UpdateTouchPoint(touchEvent, isEndList[i], TOUCH_STILL_THRESHOLD); + } + EXPECT_EQ(velocityTracker.xAxis_.GetTrackNum(), 7); +} } // namespace OHOS::Ace::NG