ULTCAN.COM

Tritium demos paper_plane Contact Us

paper_plane · Rust

tritium demo paper_plane
transcript · python · c · rust

Download
// TRITIUM-PROVENANCE sha256=7ab3f2fa4f8df8640be261938568a4bd5a768201d8fa662258c66b76d58f2c1d lang=rust
// TRITIUM-HEIGHT high=1.00 mid=0.00 low=0.00
fn fsin(x: f64) -> f64 {

    let mut pi = 3.141592653589793;
    let mut two = 6.283185307179586;
    let mut i = x;
    while i > pi {
        i = i - two;
    }
    while i <= (-pi) {
        i = i + two;
    }
    let mut x_7 = i * i;
    let mut x_2 = x_7 * 2.7557319223985893e-06;
    let mut x_4 = -0.0001984126984126984 + x_2;
    let mut x_6 = 0.008333333333333333 + (x_7 * x_4);
    let mut x_3 = -0.16666666666666666 + (x_7 * x_6);
    let mut x_5 = 1.0 + (x_7 * x_3);
    i * x_5
}

fn fcos(x: f64) -> f64 {

    let mut pi = 3.141592653589793;
    let mut two = 6.283185307179586;
    let mut i = x;
    while i > pi {
        i = i - two;
    }
    while i <= (-pi) {
        i = i + two;
    }
    let mut x_7 = i * i;
    let mut x_2 = x_7 * 2.48015873015873e-05;
    let mut x_5 = -0.001388888888888889 + x_2;
    let mut x_4 = 0.041666666666666664 + (x_7 * x_5);
    let mut x_6 = -0.5 + (x_7 * x_4);
    let mut x_3 = 1.0 + (x_7 * x_6);
    x_3
}

fn fsqrt(x: f64) -> f64 {
    let mut i = 0;
    let mut i_2 = 0.0;
    let mut x_2 = 0.0;

    let mut fcmp4 = ((x) <= (0.0)) as i64;
    if (fcmp4) != 0 {
        return 0.0;
    } else {
        i_2 = x;
        i = 0;
        while i < 8 {
            x_2 = 0.5 * (i_2 + (x / i_2));
            i_2 = x_2;
            i += 1;
        }
        return i_2;
    }
}

fn haversine_f(lat1: f64, lon1: f64, lat2: f64, lon2: f64) -> f64 {

    let mut x_2 = (lat2 - lat1) / 2.0;
    let mut aa = fsin(x_2);
    let mut x_3 = (lon2 - lon1) / 2.0;
    let mut bb = fsin(x_3);
    let mut h = ((aa * aa) + (((fcos(lat1) * (fcos(lat2))) * bb) * bb));
    let mut x = 2.0 * (fsqrt(h));
    x
}

fn haversine_km_f(lat1: f64, lon1: f64, lat2: f64, lon2: f64) -> f64 {

    let mut x = 6371.0 * (haversine_f(lat1, lon1, lat2, lon2));
    x
}

fn _atan_unit(a: f64) -> f64 {
    let mut x_3 = 0.0;
    let mut x_8 = 0.0;
    let mut x_2 = 0.0;

    let mut t8 = 0.41421356237309503;
    let mut folded = 0;
    let mut i = a;
    let mut fcmp9 = ((i) > (t8)) as i64;
    if (fcmp9) != 0 {
        x_3 = 1.0 - i;
        x_8 = 1.0 + i;
        i = x_3 / x_8;
        folded = 1;
    }
    let mut x_4 = i * i;
    let mut x_7 = x_4 * -0.09090909090909091;
    let mut x_5 = 0.1111111111111111 + x_7;
    let mut x_6 = -0.14285714285714285 + (x_4 * x_5);
    let mut x_9 = 0.2 + (x_4 * x_6);
    let mut x_11 = -0.3333333333333333 + (x_4 * x_9);
    let mut x = 1.0 + (x_4 * x_11);
    let mut x_10 = i * x;
    if folded == 1 {
        x_2 = 0.7853981633974483 - x_10;
        x_10 = x_2;
    }
    x_10
}

fn fatan_poly(z: f64) -> f64 {
    let mut x_4 = 0.0;
    let mut x = 0.0;
    let mut x_3 = 0.0;
    let mut x_2 = 0.0;

    let mut neg = 0;
    let mut i = z;
    let mut fcmp7 = ((i) < (0.0)) as i64;
    if (fcmp7) != 0 {
        x_4 = 0.0 - i;
        i = x_4;
        neg = 1;
    }
    let mut swapped = 0;
    let mut fcmp11 = ((i) > (1.0)) as i64;
    if (fcmp11) != 0 {
        x = 1.0 / i;
        i = x;
        swapped = 1;
    }
    let mut r = _atan_unit(i);
    if swapped == 1 {
        x_3 = 1.5707963267948966 - r;
        r = x_3;
    }
    if neg == 1 {
        x_2 = 0.0 - r;
        r = x_2;
    }
    r
}

