fontdue icon indicating copy to clipboard operation
fontdue copied to clipboard

Add nighly support for constant floating point arithmetic

Open deeprobin opened this issue 2 years ago • 2 comments

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,
        }
    }

deeprobin avatar Oct 07 '21 18:10 deeprobin

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.

mooman219 avatar Oct 08 '21 21:10 mooman219

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.

deeprobin avatar Oct 08 '21 21:10 deeprobin