Remove unused code

This commit is contained in:
numzero 2024-05-27 12:38:36 +03:00
parent 408bd2c936
commit 28a82acbf7

View File

@ -170,7 +170,8 @@ struct Ray {
mod basic_shapes { mod basic_shapes {
use glam::{Vec2, vec2}; use glam::{Vec2, vec2};
use crate::{Ray, shape}; use crate::Ray;
use crate::shape::Shape;
pub struct Rect { pub struct Rect {
pub size: Vec2, pub size: Vec2,
@ -183,7 +184,7 @@ mod basic_shapes {
} }
} }
impl shape::Shape for Rect { 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()
} }
@ -212,9 +213,6 @@ mod basic_shapes {
} }
} }
#[cfg(test)]
use crate::shape::Shape;
#[test] #[test]
fn test_rect() { fn test_rect() {
assert_eq!(Rect::flip_ray(Ray { pos: vec2(2.0, 3.0), dir: vec2(4.0, 5.0) }), Ray { pos: vec2(2.0, 3.0), dir: vec2(4.0, 5.0) }); assert_eq!(Rect::flip_ray(Ray { pos: vec2(2.0, 3.0), dir: vec2(4.0, 5.0) }), Ray { pos: vec2(2.0, 3.0), dir: vec2(4.0, 5.0) });
@ -244,7 +242,7 @@ mod basic_shapes {
} }
mod shape { mod shape {
use glam::{Affine2, Vec2}; use glam::Vec2;
use crate::Ray; use crate::Ray;
pub trait Shape { pub trait Shape {
@ -258,66 +256,6 @@ mod shape {
/// Возвращает визуальное представление контура, для отладки. /// Возвращает визуальное представление контура, для отладки.
fn visualise(&self) -> Vec<Vec2>; fn visualise(&self) -> Vec<Vec2>;
} }
pub struct MovedShape<S: Shape> {
pub shape: S,
pub transform: Affine2, // transform(координаты контура) = 0
}
impl<S: Shape> MovedShape<S> {
fn pt_to_inner(&self, pt: Vec2) -> Vec2 {
self.transform.transform_point2(pt)
}
fn pt_to_outer(&self, pt: Vec2) -> Vec2 {
self.transform.inverse().transform_point2(pt)
}
fn vec_to_inner(&self, vec: Vec2) -> Vec2 {
self.transform.transform_vector2(vec)
}
fn vec_to_outer(&self, vec: Vec2) -> Vec2 {
self.transform.inverse().transform_vector2(vec)
}
fn ray_to_inner(&self, ray: Ray) -> Ray {
Ray { pos: self.pt_to_inner(ray.pos), dir: self.vec_to_inner(ray.dir) }
}
fn ray_to_outer(&self, ray: Ray) -> Ray {
Ray { pos: self.pt_to_outer(ray.pos), dir: self.vec_to_outer(ray.dir) }
}
}
impl<S: Shape> Shape for MovedShape<S> {
fn is_inside(&self, pt: Vec2) -> bool {
self.shape.is_inside(self.pt_to_inner(pt))
}
fn trace_into(&self, ray: Ray) -> Option<f32> {
self.shape.trace_into(self.ray_to_inner(ray))
}
fn trace_out_of(&self, ray: Ray) -> Option<f32> {
self.shape.trace_out_of(self.ray_to_inner(ray))
}
fn visualise(&self) -> Vec<Vec2> {
self.shape.visualise().iter().map(|pt| self.pt_to_outer(*pt)).collect()
}
}
pub struct InvertedShape<S: Shape> {
pub shape: S,
}
impl<S: Shape> Shape for InvertedShape<S> {
fn is_inside(&self, pt: Vec2) -> bool {
!self.shape.is_inside(pt)
}
fn trace_into(&self, ray: Ray) -> Option<f32> {
self.shape.trace_out_of(ray)
}
fn trace_out_of(&self, ray: Ray) -> Option<f32> {
self.shape.trace_into(ray)
}
fn visualise(&self) -> Vec<Vec2> {
self.shape.visualise()
}
}
} }
trait FlatCell: std::fmt::Debug { trait FlatCell: std::fmt::Debug {
@ -357,20 +295,6 @@ trait FlatCell: std::fmt::Debug {
} }
} }
#[derive(Debug)]
struct FlatRect {
min: Vec2,
max: Vec2,
}
impl FlatCell for FlatRect {
fn pos_to_global(&self, pos: Vec2) -> Vec2 { pos }
fn pos_to_local(&self, pos: Vec2) -> Vec2 { pos }
fn ray_to_global(&self, ray: Ray) -> Ray { ray }
fn ray_to_local(&self, ray: Ray) -> Ray { ray }
fn local_bounds(&self) -> (Vec2, Vec2) { (self.min, self.max) }
}
#[derive(Debug)] #[derive(Debug)]
struct RectInside { struct RectInside {
rect: Rect, rect: Rect,