Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Asun0204
Copy link

No description provided.

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 {
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Contributor

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.

Copy link
Author

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?

Copy link
Contributor

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.

Copy link
Author

@Asun0204 Asun0204 Jan 10, 2025

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();
Copy link
Contributor

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().

Copy link
Author

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));
Copy link
Contributor

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

Copy link
Author

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

@Asun0204 Asun0204 force-pushed the main branch 2 times, most recently from 4500eb0 to 006b8f8 Compare January 10, 2025 01:11
@Asun0204 Asun0204 changed the title Add from_f32_px_truncated and from_f64_px_truncated methods Add from_f32_px_by_trunc and from_f64_px_by_trunc methods Jan 10, 2025
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 {
Copy link
Contributor

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.

Copy link
Author

Choose a reason for hiding this comment

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

fixed

@Asun0204 Asun0204 changed the title Add from_f32_px_by_trunc and from_f64_px_by_trunc methods Add from_f32_px_trunc and from_f64_px_trunc methods Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants