Skip to content

Commit

Permalink
Add more docs. (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
waywardmonkeys authored Aug 22, 2024
1 parent e234d26 commit 65c6eb3
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 41 deletions.
48 changes: 36 additions & 12 deletions src/affine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,81 +156,99 @@ impl Affine {
aff.pre_translate(-point.to_vec2())
}

/// A rotation by `th` followed by `self`.
/// A [rotation] by `th` followed by `self`.
///
/// Equivalent to `self * Affine::rotate(th)`
///
/// [rotation]: Affine::rotate
#[inline]
#[must_use]
pub fn pre_rotate(self, th: f64) -> Self {
self * Affine::rotate(th)
}

/// A rotation by `th` about `center` followed by `self`.
/// A [rotation] by `th` about `center` followed by `self`.
///
/// Equivalent to `self * Affine::rotate_about(th, center)`
///
/// Equivalent to `self * Affine::rotate_about(th)`
/// [rotation]: Affine::rotate_about
#[inline]
#[must_use]
pub fn pre_rotate_about(self, th: f64, center: Point) -> Self {
Affine::rotate_about(th, center) * self
}

/// A scale by `scale` followed by `self`.
/// A [scale] by `scale` followed by `self`.
///
/// Equivalent to `self * Affine::scale(scale)`
///
/// [scale]: Affine::scale
#[inline]
#[must_use]
pub fn pre_scale(self, scale: f64) -> Self {
self * Affine::scale(scale)
}

/// A scale by `(scale_x, scale_y)` followed by `self`.
/// A [scale] by `(scale_x, scale_y)` followed by `self`.
///
/// Equivalent to `self * Affine::scale_non_uniform(scale_x, scale_y)`
///
/// [scale]: Affine::scale_non_uniform
#[inline]
#[must_use]
pub fn pre_scale_non_uniform(self, scale_x: f64, scale_y: f64) -> Self {
self * Affine::scale_non_uniform(scale_x, scale_y)
}

/// A translation of `trans` followed by `self`.
/// A [translation] of `trans` followed by `self`.
///
/// Equivalent to `self * Affine::translate(trans)`
///
/// [translation]: Affine::translate
#[inline]
#[must_use]
pub fn pre_translate(self, trans: Vec2) -> Self {
self * Affine::translate(trans)
}

/// `self` followed by a rotation of `th`.
/// `self` followed by a [rotation] of `th`.
///
/// Equivalent to `Affine::rotate(th) * self`
///
/// [rotation]: Affine::rotate
#[inline]
#[must_use]
pub fn then_rotate(self, th: f64) -> Self {
Affine::rotate(th) * self
}

/// `self` followed by a rotation of `th` about `center`.
/// `self` followed by a [rotation] of `th` about `center`.
///
/// Equivalent to `Affine::rotate_about(th, center) * self`
///
/// [rotation]: Affine::rotate_about
#[inline]
#[must_use]
pub fn then_rotate_about(self, th: f64, center: Point) -> Self {
Affine::rotate_about(th, center) * self
}

/// `self` followed by a scale of `scale`.
/// `self` followed by a [scale] of `scale`.
///
/// Equivalent to `Affine::scale(scale) * self`
///
/// [scale]: Affine::scale
#[inline]
#[must_use]
pub fn then_scale(self, scale: f64) -> Self {
Affine::scale(scale) * self
}

/// `self` followed by a scale of `(scale_x, scale_y)`.
/// `self` followed by a [scale] of `(scale_x, scale_y)`.
///
/// Equivalent to `Affine::scale_non_uniform(scale_x, scale_y) * self`
///
/// [scale]: Affine::scale_non_uniform
#[inline]
#[must_use]
pub fn then_scale_non_uniform(self, scale_x: f64, scale_y: f64) -> Self {
Expand All @@ -240,6 +258,8 @@ impl Affine {
/// `self` followed by a translation of `trans`.
///
/// Equivalent to `Affine::translate(trans) * self`
///
/// [translation]: Affine::translate
#[inline]
#[must_use]
pub fn then_translate(mut self, trans: Vec2) -> Self {
Expand Down Expand Up @@ -297,7 +317,9 @@ impl Affine {
Rect::from_points(p00, p01).union(Rect::from_points(p10, p11))
}

/// Is this map finite?
/// Is this map [finite]?
///
/// [finite]: f64::is_finite
#[inline]
pub fn is_finite(&self) -> bool {
self.0[0].is_finite()
Expand All @@ -308,7 +330,9 @@ impl Affine {
&& self.0[5].is_finite()
}

/// Is this map NaN?
/// Is this map [NaN]?
///
/// [NaN]: f64::is_nan
#[inline]
pub fn is_nan(&self) -> bool {
self.0[0].is_nan()
Expand Down
6 changes: 3 additions & 3 deletions src/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use core::{
#[cfg(not(feature = "std"))]
use crate::common::FloatFuncs;

/// A single arc segment.
/// A single elliptical arc segment.
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand Down Expand Up @@ -80,9 +80,9 @@ impl Arc {
}
}

/// Converts an Arc into a series of cubic bezier segments.
/// Converts an `Arc` into a series of cubic bezier segments.
///
/// Closure will be invoked for each segment.
/// The closure `p` will be invoked with the control points for each segment.
pub fn to_cubic_beziers<P>(self, tolerance: f64, mut p: P)
where
P: FnMut(Point, Point, Point),
Expand Down
16 changes: 12 additions & 4 deletions src/circle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ impl Circle {
}
}

/// Is this circle finite?
/// Is this circle [finite]?
///
/// [finite]: f64::is_finite
#[inline]
pub fn is_finite(&self) -> bool {
self.center.is_finite() && self.radius.is_finite()
}

/// Is this circle NaN?
/// Is this circle [NaN]?
///
/// [NaN]: f64::is_nan
#[inline]
pub fn is_nan(&self) -> bool {
self.center.is_nan() || self.radius.is_nan()
Expand Down Expand Up @@ -224,7 +228,9 @@ impl CircleSegment {
}
}

/// Is this circle segment finite?
/// Is this circle segment [finite]?
///
/// [finite]: f64::is_finite
#[inline]
pub fn is_finite(&self) -> bool {
self.center.is_finite()
Expand All @@ -234,7 +240,9 @@ impl CircleSegment {
&& self.sweep_angle.is_finite()
}

/// Is this circle segment NaN?
/// Is this circle segment [NaN]?
///
/// [NaN]: f64::is_nan
#[inline]
pub fn is_nan(&self) -> bool {
self.center.is_nan()
Expand Down
8 changes: 6 additions & 2 deletions src/ellipse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,17 @@ impl Ellipse {
self.inner.svd()
}

/// Is this ellipse finite?
/// Is this ellipse [finite]?
///
/// [finite]: f64::is_finite
#[inline]
pub fn is_finite(&self) -> bool {
self.inner.is_finite()
}

/// Is this ellipse NaN?
/// Is this ellipse [NaN]?
///
/// [NaN]: f64::is_nan
#[inline]
pub fn is_nan(&self) -> bool {
self.inner.is_nan()
Expand Down
16 changes: 12 additions & 4 deletions src/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ impl Line {
Some(other.p0 + cd * h)
}

/// Is this line finite?
/// Is this line `finite`?
///
/// [finite]: f64::is_finite
#[inline]
pub fn is_finite(self) -> bool {
self.p0.is_finite() && self.p1.is_finite()
}

/// Is this line NaN?
/// Is this line `NaN`?
///
/// [NaN]: f64::is_nan
#[inline]
pub fn is_nan(self) -> bool {
self.p0.is_nan() || self.p1.is_nan()
Expand Down Expand Up @@ -157,13 +161,17 @@ impl ParamCurveExtrema for Line {
pub struct ConstPoint(Point);

impl ConstPoint {
/// Is this point finite?
/// Is this point [finite]?
///
/// [finite]: f64::is_finite
#[inline]
pub fn is_finite(self) -> bool {
self.0.is_finite()
}

/// Is this point NaN?
/// Is this point [NaN]?
///
/// [NaN]: f64::is_nan
#[inline]
pub fn is_nan(self) -> bool {
self.0.is_nan()
Expand Down
22 changes: 16 additions & 6 deletions src/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ impl Rect {
}

/// Returns a new `Rect`,
/// with each coordinate value rounded to the nearest integer.
/// with each coordinate value [rounded] to the nearest integer.
///
/// # Examples
///
Expand All @@ -320,6 +320,8 @@ impl Rect {
/// assert_eq!(rect.x1, 3.0);
/// assert_eq!(rect.y1, -3.0);
/// ```
///
/// [rounded]: f64::round
#[inline]
pub fn round(self) -> Rect {
Rect::new(
Expand All @@ -331,7 +333,7 @@ impl Rect {
}

/// Returns a new `Rect`,
/// with each coordinate value rounded up to the nearest integer,
/// with each coordinate value [rounded up] to the nearest integer,
/// unless they are already an integer.
///
/// # Examples
Expand All @@ -344,6 +346,8 @@ impl Rect {
/// assert_eq!(rect.x1, 3.0);
/// assert_eq!(rect.y1, -3.0);
/// ```
///
/// [rounded up]: f64::ceil
#[inline]
pub fn ceil(self) -> Rect {
Rect::new(
Expand All @@ -355,7 +359,7 @@ impl Rect {
}

/// Returns a new `Rect`,
/// with each coordinate value rounded down to the nearest integer,
/// with each coordinate value [rounded down] to the nearest integer,
/// unless they are already an integer.
///
/// # Examples
Expand All @@ -368,6 +372,8 @@ impl Rect {
/// assert_eq!(rect.x1, 3.0);
/// assert_eq!(rect.y1, -4.0);
/// ```
///
/// [rounded down]: f64::floor
#[inline]
pub fn floor(self) -> Rect {
Rect::new(
Expand Down Expand Up @@ -510,7 +516,7 @@ impl Rect {
}

/// Creates a new [`RoundedRect`] from this `Rect` and the provided
/// corner radius.
/// corner [radius](RoundedRectRadii).
#[inline]
pub fn to_rounded_rect(self, radii: impl Into<RoundedRectRadii>) -> RoundedRect {
RoundedRect::from_rect(self, radii)
Expand Down Expand Up @@ -581,13 +587,17 @@ impl Rect {
}
}

/// Is this rectangle finite?
/// Is this rectangle [finite]?
///
/// [finite]: f64::is_finite
#[inline]
pub fn is_finite(&self) -> bool {
self.x0.is_finite() && self.x1.is_finite() && self.y0.is_finite() && self.y1.is_finite()
}

/// Is this rectangle NaN?
/// Is this rectangle [NaN]?
///
/// [NaN]: f64::is_nan
#[inline]
pub fn is_nan(&self) -> bool {
self.x0.is_nan() || self.y0.is_nan() || self.x1.is_nan() || self.y1.is_nan()
Expand Down
Loading

0 comments on commit 65c6eb3

Please sign in to comment.