Run rustfmt on the native helpers

[?]
Jul 9, 2021, 4:33 AM
DITZRHVHIYQHZ3HV3VWSRZLAAK4S6NJG33VPHNQ62WCHU46R7RTQC

Dependencies

  • [2] KE43WJL7 Improve provisional colouration function
  • [3] 3AJMKZ7C Model trainer: include land mass calculation in click handler
  • [4] 5AMZXFS5 model trainer: function to generate inputs to pass neural network for rendering equirectangular projection
  • [5] FYOPJXOX Model trainer: North/South comprise the Z axis in the source data
  • [6] 6AXPZL5P Try to offload tight loop to rust (for now it segfaults)
  • [7] E742MTJA Fix segfault (don't pass pointers between functions in different SDL versions), minor refactor
  • [8] ABITXOUU Model trainer: Add provisional colouration

Change contents

  • replacement in trainmodel/src/helpers.rs at line 35
    [4.116][4.1431:1439](),[4.1431][4.1431:1439]()
    extern{
    [4.116]
    [4.1439]
    extern "C" {
  • replacement in trainmodel/src/helpers.rs at line 39
    [4.1603][4.1603:1756]()
    fn c_sdl_create_rgb_surface(flags: u32, width: u32, height: u32, depth: u32, r_mask: u32, g_mask: u32, b_mask: u32, a_mask: u32) -> *mut SDLSurface;
    [4.1603]
    [4.1756]
    fn c_sdl_create_rgb_surface(
    flags: u32,
    width: u32,
    height: u32,
    depth: u32,
    r_mask: u32,
    g_mask: u32,
    b_mask: u32,
    a_mask: u32,
    ) -> *mut SDLSurface;
  • replacement in trainmodel/src/helpers.rs at line 52
    [4.1833][4.1833:1920]()
    unsafe {
    c_sdl_map_rgba(format as *const SDLPixelFormat, r, g, b, a)
    }
    [4.1833]
    [4.1920]
    unsafe { c_sdl_map_rgba(format as *const SDLPixelFormat, r, g, b, a) }
  • replacement in trainmodel/src/helpers.rs at line 56
    [4.1936][4.1936:2046]()
    pub extern "C" fn render_tensor(data: *const u8, width: u32, height: u32, channels: i32) -> *mut SDLSurface {
    [4.1936]
    [4.2046]
    pub extern "C" fn render_tensor(
    data: *const u8,
    width: u32,
    height: u32,
    channels: i32,
    ) -> *mut SDLSurface {
  • replacement in trainmodel/src/helpers.rs at line 68
    [4.2423][4.2423:2822]()
    let pitch = unsafe {
    (*surface).pitch as usize / 4
    };
    let data = unsafe {
    std::slice::from_raw_parts(data, width * height * channels)
    };
    let pixels: &mut [u32] = unsafe {
    std::slice::from_raw_parts_mut((*surface).pixels.cast(), height * pitch)
    };
    let format = unsafe {
    (*surface).format.as_ref().unwrap()
    };
    for y in 0 .. height {
    [4.2423]
    [4.2822]
    let pitch = unsafe { (*surface).pitch as usize / 4 };
    let data = unsafe { std::slice::from_raw_parts(data, width * height * channels) };
    let pixels: &mut [u32] =
    unsafe { std::slice::from_raw_parts_mut((*surface).pixels.cast(), height * pitch) };
    let format = unsafe { (*surface).format.as_ref().unwrap() };
    for y in 0..height {
  • replacement in trainmodel/src/helpers.rs at line 76
    [4.2924][4.2924:2954]()
    for x in 0 .. width {
    [4.2924]
    [4.2954]
    for x in 0..width {
  • replacement in trainmodel/src/helpers.rs at line 96
    [4.3771][4.3771:3839]()
    _ => panic!("We only handle 1, 3, and 4 channels!")
    [4.3771]
    [4.3839]
    _ => panic!("We only handle 1, 3, and 4 channels!"),
  • replacement in trainmodel/src/helpers.rs at line 108
    [4.655][4.655:815]()
    let target = unsafe {
    std::slice::from_raw_parts_mut(target, (width as usize) * (height as usize) * 3)
    };
    for y in 0 .. (height as usize) {
    [4.655]
    [4.815]
    let target =
    unsafe { std::slice::from_raw_parts_mut(target, (width as usize) * (height as usize) * 3) };
    for y in 0..(height as usize) {
  • replacement in trainmodel/src/helpers.rs at line 115
    [4.977][4.977:1018]()
    for x in 0 .. (width as usize) {
    [4.977]
    [4.1018]
    for x in 0..(width as usize) {
  • replacement in trainmodel/src/helpers.rs at line 128
    [4.299][4.299:402](),[4.434][4.434:708]()
    pub extern "C" fn colourize_heightmap(target: *mut f64, source: *const f64, width: u32, height: u32) {
    let target = unsafe {
    std::slice::from_raw_parts_mut(target, (width as usize) * (height as usize) * 3)
    };
    let source = unsafe {
    std::slice::from_raw_parts(source, (width as usize) * (height as usize))
    };
    for y in 0 .. (height as usize) {
    [4.299]
    [4.708]
    pub extern "C" fn colourize_heightmap(
    target: *mut f64,
    source: *const f64,
    width: u32,
    height: u32,
    ) {
    let target =
    unsafe { std::slice::from_raw_parts_mut(target, (width as usize) * (height as usize) * 3) };
    let source =
    unsafe { std::slice::from_raw_parts(source, (width as usize) * (height as usize)) };
    for y in 0..(height as usize) {
  • replacement in trainmodel/src/helpers.rs at line 144
    [4.872][4.872:913]()
    for x in 0 .. (width as usize) {
    [4.872]
    [4.913]
    for x in 0..(width as usize) {
  • replacement in trainmodel/src/helpers.rs at line 147
    [4.982][4.982:1054]()
    let (r,g,b) = if s > snow_line {
    (1.,1.,1.)
    [4.982]
    [4.1054]
    let (r, g, b) = if s > snow_line {
    (1., 1., 1.)
  • replacement in trainmodel/src/helpers.rs at line 150
    [4.1092][2.0:42]()
    (s.powf(0.6),0.9,s * 0.5)
    [4.1092]
    [4.1151]
    (s.powf(0.6), 0.9, s * 0.5)
  • replacement in trainmodel/src/helpers.rs at line 152
    [4.1172][2.43:80]()
    (0.,0.,s * 4. + 0.4)
    [4.1172]
    [4.1200]
    (0., 0., s * 4. + 0.4)
  • replacement in trainmodel/src/helpers.rs at line 163
    [3.294][3.294:402]()
    pub extern "C" fn landmass_steradians(source: *const f64, width: u32, height: u32, x: u32, y: u32) -> f64 {
    [3.294]
    [3.402]
    pub extern "C" fn landmass_steradians(
    source: *const f64,
    width: u32,
    height: u32,
    x: u32,
    y: u32,
    ) -> f64 {
  • replacement in trainmodel/src/helpers.rs at line 174
    [3.538][3.538:652]()
    let source = unsafe {
    std::slice::from_raw_parts(source, (width as usize) * (height as usize))
    };
    [3.538]
    [3.652]
    let source =
    unsafe { std::slice::from_raw_parts(source, (width as usize) * (height as usize)) };
  • replacement in trainmodel/src/helpers.rs at line 178
    [3.721][3.721:789]()
    q.push_back((x,y));
    while let Some((x,y)) = q.pop_front() {
    [3.721]
    [3.789]
    q.push_back((x, y));
    while let Some((x, y)) = q.pop_front() {
  • replacement in trainmodel/src/helpers.rs at line 181
    [3.848][3.848:885]()
    if patch.insert((x,y)) {
    [3.848]
    [3.885]
    if patch.insert((x, y)) {
  • replacement in trainmodel/src/helpers.rs at line 184
    [3.953][3.953:1105]()
    for (x, y) in [(x - 1, y - 1), (x, y - 1), (x + 1, y - 1), (x + 1, y), (x + 1, y + 1), (x, y + 1), (x - 1, y + 1), (x - 1, y)].iter() {
    [3.953]
    [3.1105]
    for (x, y) in [
    (x - 1, y - 1),
    (x, y - 1),
    (x + 1, y - 1),
    (x + 1, y),
    (x + 1, y + 1),
    (x, y + 1),
    (x - 1, y + 1),
    (x - 1, y),
    ]
    .iter()
    {
  • replacement in trainmodel/src/helpers.rs at line 203
    [4.1271][3.1330:1337]()
    };
    [4.1271]
    [3.1337]
    }
  • replacement in trainmodel/src/helpers.rs at line 206
    [3.1415][3.1415:1535]()
    for (_,y) in patch.iter() {
    lines.entry(*y)
    .and_modify(|w| *w += 1)
    .or_insert(1);
    [3.1415]
    [4.1271]
    for (_, y) in patch.iter() {
    lines.entry(*y).and_modify(|w| *w += 1).or_insert(1);
  • replacement in trainmodel/src/helpers.rs at line 212
    [3.1637][3.1637:1722]()
    lines.iter().map(|(y,w)| dy * ((*y as f64) * dy).sin() * (*w as f64) * dx).sum()
    [3.1637]
    [4.1277]
    lines
    .iter()
    .map(|(y, w)| dy * ((*y as f64) * dy).sin() * (*w as f64) * dx)
    .sum()