notesy::math

Trigonometry, rounding and the like: for drawing an icon's rays or a chart's arcs (notesy::icons), and for numbers that come whole or not (a forecast's 21 and 21.4). Every function takes either, so a script needn't mind which a number is. Angles are in radians. Needs nothing.

rustuse notesy::{canvas, icons, math};

pub fn ready() {
    // A sun: a ring, and eight rays.
    let shapes = [canvas::circle([8.0, 8.0], 3.0)];
    for i in 0..8 {
        let a = math::pi() * math::float(i) / 4.0;
        let x = math::cos(a);
        let y = math::sin(a);
        shapes.push(canvas::line([8.0 + x * 4.6, 8.0 + y * 4.6], [8.0 + x * 6.4, 8.0 + y * 6.4]));
    }
    icons::draw("sun", shapes);
    let highs = [21, 23.6, 19.2];
    let top = math::max(math::max(highs[0], highs[1]), highs[2]);
    let label = `${math::round(top)}°`; // "24°"
}
Function What it gives
math::pi() π
math::sin(a), math::cos(a), math::tan(a) the sine, cosine and tangent of angle a
math::asin(x), math::acos(x), math::atan(x) the angle with that sine, cosine or tangent
math::atan2(y, x) the angle of the point x, y, seen from 0, 0
math::hypot(x, y) how far the point x, y is from 0, 0
math::radians(degrees), math::degrees(radians) an angle, the other way
math::exp(x), math::ln(x), math::log10(x) e to the x, and logarithms
math::round(x), math::floor(x), math::ceil(x) the nearest whole number, the one below, the one above: whole numbers
math::float(x) x as a number with a fraction, whole or not
math::abs(x), math::min(a, b), math::max(a, b), math::clamp(x, low, high) x without its sign, the smaller and the larger, x kept from low to high

Every page