#[derive(Debug, thiserror::Error)]
pub enum WasmError {
#[error("invalid {entity} handle: index {index} is out of bounds")]
InvalidHandle {
entity: &'static str,
index: usize,
},
#[error("invalid input: {reason}")]
InvalidInput {
reason: String,
},
#[error(transparent)]
Operations(#[from] brepkit_operations::OperationsError),
#[error(transparent)]
Topology(#[from] brepkit_topology::TopologyError),
#[error(transparent)]
Math(#[from] brepkit_math::MathError),
}
pub fn validate_finite(value: f64, name: &str) -> Result<(), WasmError> {
value
.is_finite()
.then_some(())
.ok_or_else(|| WasmError::InvalidInput {
reason: format!("{name} must be finite, got {value}"),
})
}
pub fn validate_positive(value: f64, name: &str) -> Result<(), WasmError> {
validate_finite(value, name)?;
(value > 0.0)
.then_some(())
.ok_or_else(|| WasmError::InvalidInput {
reason: format!("{name} must be positive, got {value}"),
})
}