Skip to content

Commit

Permalink
Stop exporting units via geometry crate and exports mod
Browse files Browse the repository at this point in the history
  • Loading branch information
jacg committed Aug 18, 2022
1 parent 077fe78 commit 1889ec4
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 76 deletions.
2 changes: 0 additions & 2 deletions geometry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@ mod vector;

pub use point::{Point, RatioPoint};
pub use vector::{Vector, RatioVec};
pub use units::Quantity;
pub use units::{Angle, TWOPI, Length, Time, Velocity, Ratio, PerLength, AreaPerMass};

pub mod mix;
2 changes: 1 addition & 1 deletion geometry/src/point.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::ops::{Add, AddAssign, Index, Sub, IndexMut};
use crate::{Length, Ratio};
use units::{Length, Ratio};
use crate::{Vector, RatioVec};

#[derive(Clone, Copy, Debug, PartialEq)]
Expand Down
3 changes: 1 addition & 2 deletions src/bin/foms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ pub struct Cli {

// --------------------------------------------------------------------------------
use std::error::Error;
use units::{Length, mm, mm_};
use petalo::{fom::{InRoiFn, PointValue}, io::raw::Image3D};
use petalo::Intensityf32;
use petalo::{Length};
use petalo::image::Image;
use petalo::fom;
use petalo::fom::{Sphere, ROI, centres_of_slices_closest_to};
use units::{mm, mm_};

fn main() -> Result<(), Box<dyn Error>> {
let args = Cli::from_args();
Expand Down
3 changes: 1 addition & 2 deletions src/bin/imageprimaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ pub struct Cli {

use std::error::Error;
use petalo::Lengthf32;
use petalo::Length;
use units::{mm, mm_};
use units::{Length, mm, mm_};
use petalo::fov::FOV;
use petalo::image::Image;
use petalo::io::hdf5::{read_table, Primary};
Expand Down
3 changes: 1 addition & 2 deletions src/bin/make_sensitivity_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ use std::path::PathBuf;
use petalo::{utils::group_digits, fov::FOV, Lengthf32};
use petalo::image::Image;

use petalo::{Length, Time, AreaPerMass};
use units::{ratio, kg, mm};
use units::{Length, Time, AreaPerMass, ratio, kg, mm};
use units::uom::ConstZero;
use petalo::system_matrix as sm;

Expand Down
3 changes: 2 additions & 1 deletion src/bin/makelor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use std::path::{Path, PathBuf};
use structopt::StructOpt;
use itertools::Itertools;
use indicatif::{ProgressBar, ProgressStyle};
use units::{Length, Time, Ratio};
use petalo::Point;
use petalo::io;
use petalo::io::hdf5::{SensorXYZ, Hdf5Lor};
use petalo::Energyf32;
use petalo::{Length, Time, Point, Ratio};
use units::mmps::f32::Area;
use units::uom::ConstZero;
use petalo::utils::group_digits;
Expand Down
3 changes: 1 addition & 2 deletions src/bin/mlem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ use std::error::Error;
use std::path::PathBuf;
use std::fs::create_dir_all;

use petalo::Length;
use units::{Length, mm_};
use petalo::lorogram::Scattergram;
use petalo::fov::FOV;
use petalo::image::Image;
use petalo::io;
use petalo::utils::timing::Progress;
use units::mm_;


fn main() -> Result<(), Box<dyn Error>> {
Expand Down
2 changes: 1 addition & 1 deletion src/bin/vislor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::error::Error;
use std::path::PathBuf;
use structopt::StructOpt;

use units::{Time, Ratio};
use petalo::Lengthf32;
use petalo::{Time, Ratio};
use petalo::{system_matrix::LOR, fov::FOV};
use petalo::visualize::{lor_weights, Shape};

Expand Down
3 changes: 1 addition & 2 deletions src/config/mlem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use std::path::PathBuf;

use serde::{Deserialize, Deserializer, de};


use crate::{Length, Ratio, Time};
use units::{Length, Ratio, Time};

#[cfg(test)]
fn deserialize_uom_opt<'d, D, T>(deserializer: D) -> Result<Option<T>, D::Error>
Expand Down
44 changes: 4 additions & 40 deletions src/exports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,14 @@ use ncollide3d as nc;

pub use units::uom::si::Quantity;
pub use units::uom::typenum::{Z0, N1};
use units::in_base_unit;

pub type Lengthf32 = f32;
pub use geometry::Length;

pub type PerLength = geometry::PerLength;

pub type Timef32 = f32;
pub use geometry::Time;

pub type Velocity = geometry::Velocity;

pub type Weightf32 = f32; // TODO uom Weight

pub type Ratiof32 = f32;
pub use geometry::Ratio;

pub use geometry::{Angle, TWOPI};
pub type Lengthf32 = f32;
pub type Timef32 = f32;
pub type Weightf32 = f32; // TODO uom Weight
pub type Ratiof32 = f32;
pub type Anglef32 = f32; // TODO eliminate

pub type Energyf32 = f32; // TODO uom Energy
pub type Chargef32 = f32; // TODO uom Charge

pub type Intensityf32 = f32; // TODO uom Intensity

pub use geometry::RatioVec;
Expand All @@ -40,24 +25,3 @@ pub type Point = geometry::Point;
pub use crate::index::{BoxDim_u, Index1_u, Index3_u, Index3Weightf32, LengthI, LengthU};

pub type BoundPair<T> = (std::ops::Bound<T>, std::ops::Bound<T>);

pub use geometry::AreaPerMass;


#[allow(clippy::excessive_precision)]
pub const C: Velocity = in_base_unit!(0.299_792_458);
// `f32` will truncate this to 0.299_792_47

#[cfg(test)]
mod tests {
use super::*;
use units::{m_s_, mm_ps_};
use float_eq::assert_float_eq;

#[test]
fn test_speed_of_light() {
println!("C visual check: {:?}", C);
assert_float_eq!( m_s_(C), 299_792_458.0, ulps <= 1);
assert_float_eq!(mm_ps_(C), 0.299_792_458 , ulps <= 1);
}
}
5 changes: 2 additions & 3 deletions src/fom.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use units::{Length, Quantity};
use crate::io::raw;
use crate::{Intensityf32, Ratiof32};
use crate::{Length, Point};
use geometry::Quantity;
use crate::{Point, Intensityf32, Ratiof32};
use units::ratio_;
use crate::image::{Image, ImageData};
use crate::fov::FOV;
Expand Down
4 changes: 2 additions & 2 deletions src/fov.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/// The size and granularity of the Field of View (FOV) in which images should
/// be reconstructed
use units::{Length, mm_};
use crate::{Lengthf32, Pointf32};
use crate::{Length, Point, Vector, LOR, find_tof_peak, find_entry_point, voxel_size, first_boundaries};
use crate::{Point, Vector, LOR, find_tof_peak, find_entry_point, voxel_size, first_boundaries};
use crate::index::{BoxDim_u, Index3_u, Index1_u, index1_to_3, index3_to_1};
use units::mm_;
use geometry::RatioPoint;
use uom::ConstZero;

Expand Down
7 changes: 3 additions & 4 deletions src/gauss.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::{Angle, Length, PerLength, Ratio, TWOPI, C};
use crate::config::mlem::Tof;

use units::{Angle, Length, PerLength, Ratio, TWOPI, C, mm};
use units::uom::ConstZero; // num_traits::Zero;
use units::mm;

use crate::config::mlem::Tof;

// How would you make this generic over Length -> T ?
fn make_gauss(sigma: Length, cutoff: Option<Ratio>) -> impl Fn(Length) -> PerLength {
Expand Down
2 changes: 1 addition & 1 deletion src/lorogram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::system_matrix::LOR;
use std::f32::consts::TAU;

use crate::Lengthf32;
use crate::{Angle, Length, Time, Ratio};
use units::{Angle, Length, Time, Ratio};
use units::{mm, mm_, ps_, ratio, radian_, turn};


Expand Down
3 changes: 1 addition & 2 deletions src/lorogram/build_scattergram.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::{Length, Time};
use units::{Length, Time, mm, ps};
use crate::lorogram::Scattergram;
use units::{mm, ps};

pub struct BuildScattergram {
phi_bins: Option<usize>,
Expand Down
2 changes: 1 addition & 1 deletion src/mlem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use ndarray::azip;

use rayon::prelude::*;

use units::{Length, PerLength, AreaPerMass};
use crate::{io, Lengthf32, Index1_u, Intensityf32};
use crate::{Length, PerLength, AreaPerMass};
use crate::{fov::{lor_fov_hit, FovHit}, system_matrix::{system_matrix_elements, LOR}};
use crate::fov::FOV;
use crate::gauss::make_gauss_option;
Expand Down
10 changes: 4 additions & 6 deletions src/system_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
//! indices calculated by the algorithm, must be flipped back to the original
//! coordinate system.
use units::in_base_unit;
use units::{C, Length, Ratio, PerLength, Time, in_base_unit};
use units::{mm, mm_, ns_, ratio_};
use crate::{Index3Weightf32, Lengthf32};
use crate::{Length, PerLength, Time, C,
Point, Vector, Ratio, RatioPoint, RatioVec};
use crate::{Point, Vector, RatioPoint, RatioVec};
use crate::fov::FOV;

use units::{mm, mm_, ns_, ratio_};
use crate::gauss::make_gauss_option;
use crate::index::index1_to_3;
use crate::config::mlem::Tof;
Expand All @@ -33,8 +32,7 @@ mod test {
use super::*;
#[allow(unused)] use pretty_assertions::{assert_eq, assert_ne};
use rstest::rstest;
use crate::TWOPI;
use units::ratio;
use units::{TWOPI, ratio};

// --------------------------------------------------------------------------------
// This set of hand-picked values should be easy to verify by humans. The
Expand Down
4 changes: 2 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::error::Error;
use std::ops::{Bound, Range};

use crate::{Timef32, Lengthf32, BoundPair};
use crate::{Point, Ratio};
use units::Ratio;
use crate::{Point, Timef32, Lengthf32, BoundPair};
use crate::system_matrix::LOR;
use units::{mm, ns, ratio};

Expand Down
19 changes: 19 additions & 0 deletions units/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,22 @@ mod tests {
assert_uom_eq!(nanometer, total, mm(11.0), ulps <= 1);
}
}



#[allow(clippy::excessive_precision)]
pub const C: Velocity = in_base_unit!(0.299_792_458);
// `f32` will truncate this to 0.299_792_47

#[cfg(test)]
mod test_speed_of_light {
use super::*;
use float_eq::assert_float_eq;

#[test]
fn test_speed_of_light() {
println!("C visual check: {:?}", C);
assert_float_eq!( m_s_(C), 299_792_458.0, ulps <= 1);
assert_float_eq!(mm_ps_(C), 0.299_792_458 , ulps <= 1);
}
}

0 comments on commit 1889ec4

Please sign in to comment.