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

Method clamp_xy

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

Clamps the user-supplied `xy` coordinates to the LCD space.

(&self, xy: PixelsXY)

Source from the content-addressed store, hash-verified

139
140 /// Clamps the user-supplied `xy` coordinates to the LCD space.
141 fn clamp_xy(&self, xy: PixelsXY) -> LcdXY {
142 fn clamp(value: i16, max: usize) -> usize {
143 if value < 0 {
144 0
145 } else {
146 let value = usize::try_from(value).expect("Positive value must fit");
147 if value > max { max } else { value }
148 }
149 }
150
151 LcdXY {
152 x: clamp(xy.x, self.size_pixels.width - 1),
153 y: clamp(xy.y, self.size_pixels.height - 1),
154 }
155 }
156
157 /// Given a top-left `xy` coordinate, adds the user-supplied `size` to it and clamps the result
158 /// to the LCD space.

Callers 1

draw_rect_filledMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected