1 | // Copyright 2023 the Resvg Authors |
2 | // SPDX-License-Identifier: Apache-2.0 OR MIT |
3 | |
4 | /// Fits the current rect into the specified bounds. |
5 | pub fn fit_to_rect( |
6 | r: tiny_skia::IntRect, |
7 | bounds: tiny_skia::IntRect, |
8 | ) -> Option<tiny_skia::IntRect> { |
9 | let mut left: i32 = r.left(); |
10 | if left < bounds.left() { |
11 | left = bounds.left(); |
12 | } |
13 | |
14 | let mut top: i32 = r.top(); |
15 | if top < bounds.top() { |
16 | top = bounds.top(); |
17 | } |
18 | |
19 | let mut right: i32 = r.right(); |
20 | if right > bounds.right() { |
21 | right = bounds.right(); |
22 | } |
23 | |
24 | let mut bottom: i32 = r.bottom(); |
25 | if bottom > bounds.bottom() { |
26 | bottom = bounds.bottom(); |
27 | } |
28 | |
29 | tiny_skia::IntRect::from_ltrb(left, top, right, bottom) |
30 | } |
31 | |