use crate::layout::Face;
pub fn col_to_a(col: u32, width: u32) -> f64 {
2.0 * (col as f64 + 0.5) / width as f64 - 1.0
}
pub fn row_to_b(row: u32, height: u32) -> f64 {
2.0 * (row as f64 + 0.5) / height as f64 - 1.0
}
pub fn face_dir(face: Face, a: f64, b: f64) -> [f64; 3] {
match face {
Face::Front => [-1.0, -a, -b],
Face::Back => [1.0, a, -b],
Face::Left => [-a, 1.0, -b],
Face::Right => [a, -1.0, -b],
Face::Down => [b, -a, -1.0],
Face::Up => [-b, -a, 1.0],
}
}
pub fn dir_to_face_ab(dir: [f64; 3]) -> (Face, f64, f64) {
let [x, y, z] = dir;
let (ax, ay, az) = (x.abs(), y.abs(), z.abs());
if ax >= ay && ax >= az {
if x < 0.0 {
let s = -1.0 / x; (Face::Front, -(y * s), -(z * s))
} else {
let s = 1.0 / x; (Face::Back, y * s, -(z * s))
}
} else if ay >= az {
if y > 0.0 {
let s = 1.0 / y; (Face::Left, -(x * s), -(z * s))
} else {
let s = -1.0 / y; (Face::Right, x * s, -(z * s))
}
} else if z < 0.0 {
let s = -1.0 / z; (Face::Down, -(y * s), x * s)
} else {
let s = 1.0 / z; (Face::Up, -(y * s), -(x * s))
}
}