-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add from_f32_px_trunc
and from_f64_px_trunc
methods
#60
base: main
Are you sure you want to change the base?
Conversation
src/app_unit.rs
Outdated
@@ -273,6 +273,18 @@ impl Au { | |||
Au::from_f64_au(float) | |||
} | |||
|
|||
#[inline] | |||
pub fn from_f32_px_truncate(px: f32) -> Au { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is already a scale_by_trunc
, so I would call this from_f32_px_trunc
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The input parameter type is dismatch. This is the way that f64 -> f64 * AU_PER_PX -> truncate -> i32
. Instead of scale_by_trunc
complete the way that f64 -> i32 -> f64 -> truncate -> f64 * AU_PER_PX
. Truncate operation should be between AU_PER_PX and i32.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea of what you are trying to say here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean that I would implement scale_by_trunc
method using from_f32_px_trunc
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. I'm only referring to scale_by_trunc
to be consistent with the naming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I know it and the name has been modified.
src/app_unit.rs
Outdated
@@ -273,6 +273,18 @@ impl Au { | |||
Au::from_f64_au(float) | |||
} | |||
|
|||
#[inline] | |||
pub fn from_f32_px_truncate(px: f32) -> Au { | |||
let float = (px * AU_PER_PX as f32).floor(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should use trunc()
instead of floor()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/app_unit.rs
Outdated
@@ -407,6 +419,22 @@ fn convert() { | |||
assert_eq!(Au::from_f64_px(6.), Au(360)); | |||
assert_eq!(Au::from_f64_px(6.12), Au(367)); | |||
assert_eq!(Au::from_f64_px(6.13), Au(368)); | |||
|
|||
assert_eq!(Au::from_f32_px_truncate(5.0), Au(300)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also need to rename these
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry. This fault is fixed and test unit is passed
4500eb0
to
006b8f8
Compare
from_f32_px_truncated
and from_f64_px_truncated
methodsfrom_f32_px_by_trunc
and from_f64_px_by_trunc
methods
src/app_unit.rs
Outdated
@@ -273,6 +273,18 @@ impl Au { | |||
Au::from_f64_au(float) | |||
} | |||
|
|||
#[inline] | |||
pub fn from_f32_px_by_trunc(px: f32) -> Au { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is scale_by
and scale_by_trunc
.
So here it should be from_f32_px
and from_f32_px_trunc
, not from_f32_px_by_trunc
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Signed-off-by: asun0204 <[email protected]>
from_f32_px_by_trunc
and from_f64_px_by_trunc
methodsfrom_f32_px_trunc
and from_f64_px_trunc
methods
No description provided.