Skip to content

Commit 402f68f

Browse files
committed
Address code review from Jon
1 parent 5d63f3d commit 402f68f

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

rust/kcl-lib/src/execution/exec_ast.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ use crate::std::args::FromKclValue;
103103
use crate::std::args::TyF64;
104104
use crate::std::shapes::SketchOrSurface;
105105
use crate::std::sketch::ensure_sketch_plane_in_engine;
106+
use crate::std::sketch2::SOLVER_CONVERGENCE_TOLERANCE;
106107
use crate::std::sketch2::create_segments_in_engine;
107108

108109
fn internal_err(message: impl Into<String>, range: impl Into<SourceRange>) -> KclError {
@@ -1406,7 +1407,9 @@ impl Node<SketchBlock> {
14061407
})
14071408
.collect::<Result<Vec<_>, KclError>>()?;
14081409
// Solve constraints.
1409-
let config = ezpz::Config::default().with_max_iterations(50);
1410+
let config = ezpz::Config::default()
1411+
.with_max_iterations(50)
1412+
.with_convergence_tolerance(SOLVER_CONVERGENCE_TOLERANCE);
14101413
let solve_result = if exec_state.mod_local.freedom_analysis {
14111414
ezpz::solve_analysis(&constraints, initial_guesses.clone(), config).map(|outcome| {
14121415
let freedom_analysis = FreedomAnalysis::from_ezpz_analysis(outcome.analysis, constraints.len());

rust/kcl-lib/src/std/sketch2.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ use crate::front::ObjectId;
3838
use crate::parsing::ast::types::TagNode;
3939
use crate::std::Args;
4040
use crate::std::CircularDirection;
41-
use crate::std::DEFAULT_TOLERANCE_MM;
4241
use crate::std::args::FromKclValue;
4342
use crate::std::args::TyF64;
4443
use crate::std::sketch::StraightLineParams;
@@ -52,6 +51,8 @@ use crate::std::utils::untype_point;
5251
use crate::std::utils::untyped_point_to_mm;
5352
use crate::std_utils::untyped_point_to_unit;
5453

54+
pub const SOLVER_CONVERGENCE_TOLERANCE: f64 = 1e-8;
55+
5556
/// Create the Sketch and send to the engine. Return will be None if there are
5657
/// no segments.
5758
pub(crate) async fn create_segments_in_engine(
@@ -104,9 +105,9 @@ pub(crate) async fn create_segments_in_engine(
104105
let entry_point = match &segment.kind {
105106
SegmentKind::Line { end, .. } | SegmentKind::Arc { end, .. } => {
106107
let reverse_start_mm = point_to_mm(end.clone());
107-
if distance(forward_start_mm, current_pen_mm) <= DEFAULT_TOLERANCE_MM {
108+
if distance(forward_start_mm, current_pen_mm) <= SOLVER_CONVERGENCE_TOLERANCE {
108109
forward_start.clone()
109-
} else if distance(reverse_start_mm, current_pen_mm) <= DEFAULT_TOLERANCE_MM {
110+
} else if distance(reverse_start_mm, current_pen_mm) <= SOLVER_CONVERGENCE_TOLERANCE {
110111
traversal = SegmentTraversal::Reverse;
111112
end.clone()
112113
} else {
@@ -120,7 +121,7 @@ pub(crate) async fn create_segments_in_engine(
120121

121122
// If the next segment already starts where the pen is, preserve continuity by
122123
// skipping both the engine pen move and the synthetic bookkeeping jump.
123-
if distance(entry_point_mm, current_pen_mm) > DEFAULT_TOLERANCE_MM {
124+
if distance(entry_point_mm, current_pen_mm) > SOLVER_CONVERGENCE_TOLERANCE {
124125
let id = exec_state.next_uuid();
125126
if !exec_state.sketch_mode() {
126127
exec_state
@@ -190,13 +191,10 @@ pub(crate) async fn create_segments_in_engine(
190191
debug_assert!(false, "Points should have been skipped earlier");
191192
continue;
192193
}
193-
SegmentKind::Line { end, .. } => {
194+
SegmentKind::Line { end, start, .. } => {
194195
let to = match traversal {
195196
SegmentTraversal::Forward => end.clone(),
196-
SegmentTraversal::Reverse => match &segment.kind {
197-
SegmentKind::Line { start, .. } => start.clone(),
198-
_ => unreachable!("line traversal only used for line segments"),
199-
},
197+
SegmentTraversal::Reverse => start.clone(),
200198
};
201199
let sketch = straight_line(
202200
segment.id,

0 commit comments

Comments
 (0)