From f072829c9fe89f0a76e876e0790272be280eaf30 Mon Sep 17 00:00:00 2001 From: caofengbin <1050430934@qq.com> Date: Tue, 20 Jun 2023 19:33:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=9F=BA=E4=BA=8Elanmda?= =?UTF-8?q?=E7=9A=84=E6=8F=92=E5=80=BC=E5=99=A8=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handlers/AndroidTouchHandlerTest.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/test/java/org/cloud/sonic/agent/tests/handlers/AndroidTouchHandlerTest.java b/src/test/java/org/cloud/sonic/agent/tests/handlers/AndroidTouchHandlerTest.java index 5c8ff0c2..d88d803f 100755 --- a/src/test/java/org/cloud/sonic/agent/tests/handlers/AndroidTouchHandlerTest.java +++ b/src/test/java/org/cloud/sonic/agent/tests/handlers/AndroidTouchHandlerTest.java @@ -2,6 +2,8 @@ import org.junit.Test; +import java.util.function.BiFunction; + public class AndroidTouchHandlerTest { private int width = 720; @@ -27,4 +29,39 @@ public void test() { System.out.println(re[0]); System.out.println(re[1]); } + + @Test + public void test_interpolator() { + int[] re1 = {200, 1200}; + int[] re2 = {200, 300}; + // 过渡总时间 + int duration = 500; + // 开始时间 + long startTime = System.currentTimeMillis(); + while (true) { + // 当前时间 + long currentTime = System.currentTimeMillis(); + float timeProgress = (currentTime - startTime) / (float) duration; + if (timeProgress >= 1.0f) { + // 已经过渡到结束值,停止过渡 + System.out.println("[" + re2[0] + "," + re2[1] + "]"); + break; + } + BiFunction transitionX = (start, end) -> + (int) (start + (end - start) * timeProgress); + BiFunction transitionY = (start, end) -> + (int) (start + (end - start) * timeProgress); // Y 坐标过渡函数 + + int currentX = transitionX.apply(re1[0], re2[0]); // 当前 X 坐标 + int currentY = transitionY.apply(re1[1], re2[1]); // 当前 Y 坐标 + // 使用当前坐标进行操作 + // ... + System.out.println("[" + currentX + "," + currentY + "]"); + try { + Thread.sleep(10); + } catch (InterruptedException e) { + + } + } + } }