diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-02-12 18:58:39 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-02-12 19:57:28 +0100 |
| commit | 3ffa7393f0632d9ee5dd9c821685a1a033d5c0ab (patch) | |
| tree | af09b0683352c4028436a2e5251dce54cf41d4aa /src/geom | |
| parent | f4856c18b9cf3f6952276cc61b557aebeb2fa651 (diff) | |
Make all nodes block-level
Diffstat (limited to 'src/geom')
| -rw-r--r-- | src/geom/axes.rs | 20 | ||||
| -rw-r--r-- | src/geom/point.rs | 15 | ||||
| -rw-r--r-- | src/geom/smart.rs | 10 |
3 files changed, 45 insertions, 0 deletions
diff --git a/src/geom/axes.rs b/src/geom/axes.rs index 04023898..48f8c0e8 100644 --- a/src/geom/axes.rs +++ b/src/geom/axes.rs @@ -104,6 +104,16 @@ impl<T: Ord> Axes<T> { pub fn max(self, other: Self) -> Self { Self { x: self.x.max(other.x), y: self.y.max(other.y) } } + + /// The minimum of width and height. + pub fn min_by_side(self) -> T { + self.x.min(self.y) + } + + /// The minimum of width and height. + pub fn max_by_side(self) -> T { + self.x.max(self.y) + } } impl<T> Get<Axis> for Axes<T> { @@ -189,6 +199,16 @@ impl<T> Axes<Option<T>> { } } +impl<T> Axes<Smart<T>> { + /// Unwrap the individual fields. + pub fn unwrap_or(self, other: Axes<T>) -> Axes<T> { + Axes { + x: self.x.unwrap_or(other.x), + y: self.y.unwrap_or(other.y), + } + } +} + impl Axes<bool> { /// Select `t.x` if `self.x` is true and `f.x` otherwise and same for `y`. pub fn select<T>(self, t: Axes<T>, f: Axes<T>) -> Axes<T> { diff --git a/src/geom/point.rs b/src/geom/point.rs index 34d3dcd8..ce3a6ff2 100644 --- a/src/geom/point.rs +++ b/src/geom/point.rs @@ -35,6 +35,16 @@ impl Point { Self { x: Abs::zero(), y } } + /// The component-wise minimum of this and another point. + pub fn min(self, other: Self) -> Self { + Self { x: self.x.min(other.x), y: self.y.min(other.y) } + } + + /// The component-wise minimum of this and another point. + pub fn max(self, other: Self) -> Self { + Self { x: self.x.max(other.x), y: self.y.max(other.y) } + } + /// Transform the point with the given transformation. pub fn transform(self, ts: Transform) -> Self { Self::new( @@ -42,6 +52,11 @@ impl Point { ts.ky.of(self.x) + ts.sy.of(self.y) + ts.ty, ) } + + /// Convert to a size. + pub fn to_size(self) -> Size { + Size::new(self.x, self.y) + } } impl Numeric for Point { diff --git a/src/geom/smart.rs b/src/geom/smart.rs index d20bcdfe..e115e99d 100644 --- a/src/geom/smart.rs +++ b/src/geom/smart.rs @@ -10,6 +10,16 @@ pub enum Smart<T> { } impl<T> Smart<T> { + /// Whether the value is `Auto`. + pub fn is_auto(&self) -> bool { + matches!(self, Self::Auto) + } + + /// Whether this holds a custom value. + pub fn is_custom(&self) -> bool { + matches!(self, Self::Custom(_)) + } + /// Map the contained custom value with `f`. pub fn map<F, U>(self, f: F) -> Smart<U> where |
