Commit d021ee2a by Alex Butler

### Derive defaults instead of implementing

parent 7a3954e4
 ... ... @@ -17,41 +17,23 @@ use crate::nostd_float::FloatExt; /// # let t = 0.5; let p0 = point(0.0, 0.0); let p1 = point(0.0, 0.0); /// let interpolated_point = p0 + (p1 - p0) * t; /// ``` #[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq, Hash)] #[derive(Copy, Clone, Debug, Default, PartialOrd, Ord, PartialEq, Eq, Hash)] pub struct Point { pub x: N, pub y: N, } impl Default for Point { fn default() -> Self { Point { x: N::default(), y: N::default() } } } /// A vector in 2-dimensional space, with each dimension of type `N`. /// /// Legal operations on vectors are addition and subtraction by vectors, /// addition by points (to give points), and multiplication and division by /// scalars. #[derive(Copy, Clone, Debug, PartialOrd, Ord, PartialEq, Eq, Hash)] #[derive(Copy, Clone, Debug, Default, PartialOrd, Ord, PartialEq, Eq, Hash)] pub struct Vector { pub x: N, pub y: N, } impl Default for Vector { fn default() -> Self { Vector { x: N::default(), y: N::default() } } } /// A convenience function for generating `Point`s. #[inline] pub fn point(x: N, y: N) -> Point { ... ... @@ -174,21 +156,12 @@ pub struct Curve { } /// A rectangle, with top-left corner at `min`, and bottom-right corner at /// `max`. #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct Rect { pub min: Point, pub max: Point, } impl Default for Rect { fn default() -> Self { Rect { min: Point::default(), max: Point::default() } } } impl + Copy> Rect { pub fn width(&self) -> N { self.max.x - self.min.x ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!