Change default tolerance value to not depend on units (#6055)

This commit is contained in:
Jonathan Tran
2025-03-31 15:28:15 -04:00
committed by GitHub
parent 0b1e79871f
commit d8e84cb5e3
5 changed files with 15 additions and 24 deletions

View File

@ -8,6 +8,7 @@ use kittycad_modeling_cmds as kcmc;
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::DEFAULT_TOLERANCE;
use crate::{ use crate::{
errors::{KclError, KclErrorDetails}, errors::{KclError, KclErrorDetails},
execution::{ execution::{
@ -15,7 +16,6 @@ use crate::{
EdgeCut, ExecState, ExtrudeSurface, FilletSurface, GeoMeta, KclValue, Solid, TagIdentifier, EdgeCut, ExecState, ExtrudeSurface, FilletSurface, GeoMeta, KclValue, Solid, TagIdentifier,
}, },
parsing::ast::types::TagNode, parsing::ast::types::TagNode,
settings::types::UnitLength,
std::Args, std::Args,
SourceRange, SourceRange,
}; };
@ -165,7 +165,7 @@ async fn inner_fillet(
edge_id, edge_id,
object_id: solid.id, object_id: solid.id,
radius: LengthUnit(radius), radius: LengthUnit(radius),
tolerance: LengthUnit(tolerance.unwrap_or_else(|| default_tolerance(&exec_state.length_unit().into()))), tolerance: LengthUnit(tolerance.unwrap_or(DEFAULT_TOLERANCE)),
cut_type: CutType::Fillet, cut_type: CutType::Fillet,
// We make this a none so that we can remove it in the future. // We make this a none so that we can remove it in the future.
face_id: None, face_id: None,
@ -195,17 +195,6 @@ async fn inner_fillet(
Ok(solid) Ok(solid)
} }
pub(crate) fn default_tolerance(units: &UnitLength) -> f64 {
match units {
UnitLength::Mm => 0.0000001,
UnitLength::Cm => 0.0000001,
UnitLength::In => 0.0000001,
UnitLength::Ft => 0.0001,
UnitLength::Yd => 0.001,
UnitLength::M => 0.001,
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;

View File

@ -7,11 +7,12 @@ use kcl_derive_docs::stdlib;
use kcmc::{each_cmd as mcmd, length_unit::LengthUnit, ModelingCmd}; use kcmc::{each_cmd as mcmd, length_unit::LengthUnit, ModelingCmd};
use kittycad_modeling_cmds as kcmc; use kittycad_modeling_cmds as kcmc;
use super::DEFAULT_TOLERANCE;
use crate::{ use crate::{
errors::{KclError, KclErrorDetails}, errors::{KclError, KclErrorDetails},
execution::{types::RuntimeType, ExecState, KclValue, Sketch, Solid}, execution::{types::RuntimeType, ExecState, KclValue, Sketch, Solid},
parsing::ast::types::TagNode, parsing::ast::types::TagNode,
std::{extrude::do_post_extrude, fillet::default_tolerance, Args}, std::{extrude::do_post_extrude, Args},
}; };
const DEFAULT_V_DEGREE: u32 = 2; const DEFAULT_V_DEGREE: u32 = 2;
@ -159,7 +160,7 @@ async fn inner_loft(
section_ids: sketches.iter().map(|group| group.id).collect(), section_ids: sketches.iter().map(|group| group.id).collect(),
base_curve_index, base_curve_index,
bez_approximate_rational, bez_approximate_rational,
tolerance: LengthUnit(tolerance.unwrap_or_else(|| default_tolerance(&exec_state.length_unit().into()))), tolerance: LengthUnit(tolerance.unwrap_or(DEFAULT_TOLERANCE)),
v_degree, v_degree,
}), }),
) )

View File

@ -278,6 +278,9 @@ pub enum FunctionKind {
UserDefined, UserDefined,
} }
/// The default tolerance for modeling commands in [`kittycad_modeling_cmds::length_unit::LengthUnit`].
const DEFAULT_TOLERANCE: f64 = 0.0000001;
/// Compute the length of the given leg. /// Compute the length of the given leg.
pub async fn leg_length(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> { pub async fn leg_length(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
let (hypotenuse, leg, ty) = args.get_hypotenuse_leg()?; let (hypotenuse, leg, ty) = args.get_hypotenuse_leg()?;

View File

@ -5,11 +5,12 @@ use kcl_derive_docs::stdlib;
use kcmc::{each_cmd as mcmd, length_unit::LengthUnit, shared::Angle, ModelingCmd}; use kcmc::{each_cmd as mcmd, length_unit::LengthUnit, shared::Angle, ModelingCmd};
use kittycad_modeling_cmds::{self as kcmc}; use kittycad_modeling_cmds::{self as kcmc};
use super::DEFAULT_TOLERANCE;
use crate::{ use crate::{
errors::{KclError, KclErrorDetails}, errors::{KclError, KclErrorDetails},
execution::{types::RuntimeType, ExecState, KclValue, Sketch, Solid}, execution::{types::RuntimeType, ExecState, KclValue, Sketch, Solid},
parsing::ast::types::TagNode, parsing::ast::types::TagNode,
std::{axis_or_reference::Axis2dOrEdgeReference, extrude::do_post_extrude, fillet::default_tolerance, Args}, std::{axis_or_reference::Axis2dOrEdgeReference, extrude::do_post_extrude, Args},
}; };
/// Revolve a sketch or set of sketches around an axis. /// Revolve a sketch or set of sketches around an axis.
@ -273,9 +274,7 @@ async fn inner_revolve(
target: sketch.id.into(), target: sketch.id.into(),
axis, axis,
origin, origin,
tolerance: LengthUnit( tolerance: LengthUnit(tolerance.unwrap_or(DEFAULT_TOLERANCE)),
tolerance.unwrap_or_else(|| default_tolerance(&exec_state.length_unit().into())),
),
axis_is_2d: true, axis_is_2d: true,
}), }),
) )
@ -289,9 +288,7 @@ async fn inner_revolve(
angle, angle,
target: sketch.id.into(), target: sketch.id.into(),
edge_id, edge_id,
tolerance: LengthUnit( tolerance: LengthUnit(tolerance.unwrap_or(DEFAULT_TOLERANCE)),
tolerance.unwrap_or_else(|| default_tolerance(&exec_state.length_unit().into())),
),
}), }),
) )
.await?; .await?;

View File

@ -7,11 +7,12 @@ use kittycad_modeling_cmds::{self as kcmc};
use schemars::JsonSchema; use schemars::JsonSchema;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::DEFAULT_TOLERANCE;
use crate::{ use crate::{
errors::KclError, errors::KclError,
execution::{types::RuntimeType, ExecState, Helix, KclValue, Sketch, Solid}, execution::{types::RuntimeType, ExecState, Helix, KclValue, Sketch, Solid},
parsing::ast::types::TagNode, parsing::ast::types::TagNode,
std::{extrude::do_post_extrude, fillet::default_tolerance, Args}, std::{extrude::do_post_extrude, Args},
}; };
/// A path to sweep along. /// A path to sweep along.
@ -191,7 +192,7 @@ async fn inner_sweep(
target: sketch.id.into(), target: sketch.id.into(),
trajectory, trajectory,
sectional: sectional.unwrap_or(false), sectional: sectional.unwrap_or(false),
tolerance: LengthUnit(tolerance.unwrap_or_else(|| default_tolerance(&exec_state.length_unit().into()))), tolerance: LengthUnit(tolerance.unwrap_or(DEFAULT_TOLERANCE)),
}), }),
) )
.await?; .await?;