| 1234567891011121314151617181920212223242526272829303132333435 |
- /**
- * adb 公共工具:滑动坐标计算等
- */
- function calculateSwipeCoordinates(direction, width, height) {
- const margin = 0.15
- const swipeDistance = 0.7
- let x1, y1, x2, y2
- switch (direction) {
- case 'up-down':
- x1 = x2 = Math.round(width / 2)
- y1 = Math.round(height * margin)
- y2 = Math.round(height * (margin + swipeDistance))
- break
- case 'down-up':
- x1 = x2 = Math.round(width / 2)
- y1 = Math.round(height * (margin + swipeDistance))
- y2 = Math.round(height * margin)
- break
- case 'left-right':
- y1 = y2 = Math.round(height / 2)
- x1 = Math.round(width * margin)
- x2 = Math.round(width * (margin + swipeDistance))
- break
- case 'right-left':
- y1 = y2 = Math.round(height / 2)
- x1 = Math.round(width * (margin + swipeDistance))
- x2 = Math.round(width * margin)
- break
- default:
- throw new Error(`未知的滑动方向: ${direction}`)
- }
- return { x1, y1, x2, y2 }
- }
- module.exports = { calculateSwipeCoordinates }
|