Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default tolerance to Core #2440

Merged
merged 4 commits into from
Aug 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions crates/fj-core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,46 @@
//!
//! See [`Core`].

use crate::{layers::Layers, validation::ValidationConfig};
use crate::{
algorithms::approx::Tolerance, layers::Layers, validation::ValidationConfig,
};

/// An instance of the Fornjot core
///
/// This is the main entry point to `fj-core`'s API.
#[derive(Default)]
pub struct Core {
/// The layers of data that make up the state of a core instance
pub layers: Layers,

/// Default tolerance used for intermediate geometry representation
pub default_tolerance: Tolerance,
}

impl Core {
/// Construct an instance of `Instance`
/// Construct an instance of `Core`
pub fn new() -> Self {
Self::default()
Self::from_layers(Layers::default())
}

/// Construct an instance of `Instance`, using the provided configuration
/// Construct an instance of `Core`, using the provided configuration
pub fn with_validation_config(config: ValidationConfig) -> Self {
let layers = Layers::with_validation_config(config);
Self { layers }
Self::from_layers(layers)
}

fn from_layers(layers: Layers) -> Self {
let default_tolerance = Tolerance::from_scalar(0.001)
.expect("Tolerance provided is larger than zero");

Self {
layers,
default_tolerance,
}
}
}

impl Default for Core {
fn default() -> Self {
Self::new()
}
}