summaryrefslogtreecommitdiff
path: root/src/geom.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/geom.rs')
-rw-r--r--src/geom.rs66
1 files changed, 23 insertions, 43 deletions
diff --git a/src/geom.rs b/src/geom.rs
index 5e65446e..77b1ec11 100644
--- a/src/geom.rs
+++ b/src/geom.rs
@@ -16,32 +16,24 @@ pub struct Value2<T> {
impl<T: Clone> Value2<T> {
/// Create a new 2D-value from two values.
- pub fn new(x: T, y: T) -> Value2<T> { Value2 { x, y } }
+ pub fn new(x: T, y: T) -> Self {
+ Self { x, y }
+ }
/// Create a new 2D-value with `x` set to a value and `y` to default.
- pub fn with_x(x: T) -> Value2<T> where T: Default {
- Value2 { x, y: T::default() }
+ pub fn with_x(x: T) -> Self where T: Default {
+ Self { x, y: T::default() }
}
/// Create a new 2D-value with `y` set to a value and `x` to default.
- pub fn with_y(y: T) -> Value2<T> where T: Default {
- Value2 { x: T::default(), y }
- }
-
- /// Create a new 2D-value with the primary axis set to a value and the other
- /// one to default.
- pub fn with_primary(v: T, axes: LayoutAxes) -> Value2<T> where T: Default {
- Value2::with_x(v).generalized(axes)
- }
-
- /// Create a new 2D-value with the secondary axis set to a value and the
- /// other one to default.
- pub fn with_secondary(v: T, axes: LayoutAxes) -> Value2<T> where T: Default {
- Value2::with_y(v).generalized(axes)
+ pub fn with_y(y: T) -> Self where T: Default {
+ Self { x: T::default(), y }
}
/// Create a 2D-value with `x` and `y` set to the same value `s`.
- pub fn with_all(s: T) -> Value2<T> { Value2 { x: s.clone(), y: s } }
+ pub fn with_all(s: T) -> Self {
+ Self { x: s.clone(), y: s }
+ }
/// Get the specificed component.
pub fn get(self, axis: SpecAxis) -> T {
@@ -83,16 +75,16 @@ impl<T: Clone> Value2<T> {
/// axes, that is:
/// - `x` describes the primary axis instead of the horizontal one.
/// - `y` describes the secondary axis instead of the vertical one.
- pub fn generalized(self, axes: LayoutAxes) -> Value2<T> {
+ pub fn generalized(self, axes: LayoutAxes) -> Self {
match axes.primary.axis() {
Horizontal => self,
- Vertical => Value2 { x: self.y, y: self.x },
+ Vertical => Self { x: self.y, y: self.x },
}
}
/// Returns the specialized version of this generalized Size2D (inverse to
/// `generalized`).
- pub fn specialized(self, axes: LayoutAxes) -> Value2<T> {
+ pub fn specialized(self, axes: LayoutAxes) -> Self {
// In fact, generalized is its own inverse. For reasons of clarity
// at the call site, we still have this second function.
self.generalized(axes)
@@ -104,7 +96,7 @@ impl<T: Clone> Value2<T> {
}
}
-impl<T> Debug for Value2<T> where T: Debug {
+impl<T: Debug> Debug for Value2<T> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
f.debug_list()
.entry(&self.x)
@@ -118,16 +110,16 @@ pub type Size = Value2<f64>;
impl Size {
/// The zeroed size.
- pub const ZERO: Size = Size { x: 0.0, y: 0.0 };
+ pub const ZERO: Self = Self { x: 0.0, y: 0.0 };
/// Whether the given size fits into this one, that is, both coordinate
/// values are smaller or equal.
- pub fn fits(self, other: Size) -> bool {
+ pub fn fits(self, other: Self) -> bool {
self.x >= other.x && self.y >= other.y
}
/// Return a size padded by the paddings of the given box.
- pub fn padded(self, padding: Margins) -> Size {
+ pub fn padded(self, padding: Margins) -> Self {
Size {
x: self.x + padding.left + padding.right,
y: self.y + padding.top + padding.bottom,
@@ -135,7 +127,7 @@ impl Size {
}
/// Return a size reduced by the paddings of the given box.
- pub fn unpadded(self, padding: Margins) -> Size {
+ pub fn unpadded(self, padding: Margins) -> Self {
Size {
x: self.x - padding.left - padding.right,
y: self.y - padding.top - padding.bottom,
@@ -147,7 +139,7 @@ impl Size {
///
/// This assumes the size to be generalized such that `x` corresponds to the
/// primary axis.
- pub fn anchor(self, align: LayoutAlign, axes: LayoutAxes) -> Size {
+ pub fn anchor(self, align: LayoutAlign, axes: LayoutAxes) -> Self {
Size {
x: anchor(self.x, align.primary, axes.primary),
y: anchor(self.y, align.secondary, axes.secondary),
@@ -189,17 +181,17 @@ pub struct Value4<T> {
impl<T: Clone> Value4<T> {
/// Create a new box from four sizes.
- pub fn new(left: T, top: T, right: T, bottom: T) -> Value4<T> {
+ pub fn new(left: T, top: T, right: T, bottom: T) -> Self {
Value4 { left, top, right, bottom }
}
/// Create a box with all four fields set to the same value `s`.
- pub fn with_all(value: T) -> Value4<T> {
+ pub fn with_all(value: T) -> Self {
Value4 {
left: value.clone(),
top: value.clone(),
right: value.clone(),
- bottom: value
+ bottom: value,
}
}
@@ -213,7 +205,7 @@ impl<T: Clone> Value4<T> {
}
match dir {
- LTT => &mut self.left,
+ LTR => &mut self.left,
RTL => &mut self.right,
TTB => &mut self.top,
BTT => &mut self.bottom,
@@ -224,18 +216,6 @@ impl<T: Clone> Value4<T> {
pub fn set_all(&mut self, value: T) {
*self = Value4::with_all(value);
}
-
- /// Set the `left` and `right` values.
- pub fn set_horizontal(&mut self, value: T) {
- self.left = value.clone();
- self.right = value;
- }
-
- /// Set the `top` and `bottom` values.
- pub fn set_vertical(&mut self, value: T) {
- self.top = value.clone();
- self.bottom = value;
- }
}
/// A length in four dimensions.