oxiphysics_core/interval/
linearconstraint_traits.rs1use super::functions::IntervalConstraint;
12#[allow(unused_imports)]
13use super::functions::*;
14use super::types::{Interval, LinearConstraint};
15
16impl IntervalConstraint for LinearConstraint {
17 fn propagate(&self, box_: &mut [Interval]) -> bool {
18 let mut changed = false;
19 for &(target_idx, target_coeff) in &self.coeffs {
20 if target_coeff.abs() < 1e-30 {
21 continue;
22 }
23 let mut other_sum = Interval::point(0.0);
24 for &(idx, coeff) in &self.coeffs {
25 if idx != target_idx {
26 other_sum = other_sum + box_[idx] * coeff;
27 }
28 }
29 let needed = (self.rhs - other_sum) / Interval::point(target_coeff);
30 if let Some(narrowed) = Interval::intersection(box_[target_idx], needed)
31 && (narrowed.lo > box_[target_idx].lo + 1e-15
32 || narrowed.hi < box_[target_idx].hi - 1e-15)
33 {
34 box_[target_idx] = narrowed;
35 changed = true;
36 }
37 }
38 changed
39 }
40}