Verified Commit 401ee1d3 authored by Jeremy Soller's avatar Jeremy Soller
Browse files

use num-traits for some math

parent 5e0262f3
Pipeline #3196 passed with stages
in 1 minute and 53 seconds
......@@ -13,6 +13,7 @@ exclude = ["/fonts/**"]
[dependencies]
byteorder = { version = "1.3.1", default-features = false }
num-traits = { version = "0.2.6", default-features = false }
[dev-dependencies]
approx = { version = "0.3", default-features = false }
......
......@@ -13,10 +13,12 @@
extern crate alloc;
#[cfg(feature = "no_std")]
extern crate core as std;
extern crate num_traits;
#[cfg(feature = "no_std")]
use alloc::vec::Vec;
use byteorder::{BigEndian as BE, ByteOrder};
use num_traits::float::FloatCore;
use std::ops::Deref;
mod math;
......@@ -1150,10 +1152,10 @@ impl<Data: Deref<Target = [u8]>> FontInfo<Data> {
// move to integral bboxes (treating pixels as little squares, what pixels get
// touched?)
Some(Rect {
x0: math::floor(glyph_box.x0 as f32 * scale_x + shift_x) as i32,
y0: math::floor(-glyph_box.y1 as f32 * scale_y + shift_y) as i32,
x1: math::ceil(glyph_box.x1 as f32 * scale_x + shift_x) as i32,
y1: math::ceil(-glyph_box.y0 as f32 * scale_y + shift_y) as i32,
x0: (glyph_box.x0 as f32 * scale_x + shift_x).floor() as i32,
y0: (-glyph_box.y1 as f32 * scale_y + shift_y).floor() as i32,
x1: (glyph_box.x1 as f32 * scale_x + shift_x).ceil() as i32,
y1: (-glyph_box.y0 as f32 * scale_y + shift_y).ceil() as i32,
})
} else {
// e.g. space character
......
#[cfg(feature = "no_std")]
use core::intrinsics;
#[cfg(not(feature = "no_std"))]
pub fn ceil(n: f32) -> f32 {
n.ceil()
}
#[cfg(feature = "no_std")]
pub fn ceil(n: f32) -> f32 {
unsafe { intrinsics::ceilf32(n) }
}
#[cfg(not(feature = "no_std"))]
pub fn floor(n: f32) -> f32 {
n.floor()
}
#[cfg(feature = "no_std")]
pub fn floor(n: f32) -> f32 {
unsafe { intrinsics::floorf32(n) }
}
#[cfg(not(feature = "no_std"))]
pub fn sqrt(n: f32) -> f32 {
n.sqrt()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment