Skip to main content

uzor_render/
helpers.rs

1/// Make value crisp at device pixel boundaries
2#[inline]
3pub fn crisp(val: f64, dpr: f64) -> f64 {
4    (val * dpr).round() / dpr + 0.5 / dpr
5}
6
7/// Make rectangle crisp at device pixel boundaries
8#[inline]
9pub fn crisp_rect(x: f64, y: f64, w: f64, h: f64, dpr: f64) -> (f64, f64, f64, f64) {
10    let x1 = (x * dpr).round() / dpr;
11    let y1 = (y * dpr).round() / dpr;
12    let x2 = ((x + w) * dpr).round() / dpr;
13    let y2 = ((y + h) * dpr).round() / dpr;
14    (x1, y1, x2 - x1, y2 - y1)
15}