pub enum Unit {
Micron,
Millimeter,
Centimeter,
Inch,
Foot,
Meter,
}Expand description
Units of measurement for the 3MF model.
Defines how vertex coordinates and dimensions are interpreted in real-world measurements. The unit applies to all geometric coordinates in the model (vertices, transformations, radii, etc.).
Per the 3MF specification, the default unit is Millimeter if not specified.
§Examples
use lib3mf_core::model::Unit;
// Default is millimeter
let unit = Unit::default();
assert_eq!(unit, Unit::Millimeter);
// Convert between units
let inches = Unit::Inch.convert(1.0, Unit::Millimeter);
assert!((inches - 25.4).abs() < 1e-5);
// Get scale factor to meters
assert_eq!(Unit::Millimeter.scale_factor(), 0.001);Variants§
Micron
Micrometers - 0.000001 meters (1 μm)
Millimeter
Millimeters - 0.001 meters (1 mm) - Default per 3MF spec
Centimeter
Centimeters - 0.01 meters (1 cm)
Inch
Inches - 0.0254 meters (1 in)
Foot
Feet - 0.3048 meters (1 ft)
Meter
Meters - 1.0 meters (1 m)
Implementations§
Source§impl Unit
impl Unit
Sourcepub fn scale_factor(&self) -> f64
pub fn scale_factor(&self) -> f64
Returns the scale factor to convert this unit to meters.
§Examples
use lib3mf_core::model::Unit;
assert_eq!(Unit::Millimeter.scale_factor(), 0.001);
assert_eq!(Unit::Meter.scale_factor(), 1.0);Sourcepub fn convert(&self, value: f64, target: Unit) -> f64
pub fn convert(&self, value: f64, target: Unit) -> f64
Converts a value from this unit to another target unit.
§Arguments
value- The value in this unittarget- The unit to convert to
§Returns
The value converted to the target unit.
§Examples
use lib3mf_core::model::Unit;
// 1 inch = 25.4 mm
let mm = Unit::Inch.convert(1.0, Unit::Millimeter);
assert!((mm - 25.4).abs() < 1e-5);
// 1000 mm = 1 meter
let m = Unit::Millimeter.convert(1000.0, Unit::Meter);
assert!((m - 1.0).abs() < 1e-5);Trait Implementations§
Source§impl<'de> Deserialize<'de> for Unit
impl<'de> Deserialize<'de> for Unit
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Copy for Unit
impl Eq for Unit
impl StructuralPartialEq for Unit
Auto Trait Implementations§
impl Freeze for Unit
impl RefUnwindSafe for Unit
impl Send for Unit
impl Sync for Unit
impl Unpin for Unit
impl UnwindSafe for Unit
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more