From 0cddb8798d0e823b100d2faecdd4b376a5bd72fa Mon Sep 17 00:00:00 2001 From: numzero Date: Tue, 25 Jun 2024 13:11:27 +0300 Subject: [PATCH] Move basic types to a module --- src/bin/flat/main.rs | 52 ++-------------------------------------- src/bin/flat/tube/mod.rs | 9 +++---- src/bin/flat/types.rs | 50 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 54 deletions(-) create mode 100644 src/bin/flat/types.rs diff --git a/src/bin/flat/main.rs b/src/bin/flat/main.rs index 948b208..38a0621 100644 --- a/src/bin/flat/main.rs +++ b/src/bin/flat/main.rs @@ -7,12 +7,13 @@ mod riemann; mod fns; mod float_fun; mod tube; +mod types; use riemann::{Metric, trace_iter}; -use tube::shape::Shape; use tube::Subspace::{Boundary, Inner, Outer}; use tube::metric::Tube; use tube::Space; +use types::{Location, Object, Ray}; const DT: f32 = 0.1; @@ -104,35 +105,6 @@ pub fn main() { }); } -#[derive(Copy, Clone, Debug)] -pub struct Location { - /// Положение в основной СК - pub pos: Vec2, - /// Преобразование вектора из локальной ортонормированной в основную СК - pub rot: Mat2, -} - -#[derive(Copy, Clone, Debug)] -pub struct Object { - pub id: i32, - pub loc: Location, - pub r: f32, -} - -#[derive(Copy, Clone, Debug)] -pub struct Hit { - pub distance: f32, - pub id: i32, - pub pos: Vec2, // положение в основной СК - pub rel: Ray, // в локальной ортонормированной СК объекта -} - -#[derive(Clone, Debug)] -pub struct FlatTraceResult { - pub end: Option, - pub objects: Vec, -} - fn draw_ray_2(gc: &mut Vec, space: &Space, base: Vec2, dir: Vec2) { let mut hits = Vec::::new(); let dir = space.tube.globalize(base, dir); @@ -277,23 +249,3 @@ impl Renderable for Tube { gc.fill(); } } - -#[derive(Copy, Clone, Debug, PartialEq)] -pub struct Ray { - pub pos: Vec2, - pub dir: Vec2, -} - -impl Ray { - pub fn forward(&self, dist: f32) -> Ray { - Ray { pos: self.pos + self.dir * dist, dir: self.dir } - } -} - -impl std::ops::Mul for Mat2 { - type Output = Ray; - - fn mul(self, rhs: Ray) -> Self::Output { - Ray { pos: self * rhs.pos, dir: self * rhs.dir } - } -} diff --git a/src/bin/flat/tube/mod.rs b/src/bin/flat/tube/mod.rs index c7b1e13..5f50b55 100644 --- a/src/bin/flat/tube/mod.rs +++ b/src/bin/flat/tube/mod.rs @@ -1,9 +1,10 @@ use glam::{bool, f32, Mat2, Vec2, vec2}; -use crate::{FlatTraceResult, Hit, Location, Object, Ray, riemann}; +use crate::riemann; use crate::riemann::Metric; use Subspace::{Boundary, Inner, Outer}; use metric::Tube; use shape::Shape; +use crate::types::{FlatTraceResult, Hit, Location, Object, Ray}; pub mod metric; @@ -164,7 +165,7 @@ impl Space { mod basic_shapes { use glam::{Vec2, vec2}; - use crate::Ray; + use crate::types::Ray; use super::shape::Shape; pub struct Rect { @@ -235,9 +236,9 @@ mod basic_shapes { } } -pub mod shape { +mod shape { use glam::Vec2; - use crate::Ray; + use crate::types::Ray; pub trait Shape { fn is_inside(&self, pt: Vec2) -> bool; diff --git a/src/bin/flat/types.rs b/src/bin/flat/types.rs new file mode 100644 index 0000000..101348a --- /dev/null +++ b/src/bin/flat/types.rs @@ -0,0 +1,50 @@ +use glam::{f32, i32, Mat2, Vec2}; + +#[derive(Copy, Clone, Debug, PartialEq)] +pub struct Ray { + pub pos: Vec2, + pub dir: Vec2, +} + +impl Ray { + pub fn forward(&self, dist: f32) -> Ray { + Ray { pos: self.pos + self.dir * dist, dir: self.dir } + } +} + +impl std::ops::Mul for Mat2 { + type Output = Ray; + + fn mul(self, rhs: Ray) -> Self::Output { + Ray { pos: self * rhs.pos, dir: self * rhs.dir } + } +} + +#[derive(Copy, Clone, Debug)] +pub struct Location { + /// Положение в основной СК + pub pos: Vec2, + /// Преобразование вектора из локальной ортонормированной в основную СК + pub rot: Mat2, +} + +#[derive(Copy, Clone, Debug)] +pub struct Object { + pub id: i32, + pub loc: Location, + pub r: f32, +} + +#[derive(Copy, Clone, Debug)] +pub struct Hit { + pub distance: f32, + pub id: i32, + pub pos: Vec2, // положение в основной СК + pub rel: Ray, // в локальной ортонормированной СК объекта +} + +#[derive(Clone, Debug)] +pub struct FlatTraceResult { + pub end: Option, + pub objects: Vec, +}