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

Method clamp

std/src/gfx/lcd/buffered/mod.rs:123–130  ·  view source on GitHub ↗
(value: i16, max: usize)

Source from the content-addressed store, hash-verified

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);

Callers 1

play_toneMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected