Add the traits I *want* to be there.

This commit is contained in:
numzero 2024-09-14 22:33:27 +03:00
parent 5b09bb780e
commit 4dcc256127
2 changed files with 30 additions and 0 deletions

29
src/bin/flat/ifaces.rs Normal file
View File

@ -0,0 +1,29 @@
use crate::types::{Hit, Location, Ray};
use glam::Vec2;
pub trait Traceable {
/// Traces a ray from a given starting point. `ray` is relative to the camera.
///
/// Returns all objects the ray touched. `Hit::distance` is along the ray; it may be a rough estimate except, when two objects overlap the difference of corresponding `distance`s shall be correct.
fn trace(&self, camera: Location, ray: Ray) -> Vec<Hit>;
}
pub trait OptimizedTraceable: Traceable {
type State;
/// Prepares tracing from a given starting point. `ray` is relative to the camera.
fn init(&self, camera: Location, ray: Ray) -> Self::State;
/// Similar to [`Traceable::trace`] but allows stopping early.
fn trace(&self, state: Self::State) -> (Option<Self::State>, Vec<Hit>);
}
pub struct RayPath {
pub points: Vec<Vec2>,
pub end_dir: Vec2,
}
pub trait DebugTraceable: Traceable {
/// Identical to [`Traceable::trace`], except also returns the ray path.
fn trace_dbg(&self, camera: Location, ray: Ray) -> (Vec<Hit>, RayPath);
}

View File

@ -14,6 +14,7 @@ use types::{Location, Object, Ray};
mod float_fun; mod float_fun;
mod fns; mod fns;
mod ifaces;
mod riemann; mod riemann;
mod tube; mod tube;
mod types; mod types;