Skip to content

Commit

Permalink
Add scale_by/scale_to functions to Size (#146)
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.

This is part of a fix for [resvg #810](linebender/resvg/issues/810).
  • Loading branch information
jermy authored Jan 6, 2025
1 parent cf6530d commit 34e7783
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions path/src/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,26 @@ 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 34e7783

Please sign in to comment.