(
bridge: &NativeBridge,
udid: &str,
center_x: Option<f64>,
center_y: Option<f64>,
start_distance: f64,
end_distance: f64,
angle_degrees: f64,
normalized: bool,
ste
| 73 | |
| 74 | #[allow(clippy::too_many_arguments)] |
| 75 | fn pinch_frames( |
| 76 | bridge: &NativeBridge, |
| 77 | udid: &str, |
| 78 | center_x: Option<f64>, |
| 79 | center_y: Option<f64>, |
| 80 | start_distance: f64, |
| 81 | end_distance: f64, |
| 82 | angle_degrees: f64, |
| 83 | normalized: bool, |
| 84 | steps: u32, |
| 85 | ) -> Result<Vec<MultiTouchFrame>, crate::error::AppError> { |
| 86 | if start_distance < 0.0 || end_distance < 0.0 { |
| 87 | return Err(crate::error::AppError::bad_request( |
| 88 | "Pinch distances must be non-negative.", |
| 89 | )); |
| 90 | } |
| 91 | let (width, height) = gesture_surface_size(bridge, udid, normalized); |
| 92 | let center_x = center_x.unwrap_or(width / 2.0); |
| 93 | let center_y = center_y.unwrap_or(height / 2.0); |
| 94 | let angle = angle_degrees.to_radians(); |
| 95 | let unit_x = angle.cos(); |
| 96 | let unit_y = angle.sin(); |
| 97 | let count = steps.max(2); |
| 98 | let mut frames = Vec::with_capacity(count as usize); |
| 99 | for step in 0..count { |
| 100 | let t = if count == 1 { |
| 101 | 1.0 |
| 102 | } else { |
| 103 | f64::from(step) / f64::from(count - 1) |
| 104 | }; |
| 105 | let distance = lerp(start_distance, end_distance, t) / 2.0; |
| 106 | let p1x = center_x - unit_x * distance; |
| 107 | let p1y = center_y - unit_y * distance; |
| 108 | let p2x = center_x + unit_x * distance; |
| 109 | let p2y = center_y + unit_y * distance; |
| 110 | let (x1, y1) = resolve_touch_point(bridge, udid, p1x, p1y, normalized)?; |
| 111 | let (x2, y2) = resolve_touch_point(bridge, udid, p2x, p2y, normalized)?; |
| 112 | frames.push(MultiTouchFrame { x1, y1, x2, y2 }); |
| 113 | } |
| 114 | Ok(frames) |
| 115 | } |
| 116 | |
| 117 | fn rotate_gesture_frames( |
| 118 | bridge: &NativeBridge, |
no test coverage detected