mooman219 / fontdue

The fastest font renderer in the world, written in pure rust.
Apache License 2.0
1.44k stars 71 forks source link

Add nighly support for constant floating point arithmetic #88

Open deeprobin opened 3 years ago

deeprobin commented 3 years ago

Make functions const, which use floating point arithmetic

Example Proposal

https://github.com/mooman219/fontdue/blob/master/src/font.rs#L45-L53

Before

    #[inline(always)]
    pub fn scale(&self, scale: f32) -> OutlineBounds {
        OutlineBounds {
            xmin: self.xmin * scale,
            ymin: self.ymin * scale,
            width: self.width * scale,
            height: self.height * scale,
        }
    }

After

#![feature(const_fn_floating_point_arithmetic)]
// ...

    pub const fn scale(&self, scale: f32) -> OutlineBounds {
        OutlineBounds {
            xmin: self.xmin * scale,
            ymin: self.ymin * scale,
            width: self.width * scale,
            height: self.height * scale,
        }
    }
mooman219 commented 3 years ago

Something to keep an eye on, but I'm not interested in nightly only features in Fontdue, even if there was a PR for it. Looks promising for when it hits stable.

deeprobin commented 3 years ago

There are still a few things to do in the associated tracking issue (https://github.com/rust-lang/rust/issues/57241), but guess it won't be long before this becomes stable.