summaryrefslogtreecommitdiff
path: root/src/geom
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-06-13 23:16:40 +0200
committerLaurenz <laurmaedje@gmail.com>2022-06-14 13:53:02 +0200
commitc81e2a5f56eb262663f292578c683fba7f18251f (patch)
tree6c045a8dcbec5e75e01a15f970ef8cee6ff042d0 /src/geom
parent891af17260a6750a74a102388a05e59cf1ffc3c1 (diff)
Many fixes
Diffstat (limited to 'src/geom')
-rw-r--r--src/geom/angle.rs2
-rw-r--r--src/geom/em.rs2
-rw-r--r--src/geom/fraction.rs2
-rw-r--r--src/geom/gen.rs6
-rw-r--r--src/geom/length.rs9
-rw-r--r--src/geom/paint.rs2
-rw-r--r--src/geom/point.rs2
-rw-r--r--src/geom/rect.rs22
-rw-r--r--src/geom/sides.rs11
-rw-r--r--src/geom/spec.rs2
-rw-r--r--src/geom/transform.rs4
11 files changed, 31 insertions, 33 deletions
diff --git a/src/geom/angle.rs b/src/geom/angle.rs
index 888442f7..33a864ca 100644
--- a/src/geom/angle.rs
+++ b/src/geom/angle.rs
@@ -35,7 +35,7 @@ impl Angle {
(self.0).0
}
- /// Get the value of this length in unit.
+ /// Get the value of this angle in a unit.
pub fn to_unit(self, unit: AngleUnit) -> f64 {
self.to_raw() / unit.raw_scale()
}
diff --git a/src/geom/em.rs b/src/geom/em.rs
index ec1cfbda..99b1163c 100644
--- a/src/geom/em.rs
+++ b/src/geom/em.rs
@@ -22,7 +22,7 @@ impl Em {
Self(Scalar(em))
}
- /// Create font units at the given units per em.
+ /// Create an em length from font units at the given units per em.
pub fn from_units(units: impl Into<f64>, units_per_em: f64) -> Self {
Self(Scalar(units.into() / units_per_em))
}
diff --git a/src/geom/fraction.rs b/src/geom/fraction.rs
index a913c0c2..9d4b3aab 100644
--- a/src/geom/fraction.rs
+++ b/src/geom/fraction.rs
@@ -25,7 +25,7 @@ impl Fraction {
(self.0).0
}
- /// The absolute value of the this fraction.
+ /// The absolute value of this fraction.
pub fn abs(self) -> Self {
Self::new(self.get().abs())
}
diff --git a/src/geom/gen.rs b/src/geom/gen.rs
index fc4c56e7..462de357 100644
--- a/src/geom/gen.rs
+++ b/src/geom/gen.rs
@@ -31,7 +31,7 @@ impl<T> Gen<T> {
Gen { cross: f(self.cross), main: f(self.main) }
}
- /// Convert to the specific representation, given the current block axis.
+ /// Convert to the specific representation, given the current main axis.
pub fn to_spec(self, main: SpecAxis) -> Spec<T> {
match main {
SpecAxis::Horizontal => Spec::new(self.main, self.cross),
@@ -82,9 +82,9 @@ impl<T: Debug> Debug for Gen<T> {
/// Two generic axes of a container.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum GenAxis {
- /// The minor axis.
+ /// The minor / inline axis.
Cross,
- /// The major axis.
+ /// The major / block axis.
Main,
}
diff --git a/src/geom/length.rs b/src/geom/length.rs
index 96888764..773fd2fd 100644
--- a/src/geom/length.rs
+++ b/src/geom/length.rs
@@ -10,7 +10,7 @@ impl Length {
Self(Scalar(0.0))
}
- /// The inifinite length.
+ /// The infinite length.
pub const fn inf() -> Self {
Self(Scalar(f64::INFINITY))
}
@@ -50,7 +50,7 @@ impl Length {
(self.0).0
}
- /// Get the value of this length in unit.
+ /// Get the value of this length in a unit.
pub fn to_unit(self, unit: LengthUnit) -> f64 {
self.to_raw() / unit.raw_scale()
}
@@ -75,7 +75,7 @@ impl Length {
self.to_unit(LengthUnit::In)
}
- /// The absolute value of the this length.
+ /// The absolute value of this length.
pub fn abs(self) -> Self {
Self::raw(self.to_raw().abs())
}
@@ -100,7 +100,8 @@ impl Length {
*self = (*self).max(other);
}
- /// Whether the other length fits into this one (i.e. is smaller).
+ /// Whether the other length fits into this one (i.e. is smaller). Allows
+ /// for a bit of slack.
pub fn fits(self, other: Self) -> bool {
self.0 + 1e-6 >= other.0
}
diff --git a/src/geom/paint.rs b/src/geom/paint.rs
index 4a7c9e19..522db1be 100644
--- a/src/geom/paint.rs
+++ b/src/geom/paint.rs
@@ -79,7 +79,7 @@ impl Debug for Color {
}
}
-/// An 8-bit Luma color.
+/// An 8-bit grayscale color.
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
pub struct LumaColor(pub u8);
diff --git a/src/geom/point.rs b/src/geom/point.rs
index dd89fbf5..7f67d353 100644
--- a/src/geom/point.rs
+++ b/src/geom/point.rs
@@ -15,7 +15,7 @@ impl Point {
Self { x: Length::zero(), y: Length::zero() }
}
- /// Create a new point from x and y coordinate.
+ /// Create a new point from x and y coordinates.
pub const fn new(x: Length, y: Length) -> Self {
Self { x, y }
}
diff --git a/src/geom/rect.rs b/src/geom/rect.rs
index 34160b04..dceb3577 100644
--- a/src/geom/rect.rs
+++ b/src/geom/rect.rs
@@ -4,13 +4,15 @@ use std::mem;
/// A rectangle with rounded corners.
#[derive(Debug, Copy, Clone, PartialEq)]
-pub struct Rect {
- size: Size,
- radius: Sides<Length>,
+pub struct RoundedRect {
+ /// The size of the rectangle.
+ pub size: Size,
+ /// The radius at each side.
+ pub radius: Sides<Length>,
}
-impl Rect {
- /// Create a new rectangle.
+impl RoundedRect {
+ /// Create a new rounded rectangle.
pub fn new(size: Size, radius: Sides<Length>) -> Self {
Self { size, radius }
}
@@ -55,7 +57,6 @@ impl Rect {
} else {
let mut paths = self.stroke_segments(Sides::splat(None));
assert_eq!(paths.len(), 1);
-
Geometry::Path(paths.pop().unwrap().0)
}
}
@@ -103,7 +104,7 @@ impl Rect {
}
/// Draws one side of the rounded rectangle. Will always draw the left arc. The
-/// right arc will be drawn halfway iff there is no connection.
+/// right arc will be drawn halfway if and only if there is no connection.
fn draw_side(
path: &mut Path,
side: Side,
@@ -114,7 +115,6 @@ fn draw_side(
) {
let angle_left = Angle::deg(if connection.prev { 90.0 } else { 45.0 });
let angle_right = Angle::deg(if connection.next { 90.0 } else { 45.0 });
-
let length = size.get(side.axis());
// The arcs for a border of the rectangle along the x-axis, starting at (0,0).
@@ -166,9 +166,9 @@ fn draw_side(
}
}
-/// A state machine that indicates which sides of the border strokes in a 2D
-/// polygon are connected to their neighboring sides.
-#[derive(Debug, Default, Copy, Clone, PartialEq, Eq)]
+/// Indicates which sides of the border strokes in a 2D polygon are connected to
+/// their neighboring sides.
+#[derive(Debug, Default, Copy, Clone, Eq, PartialEq)]
struct Connection {
prev: bool,
next: bool,
diff --git a/src/geom/sides.rs b/src/geom/sides.rs
index 43e470d2..938539fe 100644
--- a/src/geom/sides.rs
+++ b/src/geom/sides.rs
@@ -32,7 +32,7 @@ impl<T> Sides<T> {
}
}
- /// Maps the individual fields with `f`.
+ /// Map the individual fields with `f`.
pub fn map<F, U>(self, mut f: F) -> Sides<U>
where
F: FnMut(T) -> U,
@@ -58,12 +58,12 @@ impl<T> Sides<T> {
}
}
- /// Returns an iterator over the sides.
+ /// An iterator over the sides.
pub fn iter(&self) -> impl Iterator<Item = &T> {
[&self.left, &self.top, &self.right, &self.bottom].into_iter()
}
- /// Returns whether all sides are equal.
+ /// Whether all sides are equal.
pub fn is_uniform(&self) -> bool
where
T: PartialEq,
@@ -72,10 +72,7 @@ impl<T> Sides<T> {
}
}
-impl<T> Sides<T>
-where
- T: Add,
-{
+impl<T: Add> Sides<T> {
/// Sums up `left` and `right` into `x`, and `top` and `bottom` into `y`.
pub fn sum_by_axis(self) -> Spec<T::Output> {
Spec::new(self.left + self.right, self.top + self.bottom)
diff --git a/src/geom/spec.rs b/src/geom/spec.rs
index 3fe1793a..e80df870 100644
--- a/src/geom/spec.rs
+++ b/src/geom/spec.rs
@@ -26,7 +26,7 @@ impl<T> Spec<T> {
Self { x: v.clone(), y: v }
}
- /// Maps the individual fields with `f`.
+ /// Map the individual fields with `f`.
pub fn map<F, U>(self, mut f: F) -> Spec<U>
where
F: FnMut(T) -> U,
diff --git a/src/geom/transform.rs b/src/geom/transform.rs
index 40c8e9e4..b82807fd 100644
--- a/src/geom/transform.rs
+++ b/src/geom/transform.rs
@@ -48,8 +48,8 @@ impl Transform {
}
/// Whether this is the identity transformation.
- pub fn is_identity(&self) -> bool {
- *self == Self::identity()
+ pub fn is_identity(self) -> bool {
+ self == Self::identity()
}
/// Pre-concatenate another transformation.