Skip to content

Make NumberOrPercentage and AngleOrNumber getters public. #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,14 +669,17 @@ pub enum NumberOrPercentage {
}

impl NumberOrPercentage {
fn unit_value(&self) -> f32 {
/// Return the value as a percentage.
pub fn unit_value(&self) -> f32 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in the calc() code we call this unitless_value, maybe do the same for consistency?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unit_value comes from Token::Percentage { unit_value, .. }. Consistency can go either way here, so without having to swap the two methods around, because unitless value will now be the "other" one, I'd rather keep it as is for now.

match *self {
NumberOrPercentage::Number { value } => value,
NumberOrPercentage::Percentage { unit_value } => unit_value,
}
}

fn value(&self, percentage_basis: f32) -> f32 {
/// Return the value as a number with a percentage adjusted to the
/// `percentage_basis`.
pub fn value(&self, percentage_basis: f32) -> f32 {
match *self {
Self::Number { value } => value,
Self::Percentage { unit_value } => unit_value * percentage_basis,
Expand All @@ -699,7 +702,9 @@ pub enum AngleOrNumber {
}

impl AngleOrNumber {
fn degrees(&self) -> f32 {
/// Return the angle in degrees. `AngleOrNumber::Number` is returned as
/// degrees, because it is the canonical unit.
pub fn degrees(&self) -> f32 {
match *self {
AngleOrNumber::Number { value } => value,
AngleOrNumber::Angle { degrees } => degrees,
Expand Down