fn fatan2(y: f64, x: f64) -> f64 {
    let mut x_7 = 0.0;
    let mut x_2 = 0.0;
    let mut fcmp18 = 0;
    let mut fatan_poly_2 = 0.0;
    let mut fcmp25 = 0;
    let mut x_5 = 0.0;
    let mut fcmp34 = 0;
    let mut x_3 = 0.0;
    let mut x_6 = 0.0;
    let mut fcmp40 = 0;
    let mut x_4 = 0.0;

    let mut i = y;
    let mut fcmp6 = ((i) < (0.0)) as i64;
    if (fcmp6) != 0 {
        x_7 = 0.0 - i;
        i = x_7;
    }
    let mut i_2 = x;
    let mut fcmp11 = ((i_2) < (0.0)) as i64;
    if (fcmp11) != 0 {
        x_2 = 0.0 - i_2;
        i_2 = x_2;
    }
    let mut fcmp16 = ((i_2) >= (i)) as i64;
    if (fcmp16) != 0 {
        fcmp18 = ((i_2) == (0.0)) as i64;
        if (fcmp18) != 0 {
            return 0.0;
        } else {
            fatan_poly_2 = fatan_poly(i / i_2);
        }
    } else {
        fcmp25 = ((i) == (0.0)) as i64;
        if (fcmp25) != 0 {
            return 0.0;
        } else {
            x_5 = 1.5707963267948966 - (fatan_poly(i_2 / i));
            fatan_poly_2 = x_5;
        }
    }
    let mut fcmp32 = ((x) < (0.0)) as i64;
    if (fcmp32) != 0 {
        fcmp34 = ((y) < (0.0)) as i64;
        if (fcmp34) != 0 {
            x_3 = fatan_poly_2 - 3.141592653589793;
            return x_3;
        } else {
            x_6 = 3.141592653589793 - fatan_poly_2;
            return x_6;
        }
    } else {
        fcmp40 = ((y) < (0.0)) as i64;
        if (fcmp40) != 0 {
            x_4 = 0.0 - fatan_poly_2;
            return x_4;
        } else {
            return fatan_poly_2;
        }
    }
}

fn bearing_f(lat1: f64, lon1: f64, lat2: f64, lon2: f64) -> f64 {

    let mut l2 = lon2;
    let mut l1 = lon1;
    let mut dl = l2 - l1;
    let mut dlon1 = dl;
    let mut sd = fsin(dlon1);
    let mut lat2a = lat2;
    let mut cl2 = fcos(lat2a);
    let mut ya = sd * cl2;
    let mut lat1a = lat1;
    let mut cl1 = fcos(lat1a);
    let mut lat2b = lat2;
    let mut sl2 = fsin(lat2b);
    let mut t1 = cl1 * sl2;
    let mut lat1b = lat1;
    let mut sl1 = fsin(lat1b);
    let mut lat2c = lat2;
    let mut cl2b = fcos(lat2c);
    let mut dlon2 = dl;
    let mut cd = fcos(dlon2);
    let mut t2a = sl1 * cl2b;
    let mut t2 = t2a * cd;
    let mut xa = t1 - t2;
    let mut yy = ya;
    let mut xx = xa;
    let mut br = fatan2(yy, xx);
    br
}

fn bearing_deg_f(lat1: f64, lon1: f64, lat2: f64, lon2: f64) -> f64 {
    let mut x_2 = 0.0;
    let mut x = 0.0;

    let mut br = bearing_f(lat1, lon1, lat2, lon2);
    let mut x_3 = br * 57.29577951308232;
    while x_3 < 0.0 {
        x_2 = x_3 + 360.0;
        x_3 = x_2;
    }
    while x_3 >= 360.0 {
        x = x_3 - 360.0;
        x_3 = x;
    }
    x_3
}

fn interest_radius_f(dx: f64, dy: f64, r: f64) -> i64 {

    let mut fcmp13 = ((((dx * dx) + (dy * dy))) <= (r * r)) as i64;
    if (fcmp13) != 0 { 1 } else { 0 }
}

fn mmog_interest_filter(vals: &mut [f64], ys: &mut [f64], n: i64, cx: f64, cy: f64, r: f64, out: &mut [i64]) -> i64 {
    let mut fcmp27 = 0;

    let mut m = 0;
    let mut i = 0;
    while i < n {
        fcmp27 = (((interest_radius_f((vals[i as usize] - cx), (ys[i as usize] - cy), r))) == 1) as i64;
        if (fcmp27) != 0 {
            out[m as usize] = i;
            m += 1;
        }
        i += 1;
    }
    m
}

fn mmog_tick_rate_ok(last_ms: i64, now_ms: i64, min_dt: i64) -> i64 {

    if (now_ms - last_ms) >= min_dt { 1 } else { 0 }
}

fn transform3d(x: f64, y: f64, z: f64, r00: f64, r01: f64, r02: f64, r10: f64, r11: f64, r12: f64, r20: f64, r21: f64, r22: f64, tx: f64, ty: f64, tz: f64, out: &mut [f64]) -> i64 {

    out[0] = ((((r00 * x) + (r01 * y)) + (r02 * z)) + tx);
    out[1] = ((((r10 * x) + (r11 * y)) + (r12 * z)) + ty);
    out[2] = ((((r20 * x) + (r21 * y)) + (r22 * z)) + tz);
    1
}

fn project3d(x: f64, y: f64, z: f64, f: f64, out: &mut [f64]) -> i64 {

    let mut fcmp6 = ((z) == (0.0)) as i64;
    if (fcmp6) != 0 {
        out[0] = 0.0;
        out[1] = 0.0;
        return 0;
    } else {
        out[0] = ((f * x) / z);
        out[1] = ((f * y) / z);
        return 1;
    }
}

fn viewport(u: f64, v: f64, w: f64, h: f64, out: &mut [f64]) -> i64 {

    let mut x_4 = u + 1.0;
    let mut x_3 = x_4 * 0.5;
    out[0] = x_3 * w;
    let mut x = 1.0 - v;
    let mut x_2 = x * 0.5;
    out[1] = x_2 * h;
    1
}
ULTCAN.COM