resvg/geom.rs
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
/// Fits the current rect into the specified bounds.
pub fn fit_to_rect(
r: tiny_skia::IntRect,
bounds: tiny_skia::IntRect,
) -> Option<tiny_skia::IntRect> {
let mut left = r.left();
if left < bounds.left() {
left = bounds.left();
}
let mut top = r.top();
if top < bounds.top() {
top = bounds.top();
}
let mut right = r.right();
if right > bounds.right() {
right = bounds.right();
}
let mut bottom = r.bottom();
if bottom > bounds.bottom() {
bottom = bounds.bottom();
}
tiny_skia::IntRect::from_ltrb(left, top, right, bottom)
}