Skip to content

Commit f981e2b

Browse files
committed
Rect FloatConversion
1 parent 4a058fa commit f981e2b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- `Fraction::new` now contains a `debug_assert!` ensuring the denominator is
1313
non-zero.
1414

15+
### Added
16+
17+
- `Rect` now implements `FloatConversion` when its unit type implements it.
18+
1519
## v0.4.0 (2024-07-22)
1620

1721
### Breaking Changes

src/rect.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::ops::{Add, AddAssign, Sub, SubAssign};
22

33
use crate::traits::{IntoSigned, IntoUnsigned, Ranged};
4-
use crate::{Point, Round, Size, Zero};
4+
use crate::{FloatConversion, Point, Round, Size, Zero};
55

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

309+
impl<Unit> FloatConversion for Rect<Unit>
310+
where
311+
Unit: FloatConversion,
312+
{
313+
type Float = Rect<Unit::Float>;
314+
315+
fn into_float(self) -> Self::Float {
316+
self.map(FloatConversion::into_float)
317+
}
318+
319+
fn from_float(float: Self::Float) -> Self {
320+
float.map(FloatConversion::from_float)
321+
}
322+
}
323+
309324
#[test]
310325
fn intersection() {
311326
assert_eq!(

0 commit comments

Comments
 (0)