forked from 1b-agent/opencadstudio-upstream
Merge pull request #1415 from ramox81/codex/aligned-constraint-parity
Aligned dimensional constraint: Point & line, 2Lines, value and property parity # Conflicts: # src/app/command_driver.rs # src/app/update/viewport.rs # src/entities/dimension.rs # src/scene/parametric_constraints.rs
This commit is contained in:
commit
7490b2bebd
12 files changed
+1292
-167
No files matched your search
@@ -993,9 +993,15 @@ fn resolved_target(params: &ParameterTable, constraint: &ParametricConstraint) -
|
||||
if !value.is_finite() {
|
||||
return None;
|
||||
}
|
||||
// A dimensional distance keeps its sign in the parameter but measures
|
||||
// its magnitude, as the reference does (`d1=-50` shortens the line to
|
||||
// 50; `0` folds the points together).
|
||||
if constraint.kind == ConstraintKind::Distance {
|
||||
return Some(value.abs());
|
||||
}
|
||||
let must_be_positive = matches!(
|
||||
constraint.kind,
|
||||
ConstraintKind::Distance | ConstraintKind::Radius | ConstraintKind::Diameter
|
||||
ConstraintKind::Radius | ConstraintKind::Diameter
|
||||
);
|
||||
(!must_be_positive || value > 0.0).then_some(value)
|
||||
}
|
||||
@@ -1592,6 +1598,14 @@ fn build_constraint(
|
||||
let Some(resolved) = resolved_target(params, c) else {
|
||||
return Vec::new();
|
||||
};
|
||||
// A zero distance folds the points together; the distance
|
||||
// residual has no gradient there, the coordinate equalities do.
|
||||
if resolved.abs() <= f64::EPSILON {
|
||||
return vec![
|
||||
Rc::new(Equal::new(pa.x, pb.x, 1.0)),
|
||||
Rc::new(Equal::new(pa.y, pb.y, 1.0)),
|
||||
];
|
||||
}
|
||||
let target = sys.add_param(resolved, true);
|
||||
vec![Rc::new(P2PDistance::new(pa, pb, target))]
|
||||
}
|
||||
@@ -1613,10 +1627,13 @@ fn build_constraint(
|
||||
distance_direction_type::PARALLEL_TO_LINE
|
||||
| distance_direction_type::PERPENDICULAR_TO_LINE
|
||||
) {
|
||||
if let Some(line) = direction_ref
|
||||
.first()
|
||||
.and_then(|reference| whole_line(sys, cache, *reference))
|
||||
{
|
||||
if let Some(line) = direction_ref.first().and_then(|reference| {
|
||||
// A text baseline or an ellipse axis directs the
|
||||
// distance the same way a line does.
|
||||
whole_line(sys, cache, *reference).or_else(|| {
|
||||
directional_line(sys, cache, *reference).map(|(line, _)| line)
|
||||
})
|
||||
}) {
|
||||
let current = {
|
||||
let store = sys.store();
|
||||
let delta = [
|
||||
@@ -3812,6 +3829,24 @@ impl Scene {
|
||||
self.parametric_constraints[i].dof = None;
|
||||
self.parametric_constraints[i].conflicts.clear();
|
||||
}
|
||||
// A dimensional constraint set to zero means the collapse.
|
||||
let zero_collapse: HashSet<Handle> = {
|
||||
let set = &self.parametric_constraints[i];
|
||||
let params = if set.local_parameters.is_empty() {
|
||||
&self.named_parameters
|
||||
} else {
|
||||
&set.local_parameters
|
||||
};
|
||||
set.constraints
|
||||
.iter()
|
||||
.filter(|c| {
|
||||
c.enabled
|
||||
&& c.kind == ConstraintKind::Distance
|
||||
&& resolved_target(params, c).is_some_and(|v| v.abs() <= f64::EPSILON)
|
||||
})
|
||||
.flat_map(|c| c.refs.iter().map(|r| r.entity))
|
||||
.collect()
|
||||
};
|
||||
for (handle, new_entity) in solved {
|
||||
// An edit the constraints can only satisfy by collapsing the
|
||||
// entity (a rotated line whose start is fixed and direction
|
||||
@@ -3820,7 +3855,8 @@ impl Scene {
|
||||
let new_entity = match originals.get(&handle) {
|
||||
Some(original)
|
||||
if collapsed_by_solve(&new_entity)
|
||||
&& !collapsed_by_solve(original.as_ref()) =>
|
||||
&& !collapsed_by_solve(original.as_ref())
|
||||
&& !zero_collapse.contains(&handle) =>
|
||||
{
|
||||
original.as_ref().clone()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user