summaryrefslogtreecommitdiff
path: root/src/geom
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-08-21 16:38:51 +0200
committerLaurenz <laurmaedje@gmail.com>2021-08-21 17:30:21 +0200
commit0dd4ae0a7ac0c247078df492469ff20b8a90c886 (patch)
tree07a55343b9ccab3fe76b0f1b0de9d1be310d8b14 /src/geom
parentf38eb10c2b54bd13ccef119454839f6a66448462 (diff)
Prune derives
Diffstat (limited to 'src/geom')
-rw-r--r--src/geom/angle.rs21
-rw-r--r--src/geom/fr.rs8
-rw-r--r--src/geom/length.rs16
-rw-r--r--src/geom/linear.rs8
-rw-r--r--src/geom/relative.rs8
-rw-r--r--src/geom/sides.rs16
6 files changed, 40 insertions, 37 deletions
diff --git a/src/geom/angle.rs b/src/geom/angle.rs
index 8f18210c..cf3e49a0 100644
--- a/src/geom/angle.rs
+++ b/src/geom/angle.rs
@@ -1,8 +1,11 @@
-use super::*;
use decorum::N64;
+use serde::{Deserialize, Serialize};
+
+use super::*;
/// An angle.
#[derive(Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
+#[derive(Serialize, Deserialize)]
pub struct Angle(N64);
impl Angle {
@@ -52,6 +55,13 @@ impl Angle {
}
}
+impl Debug for Angle {
+ fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+ let unit = AngularUnit::Deg;
+ write!(f, "{}{}", self.to_unit(unit), unit)
+ }
+}
+
impl Display for Angle {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
// Format with the unit that yields the shortest output, preferring
@@ -66,13 +76,6 @@ impl Display for Angle {
}
}
-impl Debug for Angle {
- fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- let unit = AngularUnit::Deg;
- write!(f, "{}{}", self.to_unit(unit), unit)
- }
-}
-
impl Neg for Angle {
type Output = Self;
@@ -134,7 +137,7 @@ impl Sum for Angle {
}
}
/// Different units of angular measurement.
-#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum AngularUnit {
/// Radians.
Rad,
diff --git a/src/geom/fr.rs b/src/geom/fr.rs
index 1768366a..eaf539d9 100644
--- a/src/geom/fr.rs
+++ b/src/geom/fr.rs
@@ -33,15 +33,15 @@ impl Fractional {
}
}
-impl Display for Fractional {
+impl Debug for Fractional {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- write!(f, "{}fr", self.get())
+ Display::fmt(self, f)
}
}
-impl Debug for Fractional {
+impl Display for Fractional {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- Display::fmt(self, f)
+ write!(f, "{}fr", self.get())
}
}
diff --git a/src/geom/length.rs b/src/geom/length.rs
index 343b523c..3510fa6f 100644
--- a/src/geom/length.rs
+++ b/src/geom/length.rs
@@ -126,6 +126,13 @@ impl Length {
}
}
+impl Debug for Length {
+ fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+ let unit = LengthUnit::Pt;
+ write!(f, "{}{}", self.to_unit(unit), unit)
+ }
+}
+
impl Display for Length {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
use LengthUnit::*;
@@ -142,13 +149,6 @@ impl Display for Length {
}
}
-impl Debug for Length {
- fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- let unit = LengthUnit::Pt;
- write!(f, "{}{}", self.to_unit(unit), unit)
- }
-}
-
impl Neg for Length {
type Output = Self;
@@ -217,7 +217,7 @@ impl<'a> Sum<&'a Length> for Length {
}
/// Different units of length measurement.
-#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
+#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum LengthUnit {
/// Points.
Pt,
diff --git a/src/geom/linear.rs b/src/geom/linear.rs
index 38d19b13..6a20b826 100644
--- a/src/geom/linear.rs
+++ b/src/geom/linear.rs
@@ -47,15 +47,15 @@ impl Linear {
}
}
-impl Display for Linear {
+impl Debug for Linear {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- write!(f, "{} + {}", self.rel, self.abs)
+ write!(f, "{:?} + {:?}", self.rel, self.abs)
}
}
-impl Debug for Linear {
+impl Display for Linear {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- write!(f, "{:?} + {:?}", self.rel, self.abs)
+ write!(f, "{} + {}", self.rel, self.abs)
}
}
diff --git a/src/geom/relative.rs b/src/geom/relative.rs
index 149c0b9c..7785788c 100644
--- a/src/geom/relative.rs
+++ b/src/geom/relative.rs
@@ -46,15 +46,15 @@ impl Relative {
}
}
-impl Display for Relative {
+impl Debug for Relative {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- write!(f, "{}%", 100.0 * self.get())
+ Display::fmt(self, f)
}
}
-impl Debug for Relative {
+impl Display for Relative {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- Display::fmt(self, f)
+ write!(f, "{}%", 100.0 * self.get())
}
}
diff --git a/src/geom/sides.rs b/src/geom/sides.rs
index f9fdc01f..d4fdf247 100644
--- a/src/geom/sides.rs
+++ b/src/geom/sides.rs
@@ -33,6 +33,14 @@ impl<T> Sides<T> {
}
}
+impl Sides<Length> {
+ /// A size with `left` and `right` summed into `width`, and `top` and
+ /// `bottom` summed into `height`.
+ pub fn size(self) -> Size {
+ Size::new(self.left + self.right, self.top + self.bottom)
+ }
+}
+
impl Sides<Linear> {
/// Resolve the linear sides relative to the given `size`.
pub fn resolve(self, size: Size) -> Sides<Length> {
@@ -45,14 +53,6 @@ impl Sides<Linear> {
}
}
-impl Sides<Length> {
- /// A size with `left` and `right` summed into `width`, and `top` and
- /// `bottom` summed into `height`.
- pub fn size(self) -> Size {
- Size::new(self.left + self.right, self.top + self.bottom)
- }
-}
-
impl<T> Get<Side> for Sides<T> {
type Component = T;