resvg/
geom.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5/// Fits the current rect into the specified bounds.
6pub fn fit_to_rect(
7    r: tiny_skia::IntRect,
8    bounds: tiny_skia::IntRect,
9) -> Option<tiny_skia::IntRect> {
10    let mut left = r.left();
11    if left < bounds.left() {
12        left = bounds.left();
13    }
14
15    let mut top = r.top();
16    if top < bounds.top() {
17        top = bounds.top();
18    }
19
20    let mut right = r.right();
21    if right > bounds.right() {
22        right = bounds.right();
23    }
24
25    let mut bottom = r.bottom();
26    if bottom > bounds.bottom() {
27        bottom = bounds.bottom();
28    }
29
30    tiny_skia::IntRect::from_ltrb(left, top, right, bottom)
31}