use bevy::prelude::*;

mod basis_f64;
mod vector3_f64;

pub use basis_f64::*;
pub use vector3_f64::*;

pub struct DoublePrecisionPlugin;

impl Plugin for DoublePrecisionPlugin {
    fn build(&self, app: &mut App) {
        app.insert_resource(WorldOffset::default())
            .register_type::<TranslationD>()
            .add_systems(PostUpdate, translation_system);
    }
}

#[derive(Resource, Reflect, Default)]
#[reflect(Resource)]
pub struct WorldOffset(pub Vector3D);

#[derive(Component, Reflect, Default)]
#[reflect(Component)]
pub struct TranslationD(pub Vector3D);

fn translation_system(
    mut query: Query<(&mut Transform, &TranslationD)>,
    world_offset: Res<WorldOffset>,
) {
    for (mut real_transform, translation) in query.iter_mut() {
        real_transform.translation = Vec3::from(translation.0 - world_offset.0);
    }
}
