diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e6eb3a..f2ef273 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Breaking Changes + +- `Px`, `UPx`, and `Lp` no longer directly have an associated constant `ZERO`. + This constant is still available via the `Zero` trait. + ## v0.2.2 (2024-01-04) ### Added diff --git a/src/rect.rs b/src/rect.rs index ef63100..33e52e0 100644 --- a/src/rect.rs +++ b/src/rect.rs @@ -1,7 +1,7 @@ use std::ops::{Add, AddAssign, Sub, SubAssign}; use crate::traits::{IntoSigned, IntoUnsigned, Ranged}; -use crate::{Point, Round, Size}; +use crate::{Point, Round, Size, Zero}; /// A 2d area expressed as an origin ([`Point`]) and a [`Size`]. #[derive(Clone, Copy, Eq, PartialEq, Hash, Debug)] @@ -292,6 +292,20 @@ where const MIN: Self = Self::new(Point::MIN, Size::MIN); } +impl Zero for Rect +where + Unit: Zero, +{ + const ZERO: Self = Self { + origin: Point::ZERO, + size: Size::ZERO, + }; + + fn is_zero(&self) -> bool { + self.origin.is_zero() && self.size.is_zero() + } +} + #[test] fn intersection() { assert_eq!( diff --git a/src/tests.rs b/src/tests.rs index 6e74a26..f1dbe89 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -3,7 +3,7 @@ use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; use crate::traits::{FromComponents, IntoComponents, ScreenScale}; use crate::units::{Lp, Px, UPx}; -use crate::{Angle, Fraction, Point, Size}; +use crate::{Angle, Fraction, Point, Size, Zero}; #[test] fn one_inch_is_correct() { diff --git a/src/units.rs b/src/units.rs index 13eeb51..dc74c8d 100644 --- a/src/units.rs +++ b/src/units.rs @@ -31,8 +31,6 @@ macro_rules! define_integer_type { pub const MAX: Self = Self(<$inner>::MAX); /// The minimum value for this type. pub const MIN: Self = Self(<$inner>::MIN); - /// Zero for this type. - pub const ZERO: Self = Self(0); /// Returns a new wrapped value for this unit. #[must_use]