Given two points, calculates the origin and size of the rectangle they define.
(x1y1: PixelsXY, x2y2: PixelsXY)
| 136 | |
| 137 | /// Given two points, calculates the origin and size of the rectangle they define. |
| 138 | fn 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. |
| 169 | fn tri_points(x1y1: PixelsXY, x2y2: PixelsXY, x3y3: PixelsXY) -> bool { |
no test coverage detected