Skip to content

Commit f0aa31c

Browse files
authored
Add solver conflict output on segments (#9298)
* Add solver conflict output on segments * Condense matches and add comments
1 parent 057d8a1 commit f0aa31c

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,11 +1440,10 @@ fn substitute_sketch_var_in_unsolved_expr(
14401440
source_ranges.to_vec(),
14411441
)));
14421442
};
1443-
// TODO: sketch-api: This isn't implemented properly yet.
1444-
// solve_outcome.unsatisfied.contains means "Fixed or over-constrained"
14451443
let freedom = if solve_outcome.unsatisfied.contains(&var_id.0) {
1446-
Freedom::Free
1444+
Freedom::Conflict
14471445
} else {
1446+
// TODO: sketch-api: This isn't implemented properly yet.
14481447
Freedom::Fixed
14491448
};
14501449
Ok((TyF64::new(*solution, solution_ty), freedom))

rust/kcl-lib/src/frontend/sketch.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,24 +113,21 @@ pub struct Point {
113113
#[ts(export, export_to = "FrontendApi.ts")]
114114
pub enum Freedom {
115115
Free,
116-
Partial,
117116
Fixed,
117+
Conflict,
118118
}
119119

120120
impl Freedom {
121+
/// Merges two Freedom values. For example, a point has a solver variable
122+
/// for each dimension, x and y. If one dimension is `Free` and the other is
123+
/// `Fixed`, the point overall is `Free` since it isn't fully constrained.
124+
/// `Conflict` infects the most, followed by `Free`. An object must be fully
125+
/// `Fixed` to be `Fixed` overall.
121126
pub fn merge(self, other: Self) -> Self {
122-
match self {
123-
Self::Free => match other {
124-
Self::Free => Self::Free,
125-
Self::Partial => Self::Partial,
126-
Self::Fixed => Self::Partial,
127-
},
128-
Self::Partial => Self::Partial,
129-
Self::Fixed => match other {
130-
Self::Free => Self::Partial,
131-
Self::Partial => Self::Partial,
132-
Self::Fixed => Self::Fixed,
133-
},
127+
match (self, other) {
128+
(Self::Conflict, _) | (_, Self::Conflict) => Self::Conflict,
129+
(Self::Free, _) | (_, Self::Free) => Self::Free,
130+
(Self::Fixed, Self::Fixed) => Self::Fixed,
134131
}
135132
}
136133
}

0 commit comments

Comments
 (0)