font_types/
bbox.rs

1use core::ops::Mul;
2
3/// Minimum and maximum extents of a rectangular region.
4#[derive(Copy, Clone, PartialEq, Eq, Default, Debug)]
5#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6pub struct BoundingBox<T> {
7    /// Minimum extent in the x direction-- the left side of a region.
8    pub x_min: T,
9    /// Minimum extent in the y direction. In a Y-up coordinate system,
10    /// which is used by fonts, this represents the bottom of a region.
11    pub y_min: T,
12    /// Maximum extent in the x direction-- the right side of a region.
13    pub x_max: T,
14    /// Maximum extend in the y direction. In a Y-up coordinate system,
15    /// which is used by fonts, this represents the top of the
16    /// region.
17    pub y_max: T,
18}
19
20impl<T> BoundingBox<T>
21where
22    T: Mul<Output = T> + Copy,
23{
24    /// Return a `BoundingBox` scaled by a scale factor of the same type
25    /// as the stored bounds.
26    pub fn scale(&self, factor: T) -> Self {
27        Self {
28            x_min: self.x_min * factor,
29            y_min: self.y_min * factor,
30            x_max: self.x_max * factor,
31            y_max: self.y_max * factor,
32        }
33    }
34}