use crate::mesh_frame::MeshFrame;
#[derive(Clone, Copy, Debug, PartialEq)]
pub(super) struct RenderFrameRebase {
x: f32,
y: f32,
z: f32,
axes: [f32; 4],
}
impl Default for RenderFrameRebase {
fn default() -> Self {
Self::from_frame(MeshFrame::RawIfc)
}
}
impl RenderFrameRebase {
pub(super) fn from_frame(frame: MeshFrame) -> Self {
let (x, y, z) = frame.rtc_offset();
let x_axis = frame.rotate_into_frame([1.0, 0.0, 0.0]);
let y_axis = frame.rotate_into_frame([0.0, 1.0, 0.0]);
Self {
x: x as f32,
y: y as f32,
z: z as f32,
axes: [
x_axis[0] as f32,
x_axis[1] as f32,
y_axis[0] as f32,
y_axis[1] as f32,
],
}
}
pub(super) fn plan_direction(self, ifc_dx: f32, ifc_dy: f32) -> (f32, f32) {
let (x, y) = self.rotate_plan(ifc_dx, ifc_dy);
(x, -y + 0.0)
}
#[inline]
fn rotate_plan(self, x: f32, y: f32) -> (f32, f32) {
(
self.axes[0] * x + self.axes[2] * y,
self.axes[1] * x + self.axes[3] * y,
)
}
pub(super) fn plan(self, ifc_x: f32, ifc_y: f32) -> (f32, f32) {
let (x, y) = self.rotate_plan(ifc_x - self.x, ifc_y - self.y);
(x, -y + 0.0)
}
pub(super) fn elevation(self, ifc_z: f32) -> f32 {
ifc_z - self.z
}
}
#[cfg(test)]
#[path = "rebase_tests.rs"]
mod rebase_tests;