Add `Size.max`, conversions between `Position` and `Size`, `BoxBounds.extent`, and `BoxBounds.with_size`.
This commit is contained in:
parent
e7c34d9745
commit
ef035c5283
|
@ -122,6 +122,27 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> Size<T>
|
||||||
|
where
|
||||||
|
T: Ord,
|
||||||
|
{
|
||||||
|
pub fn max(self, rhs: Self) -> Self {
|
||||||
|
Self {
|
||||||
|
width: max(self.width, rhs.width),
|
||||||
|
height: max(self.height, rhs.height),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> From<Position<T>> for Size<T> {
|
||||||
|
fn from(size: Position<T>) -> Self {
|
||||||
|
Self {
|
||||||
|
width: size.x,
|
||||||
|
height: size.y,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A type which represents the offset and size of text-orientation-relative
|
/// A type which represents the offset and size of text-orientation-relative
|
||||||
/// boxes.
|
/// boxes.
|
||||||
///
|
///
|
||||||
|
@ -231,6 +252,10 @@ where
|
||||||
pub fn origin(&self) -> Position<T> {
|
pub fn origin(&self) -> Position<T> {
|
||||||
Position::from((self.offset_x(), self.offset_y()))
|
Position::from((self.offset_x(), self.offset_y()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn extent(&self) -> Position<T> {
|
||||||
|
Position::from((self.extent_x(), self.extent_y()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> BoxBounds<T>
|
impl<T> BoxBounds<T>
|
||||||
|
@ -250,6 +275,20 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T> BoxBounds<T>
|
||||||
|
where
|
||||||
|
T: Add<T, Output = T> + Clone,
|
||||||
|
{
|
||||||
|
pub fn with_size(self, new_size: Size<T>) -> Self {
|
||||||
|
Self {
|
||||||
|
offset_x: self.offset_x.clone(),
|
||||||
|
extent_x: self.offset_x + new_size.width,
|
||||||
|
offset_y: self.offset_y.clone(),
|
||||||
|
extent_y: self.offset_y + new_size.height,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T> Add for BoxBounds<T>
|
impl<T> Add for BoxBounds<T>
|
||||||
where
|
where
|
||||||
T: Add<T> + Ord + Clone,
|
T: Add<T> + Ord + Clone,
|
||||||
|
|
Loading…
Reference in New Issue