Skip to content

Commit

Permalink
simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
apparebit committed Aug 14, 2024
1 parent 28ef1ec commit 019f5a1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/core/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ mod oklab {
((a.powi(2) + b.powi(2)).sqrt(), b.atan2(a).to_degrees())
};

let h = if h < 0.0 { h + 360.0 } else { h };
let h = if h.is_sign_negative() { h + 360.0 } else { h };

[L, C, h]
}
Expand Down
51 changes: 25 additions & 26 deletions src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,19 +537,21 @@ impl Color {
/// threshold. Upon violation of this invariant, this method returns the
/// offending threshold as an error object.
///
/// # Algorithmic Considerations
/// # Algorithm
///
/// Unlike [`is_achromatic`](Color::is_achromatic), this method accepts an
/// explicit threshold argument. While that does necessitate testing the
/// argument's sign for all invocations, it addresses a real need for
/// applications such as
/// argument's sign on every single invocation, it also addresses a real
/// need for applications such as
/// [prettypretty.plot](https://github.com/apparebit/prettypretty/blob/main/prettypretty/plot.py)
/// that require consistent but coarse detection of achromatic colors. The
/// plot script graphs colors on the two-dimensional hue-chroma plane of
/// Oklab. Since that places *all* achromatic colors at the same
/// coordinates, the origin, the plot script uses the threshold 𝚾=0.05 so
/// that almost achromatic colors do not form an unsightly blob but rather
/// are pushed to the origin.
/// that require consistent but coarse-grained detection of achromatic
/// colors. The plot script, for instance, scatter-plots colors on the
/// two-dimensional hue-chroma plane of the Oklab variations. Since that
/// would project achromatic colors to the origin and nearly achromatic
/// colors near the origin, the script uses a relatively high threshold,
/// 𝜲=0.05, to prevent a large blob of partially overlappig colors close to
/// the origin. Instead, close-by colors are projected to the origin, which
/// shows only one (average) gray.
///
/// # Examples
///
Expand Down Expand Up @@ -580,28 +582,25 @@ impl Color {
/// Oklrch, converting this color if necessary.
///
/// The threshold must be non-negative, since chroma in Oklch/Oklrch is
/// non-negative and cannot possibly be less than a negative threshold. Upon
/// violation of this invariant, the method returns the offending threshold
/// as an error object.
///
/// # Panics
///
/// Since chroma in Oklch/Oklrch is non-negative and must be less than the
/// threshold, negative threshold values are useless. This method panics if
/// that is the case.
/// non-negative and hence cannot possibly be less equal than a negative
/// threshold. Upon violation of this invariant, this method returns the
/// offending threshold as an error object.
///
/// # Algorithmic Considerations
/// # Algorithm
///
/// Unlike [`is_achromatic`](Color::is_achromatic), this method accepts an
/// explicit threshold argument. While that does necessitate testing the
/// argument's sign, it is directly useful for applications such as
/// argument's sign on every single invocation, it also addresses a real
/// need for applications such as
/// [prettypretty.plot](https://github.com/apparebit/prettypretty/blob/main/prettypretty/plot.py)
/// that require consistent but coarse detection of achromatic colors. The
/// plot script graphs colors on the two-dimensional hue-chroma plane of
/// Oklab. Since that places *all* achromatic colors at the same coordinates,
/// the origin, the plot script uses the threshold 𝚾=0.05 so that almost
/// achromatic colors do not form an unsightly blob but rather are pushed
/// to the origin.
/// that require consistent but coarse-grained detection of achromatic
/// colors. The plot script, for instance, scatter-plots colors on the
/// two-dimensional hue-chroma plane of the Oklab variations. Since that
/// would project achromatic colors to the origin and nearly achromatic
/// colors near the origin, the script uses a relatively high threshold,
/// 𝜲=0.05, to prevent a large blob of partially overlappig colors close to
/// the origin. Instead, close-by colors are projected to the origin, which
/// shows only one (average) gray.
///
/// # Examples
///
Expand Down
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub(crate) trait Environment {
#[inline]
fn is_non_empty(&self, key: &str) -> bool {
let value = self.read_os(key);
value.is_some() && value.unwrap().len() > 0
value.is_some() && !value.unwrap().is_empty()
}

/// Determine whether the environment variable has the given value.
Expand Down

0 comments on commit 019f5a1

Please sign in to comment.