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

Function rect_points

std/src/console/graphics.rs:138–166  ·  view source on GitHub ↗

Given two points, calculates the origin and size of the rectangle they define.

(x1y1: PixelsXY, x2y2: PixelsXY)

Source from the content-addressed store, hash-verified

136
137/// Given two points, calculates the origin and size of the rectangle they define.
138fn rect_points(x1y1: PixelsXY, x2y2: PixelsXY) -> Option<(PixelsXY, SizeInPixels)> {
139 let (x1, x2) = if x1y1.x < x2y2.x { (x1y1.x, x2y2.x) } else { (x2y2.x, x1y1.x) };
140 let (y1, y2) = if x1y1.y < x2y2.y { (x1y1.y, x2y2.y) } else { (x2y2.y, x1y1.y) };
141
142 let width = {
143 let width = i32::from(x2) - i32::from(x1);
144 if cfg!(debug_assertions) {
145 u32::try_from(width).expect("Width must have been non-negative")
146 } else {
147 width as u32
148 }
149 }
150 .clamped_into();
151 let height = {
152 let height = i32::from(y2) - i32::from(y1);
153 if cfg!(debug_assertions) {
154 u32::try_from(height).expect("Height must have been non-negative")
155 } else {
156 height as u32
157 }
158 }
159 .clamped_into();
160
161 if width == 0 || height == 0 {
162 None
163 } else {
164 Some((PixelsXY::new(x1, y1), SizeInPixels::new(width, height)))
165 }
166}
167
168/// Returns true if the three points define a non-degenerate triangle.
169fn tri_points(x1y1: PixelsXY, x2y2: PixelsXY, x3y3: PixelsXY) -> bool {

Callers 2

draw_rectMethod · 0.85
draw_rect_filledMethod · 0.85

Calls 1

clamped_intoMethod · 0.80

Tested by

no test coverage detected