Function snap_and_clamp_bounds

Source
pub fn snap_and_clamp_bounds(
    bounds: Rect,
    surface: [f32; 2],
) -> (Rect, [f32; 2], [u32; 2])
Expand description

Snaps physical bounds outward and clamps their far edges to a surface.

The returned tuple is (snapped_bounds, origin, integer_size). Each size is forced to at least one pixel, even for empty or fully out-of-surface bounds; callers must reject invalid bounds earlier. Float-to-u32 casts saturate negative and excessively large values according to Rust cast semantics.

ยงExamples

use ailloli_ui_core::Rect;
use ailloli_ui_render_wgpu::cmd_bounds::snap_and_clamp_bounds;
let (bounds, origin, size) = snap_and_clamp_bounds(
    Rect::new(1.25, 2.5, 3.0, 4.0), [100.0, 100.0]);
assert_eq!(origin, [1.0, 2.0]);
assert_eq!(size, [4, 5]);
assert_eq!(bounds, Rect::new(1.0, 2.0, 4.0, 5.0));