MCPcopy Index your code
hub / github.com/endbasic/endbasic / clip_xy

Method clip_xy

std/src/gfx/lcd/buffered/mod.rs:122–138  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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 {

Callers 4

peek_pixelMethod · 0.80
read_pixelsMethod · 0.80
put_pixelsMethod · 0.80
draw_pixelMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected