Remove single-implementation traits
This commit is contained in:
parent
0cddb8798d
commit
4caa260a34
|
|
@ -3,7 +3,6 @@ use crate::riemann;
|
||||||
use crate::riemann::Metric;
|
use crate::riemann::Metric;
|
||||||
use Subspace::{Boundary, Inner, Outer};
|
use Subspace::{Boundary, Inner, Outer};
|
||||||
use metric::Tube;
|
use metric::Tube;
|
||||||
use shape::Shape;
|
|
||||||
use crate::types::{FlatTraceResult, Hit, Location, Object, Ray};
|
use crate::types::{FlatTraceResult, Hit, Location, Object, Ray};
|
||||||
|
|
||||||
pub mod metric;
|
pub mod metric;
|
||||||
|
|
@ -76,7 +75,7 @@ impl Space {
|
||||||
|
|
||||||
pub fn trace_outer(&self, ray: Ray) -> FlatTraceResult {
|
pub fn trace_outer(&self, ray: Ray) -> FlatTraceResult {
|
||||||
assert_eq!(self.which_subspace(ray.pos), Outer);
|
assert_eq!(self.which_subspace(ray.pos), Outer);
|
||||||
let cell = basic_shapes::Rect { size: vec2(self.tube.outer_radius, self.tube.external_halflength) };
|
let cell = Rect { size: vec2(self.tube.outer_radius, self.tube.external_halflength) };
|
||||||
let objs = self.list_objects_outer();
|
let objs = self.list_objects_outer();
|
||||||
let lim = cell.trace_into(ray);
|
let lim = cell.trace_into(ray);
|
||||||
let dist = lim.unwrap_or(f32::INFINITY);
|
let dist = lim.unwrap_or(f32::INFINITY);
|
||||||
|
|
@ -163,12 +162,7 @@ impl Space {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod basic_shapes {
|
struct Rect {
|
||||||
use glam::{Vec2, vec2};
|
|
||||||
use crate::types::Ray;
|
|
||||||
use super::shape::Shape;
|
|
||||||
|
|
||||||
pub struct Rect {
|
|
||||||
pub size: Vec2,
|
pub size: Vec2,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -177,9 +171,7 @@ mod basic_shapes {
|
||||||
fn flip_ray(ray: Ray) -> Ray {
|
fn flip_ray(ray: Ray) -> Ray {
|
||||||
Ray { pos: ray.pos * ray.dir.signum(), dir: ray.dir.abs() }
|
Ray { pos: ray.pos * ray.dir.signum(), dir: ray.dir.abs() }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl Shape for Rect {
|
|
||||||
fn is_inside(&self, pt: Vec2) -> bool {
|
fn is_inside(&self, pt: Vec2) -> bool {
|
||||||
pt.abs().cmplt(self.size).all()
|
pt.abs().cmplt(self.size).all()
|
||||||
}
|
}
|
||||||
|
|
@ -234,36 +226,17 @@ mod basic_shapes {
|
||||||
assert_eq!(r.trace_out_of(Ray { pos: vec2(1.0, 1.0), dir: vec2(0.0, -1.0) }), Some(4.0));
|
assert_eq!(r.trace_out_of(Ray { pos: vec2(1.0, 1.0), dir: vec2(0.0, -1.0) }), Some(4.0));
|
||||||
assert_eq!(r.trace_out_of(Ray { pos: vec2(2.0, 3.0), dir: vec2(1.0, 1.0) }), Some(0.0));
|
assert_eq!(r.trace_out_of(Ray { pos: vec2(2.0, 3.0), dir: vec2(1.0, 1.0) }), Some(0.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct TubeInside {
|
||||||
|
tube: Tube,
|
||||||
}
|
}
|
||||||
|
|
||||||
mod shape {
|
impl TubeInside {
|
||||||
use glam::Vec2;
|
|
||||||
use crate::types::Ray;
|
|
||||||
|
|
||||||
pub trait Shape {
|
|
||||||
fn is_inside(&self, pt: Vec2) -> bool;
|
|
||||||
|
|
||||||
/// Ищет ближайшее пересечение луча с границей в направлении внутрь контура. Возвращает расстояние (в ray.dir).
|
|
||||||
fn trace_into(&self, ray: Ray) -> Option<f32>;
|
|
||||||
/// Ищет ближайшее пересечение луча с границей в направлении вовне контура. Возвращает расстояние (в ray.dir).
|
|
||||||
fn trace_out_of(&self, ray: Ray) -> Option<f32>;
|
|
||||||
|
|
||||||
/// Возвращает визуальное представление контура, для отладки.
|
|
||||||
fn visualise(&self) -> Vec<Vec2>;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
trait FlatCell: std::fmt::Debug {
|
|
||||||
fn pos_to_global(&self, pos: Vec2) -> Vec2;
|
|
||||||
fn pos_to_local(&self, pos: Vec2) -> Vec2;
|
|
||||||
fn ray_to_global(&self, ray: Ray) -> Ray;
|
|
||||||
fn ray_to_local(&self, ray: Ray) -> Ray;
|
|
||||||
|
|
||||||
fn is_inside(&self, pos: Vec2) -> bool {
|
fn is_inside(&self, pos: Vec2) -> bool {
|
||||||
let bnd = self.local_bounds();
|
let bnd = self.local_bounds();
|
||||||
pos.cmpge(bnd.0).all() && pos.cmple(bnd.1).all()
|
pos.cmpge(bnd.0).all() && pos.cmple(bnd.1).all()
|
||||||
}
|
}
|
||||||
fn local_bounds(&self) -> (Vec2, Vec2);
|
|
||||||
|
|
||||||
fn to_boundary(&self, ray: Ray) -> Option<f32> {
|
fn to_boundary(&self, ray: Ray) -> Option<f32> {
|
||||||
assert!(self.is_inside(ray.pos));
|
assert!(self.is_inside(ray.pos));
|
||||||
|
|
@ -288,14 +261,7 @@ trait FlatCell: std::fmt::Debug {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct TubeInside {
|
|
||||||
tube: Tube,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FlatCell for TubeInside {
|
|
||||||
fn pos_to_global(&self, pos: Vec2) -> Vec2 {
|
fn pos_to_global(&self, pos: Vec2) -> Vec2 {
|
||||||
vec2(pos.x, self.tube.y(pos.y))
|
vec2(pos.x, self.tube.y(pos.y))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user