Clips the user-supplied `xy` coordinates to the LCD space. Returns `None` if they are out of range and the converted value otherwise.
(&self, xy: PixelsXY)
| 120 | /// Clips the user-supplied `xy` coordinates to the LCD space. Returns `None` if they are out |
| 121 | /// of range and the converted value otherwise. |
| 122 | fn clip_xy(&self, xy: PixelsXY) -> Option<LcdXY> { |
| 123 | fn clamp(value: i16, max: usize) -> Option<usize> { |
| 124 | if value < 0 { |
| 125 | None |
| 126 | } else { |
| 127 | let value = usize::try_from(value).expect("Positive value must fit"); |
| 128 | if value > max { None } else { Some(value) } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | let x = clamp(xy.x, self.size_pixels.width - 1); |
| 133 | let y = clamp(xy.y, self.size_pixels.height - 1); |
| 134 | match (x, y) { |
| 135 | (Some(x), Some(y)) => Some(LcdXY { x, y }), |
| 136 | _ => None, |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | /// Clamps the user-supplied `xy` coordinates to the LCD space. |
| 141 | fn clamp_xy(&self, xy: PixelsXY) -> LcdXY { |
no outgoing calls
no test coverage detected