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 serde::{Deserialize, Serialize};
use super::DEFAULT_TOLERANCE;
use crate::{
errors::{KclError, KclErrorDetails},
execution::{
@ -15,7 +16,6 @@ use crate::{
EdgeCut, ExecState, ExtrudeSurface, FilletSurface, GeoMeta, KclValue, Solid, TagIdentifier,
},
parsing::ast::types::TagNode,
settings::types::UnitLength,
std::Args,
SourceRange,
};
@ -165,7 +165,7 @@ async fn inner_fillet(
edge_id,
object_id: solid.id,
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,
// We make this a none so that we can remove it in the future.
face_id: None,
@ -195,17 +195,6 @@ async fn inner_fillet(
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)]
mod tests {
use super::*;

View File

@ -7,11 +7,12 @@ use kcl_derive_docs::stdlib;
use kcmc::{each_cmd as mcmd, length_unit::LengthUnit, ModelingCmd};
use kittycad_modeling_cmds as kcmc;
use super::DEFAULT_TOLERANCE;
use crate::{
errors::{KclError, KclErrorDetails},
execution::{types::RuntimeType, ExecState, KclValue, Sketch, Solid},
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;
@ -159,7 +160,7 @@ async fn inner_loft(
section_ids: sketches.iter().map(|group| group.id).collect(),
base_curve_index,
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,
}),
)

View File

@ -278,6 +278,9 @@ pub enum FunctionKind {
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.
pub async fn leg_length(_exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
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 kittycad_modeling_cmds::{self as kcmc};
use super::DEFAULT_TOLERANCE;
use crate::{
errors::{KclError, KclErrorDetails},
execution::{types::RuntimeType, ExecState, KclValue, Sketch, Solid},
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.
@ -273,9 +274,7 @@ async fn inner_revolve(
target: sketch.id.into(),
axis,
origin,
tolerance: LengthUnit(
tolerance.unwrap_or_else(|| default_tolerance(&exec_state.length_unit().into())),
),
tolerance: LengthUnit(tolerance.unwrap_or(DEFAULT_TOLERANCE)),
axis_is_2d: true,
}),
)
@ -289,9 +288,7 @@ async fn inner_revolve(
angle,
target: sketch.id.into(),
edge_id,
tolerance: LengthUnit(
tolerance.unwrap_or_else(|| default_tolerance(&exec_state.length_unit().into())),
),
tolerance: LengthUnit(tolerance.unwrap_or(DEFAULT_TOLERANCE)),
}),
)
.await?;

View File

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