const DEFAULT_RENDERING_PRECISION: f64 = 0.1;
mod boolean_op;
pub mod error;
pub mod geo2d;
#[cfg(feature = "geo3d")]
pub mod geo3d;
pub type Integer = i64;
pub type Scalar = f64;
pub type Vec2 = cgmath::Vector2<Scalar>;
pub type Vec3 = cgmath::Vector3<Scalar>;
pub type Vec4 = cgmath::Vector4<Scalar>;
pub type Mat2 = cgmath::Matrix2<Scalar>;
pub type Mat3 = cgmath::Matrix3<Scalar>;
pub type Mat4 = cgmath::Matrix4<Scalar>;
pub type Angle = cgmath::Rad<Scalar>;
pub type Id = compact_str::CompactString;
pub use boolean_op::BooleanOp;
pub use error::*;
pub trait Depth {
fn depth(&self) -> usize;
}
pub trait RenderHash {
fn render_hash(&self) -> Option<u64> {
None
}
}
pub trait Renderer {
fn precision(&self) -> crate::Scalar;
fn change_render_state(&mut self, _: &str, _: &str) -> CoreResult<()> {
Ok(())
}
}
pub type Renderer2D = dyn geo2d::Renderer;
pub type Renderer3D = dyn geo3d::Renderer;
pub type Primitive2D = dyn geo2d::Primitive;
pub type Primitive3D = dyn geo3d::Primitive;
#[derive(Debug, Default, Clone)]
pub struct ExportSettings(toml::Table);
impl std::ops::Deref for ExportSettings {
type Target = toml::Table;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl std::ops::DerefMut for ExportSettings {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl ExportSettings {
pub fn with_filename(filename: String) -> Self {
let mut settings = ExportSettings::default();
settings.insert("filename".to_string(), toml::Value::String(filename));
settings
}
pub fn filename(&self) -> Option<&str> {
self.get("filename").and_then(|filename| filename.as_str())
}
pub fn render_precision(&self) -> CoreResult<f64> {
if let Some(precision) = self.0.get("render_precision") {
if let Some(precision) = precision.as_float() {
Ok(precision)
} else {
Err(CoreError::InvalidRenderPrecision(precision.to_string()))
}
} else {
Ok(DEFAULT_RENDERING_PRECISION)
}
}
pub fn exporter_id(&self) -> Option<String> {
if let Some(exporter) = self.0.get("exporter") {
Some(exporter.to_string())
} else if let Some(filename) = self.filename() {
std::path::Path::new(&filename)
.extension()
.and_then(std::ffi::OsStr::to_str)
.map(|f| f.to_string())
} else {
None
}
}
}
#[test]
fn export_settings() {
let export_settings = ExportSettings::with_filename("test.stl".into());
assert_eq!(export_settings.filename(), Some("test.stl"));
assert_eq!(export_settings.exporter_id(), Some("stl".into()))
}