Skip to content

Commit

Permalink
Rect FloatConversion
Browse files Browse the repository at this point in the history
  • Loading branch information
ecton committed Oct 6, 2024
1 parent 4a058fa commit f981e2b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `Fraction::new` now contains a `debug_assert!` ensuring the denominator is
non-zero.

### Added

- `Rect` now implements `FloatConversion` when its unit type implements it.

## v0.4.0 (2024-07-22)

### Breaking Changes
Expand Down
17 changes: 16 additions & 1 deletion src/rect.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::ops::{Add, AddAssign, Sub, SubAssign};

use crate::traits::{IntoSigned, IntoUnsigned, Ranged};
use crate::{Point, Round, Size, Zero};
use crate::{FloatConversion, Point, Round, Size, Zero};

/// A 2d area expressed as an origin ([`Point`]) and a [`Size`].
#[derive(Clone, Copy, Eq, PartialEq, Hash, Debug)]
Expand Down Expand Up @@ -306,6 +306,21 @@ where
}
}

impl<Unit> FloatConversion for Rect<Unit>
where
Unit: FloatConversion,
{
type Float = Rect<Unit::Float>;

fn into_float(self) -> Self::Float {
self.map(FloatConversion::into_float)
}

fn from_float(float: Self::Float) -> Self {
float.map(FloatConversion::from_float)
}
}

#[test]
fn intersection() {
assert_eq!(
Expand Down

0 comments on commit f981e2b

Please sign in to comment.