Consolidate Vec/Coord into the geom submodule

Also add the missing coord.rs to version control...
It should have been checked in earlier
This commit is contained in:
2020-09-26 14:09:41 -07:00
parent 452141dd0d
commit d39db969b5
10 changed files with 55 additions and 16 deletions

View File

@@ -1,6 +1,5 @@
use coremem::{consts, Driver, Flt, mat, meas};
use coremem::coord::Coord;
use coremem::geom::{CylinderZ, Vec2};
use coremem::geom::{Coord, CylinderZ, Vec2};
fn main() {
coremem::init_logging();

View File

@@ -1,10 +1,9 @@
use crate::{flt::Flt, mat};
use crate::consts;
use crate::coord::Coord;
use crate::geom::{Coord, Vec3};
use crate::meas::{self, AbstractMeasurement};
use crate::render::{self, MultiRenderer, Renderer};
use crate::sim::{GenericSim as _, SimState};
use crate::vec::Vec3;
use log::{info, trace};
use std::path::PathBuf;

42
src/geom/coord.rs Normal file
View File

@@ -0,0 +1,42 @@
use std::fmt::{self, Display};
#[derive(Copy, Clone, Default, Eq, PartialEq)]
pub struct Coord {
y: u32,
x: u32,
z: u32,
}
impl Coord {
pub fn new(x: u32, y: u32, z: u32) -> Self {
Self {
x,
y,
z,
}
}
pub fn x(&self) -> u32 {
self.x
}
pub fn y(&self) -> u32 {
self.y
}
pub fn z(&self) -> u32 {
self.z
}
/// Convert for use with ndarray indexing
pub(crate) fn row_major_idx(&self) -> [usize; 3] {
[self.z as _, self.y as _, self.x as _]
}
}
impl From<(u32, u32, u32)> for Coord {
fn from((x, y, z): (u32, u32, u32)) -> Self {
Self::new(x, y, z)
}
}
impl Display for Coord {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "({}, {}, {})", self.x, self.y, self.z)
}
}

View File

@@ -1,5 +1,10 @@
mod coord;
mod vec;
pub use coord::Coord;
pub use vec::{Vec2, Vec3};
use crate::flt::{Flt, Real};
pub use crate::vec::{Vec2, Vec3};
use std::fmt::{self, Display};
use std::ops::Add;

View File

@@ -1,5 +1,5 @@
use crate::flt::{Flt, Real};
use crate::coord::Coord;
use super::Coord;
use std::convert::From;
use std::iter::Sum;
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub};

View File

@@ -7,14 +7,12 @@
use log::info;
pub mod coord;
pub mod driver;
pub mod geom;
pub mod mat;
pub mod meas;
pub mod render;
pub mod sim;
pub mod vec;
pub use driver::*;
pub use mat::*;

View File

@@ -1,7 +1,6 @@
use crate::{CellState, consts};
use crate::flt::{Flt, Real};
use crate::geom::{Line2d, Vec2, Polygon2d};
use crate::vec::Vec3;
use crate::geom::{Line2d, Vec2, Vec3, Polygon2d};
use log::{debug, trace};
use enum_dispatch::enum_dispatch;
use std::cmp::Ordering;

View File

@@ -1,6 +1,5 @@
use crate::coord::Coord;
use crate::flt::Flt;
use crate::geom::{Vec3, Region};
use crate::geom::{Coord, Vec3, Region};
use crate::mat::Material as _;
use crate::sim::{Cell, GenericSim};
use std::fmt::Display;

View File

@@ -1,9 +1,8 @@
use ansi_term::Color::RGB;
use crate::geom::Vec2;
use crate::geom::{Vec2, Vec3};
use crate::{flt::{Flt, Real}, Material as _};
use crate::mat;
use crate::sim::{Cell, GenericSim};
use crate::vec::Vec3;
use crate::meas::AbstractMeasurement;
use font8x8::{BASIC_FONTS, GREEK_FONTS, UnicodeFonts as _};
use log::trace;

View File

@@ -1,7 +1,6 @@
use crate::{flt::{Flt, Real}, consts};
use crate::coord::Coord;
use crate::geom::{Coord, Vec3};
use crate::mat::{self, GenericMaterial, Material};
use crate::vec::Vec3;
use log::trace;
use ndarray::{Array3, Zip};