Skip to content

Commit

Permalink
Add scale_by/scale_to functions to Size
Browse files Browse the repository at this point in the history
These match the implementations for for IntSize, making it simpler to
implement floating point support in the resvg main binary.
  • Loading branch information
jermy committed Dec 27, 2024
1 parent cf6530d commit 54790fb
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions path/src/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,29 @@ impl Size {
size_scale_f64(*self, to, true)
}

/// Scales current size by the specified factor.
#[inline]
pub fn scale_by(&self, factor: f32) -> Option<Self> {
Self::from_wh(
self.width() * factor,
self.height() * factor,
)
}

/// Scales current size to the specified width.
#[inline]
pub fn scale_to_width(&self, new_width: f32) -> Option<Self> {
let new_height = new_width * self.height() / self.width();
Self::from_wh(new_width, new_height)
}

/// Scales current size to the specified height.
#[inline]
pub fn scale_to_height(&self, new_height: f32) -> Option<Self> {
let new_width = new_height * self.width() / self.height();
Self::from_wh(new_width, new_height)
}

/// Converts into [`IntSize`].
pub fn to_int_size(&self) -> IntSize {
IntSize::from_wh(
Expand Down

0 comments on commit 54790fb

Please sign in to comment.