Another project
0

Configure Feed

Select the types of activity you want to include in your feed.

fix(document): dont bother with old cache lookups

Lewis: May this revision serve well! <lu5a@proton.me>

author
Lewis
date (Jun 5, 2026, 12:51 PM +0300) commit d4557ced parent 237b590b change-id kxsntvux
+58 -15
+2 -7
crates/bone-document/src/evaluator.rs
··· 149 149 } 150 150 151 151 #[must_use] 152 - pub fn lookup(&self, feature: FeatureId) -> Option<&EvaluatedSketch> { 153 - self.sketches.get(&feature).map(|cached| &cached.output) 154 - } 155 - 156 - #[must_use] 157 - pub fn lookup_extrude(&self, feature: FeatureId) -> Option<&EvaluatedExtrude> { 158 - self.extrudes.get(&feature).map(|cached| &cached.output) 152 + pub fn contains(&self, feature: FeatureId) -> bool { 153 + self.sketches.contains_key(&feature) || self.extrudes.contains_key(&feature) 159 154 } 160 155 161 156 pub fn invalidate(&mut self, feature: FeatureId) -> bool {
+7 -7
crates/bone-document/tests/evaluator.rs
··· 145 145 let second = cache.evaluate(fid, &sketch).clone(); 146 146 assert_eq!(first, second); 147 147 assert_eq!(cache.len(), 1); 148 - assert!(cache.lookup(fid).is_some()); 148 + assert!(cache.contains(fid)); 149 149 } 150 150 151 151 #[test] ··· 172 172 cache.evaluate(a, &horizontal_line_sketch(10.0)); 173 173 cache.evaluate(b, &horizontal_line_sketch(20.0)); 174 174 assert_eq!(cache.len(), 2); 175 - assert!(cache.lookup(a).is_some()); 176 - assert!(cache.lookup(b).is_some()); 175 + assert!(cache.contains(a)); 176 + assert!(cache.contains(b)); 177 177 } 178 178 179 179 #[test] ··· 182 182 let fid = feature_id(7); 183 183 cache.evaluate(fid, &horizontal_line_sketch(10.0)); 184 184 assert!(cache.invalidate(fid)); 185 - assert!(cache.lookup(fid).is_none()); 185 + assert!(!cache.contains(fid)); 186 186 assert!(!cache.invalidate(fid)); 187 187 } 188 188 ··· 194 194 cache.evaluate(keep, &horizontal_line_sketch(10.0)); 195 195 cache.evaluate(drop, &horizontal_line_sketch(20.0)); 196 196 cache.retain([keep]); 197 - assert!(cache.lookup(keep).is_some()); 198 - assert!(cache.lookup(drop).is_none()); 197 + assert!(cache.contains(keep)); 198 + assert!(!cache.contains(drop)); 199 199 assert_eq!(cache.len(), 1); 200 200 } 201 201 ··· 378 378 first, refreshed, 379 379 "a changed upstream sketch refreshes the extrude" 380 380 ); 381 - assert!(cache.lookup_extrude(extrude_feature).is_some()); 381 + assert!(cache.contains(extrude_feature)); 382 382 assert_eq!(cache.len(), 2); 383 383 } 384 384
+49 -1
crates/bone-document/tests/undo.rs
··· 1 1 use std::num::NonZeroUsize; 2 2 3 - use bone_document::{Document, EditOutcome, Sketch, SketchEdit, SketchEntity, UndoStack}; 3 + use bone_document::{Document, EditOutcome, FeatureEdge, Sketch, SketchEdit, SketchEntity, UndoStack}; 4 4 use bone_kernel::{ 5 5 ExtrudeDirection, ExtrudeEndCondition, ExtrudeFeature, ExtrudeSense, MergeResult, 6 6 }; ··· 185 185 } 186 186 187 187 #[test] 188 + fn redo_never_exceeds_capacity() { 189 + let mut stack = UndoStack::with_capacity(cap(2)); 190 + let mut live = base_doc(); 191 + [1u32, 2, 3, 4].iter().for_each(|i| { 192 + stack.record(live.clone()); 193 + live.insert_sketch(sketch_id(*i), format!("S{i}"), Sketch::new(plane())); 194 + assert!(stack.past_len() <= 2, "record stays within capacity"); 195 + }); 196 + std::iter::from_fn(|| { 197 + stack 198 + .undo(&mut live) 199 + .then(|| assert!(stack.past_len() <= 2 && stack.future_len() <= 2)) 200 + }) 201 + .for_each(drop); 202 + std::iter::from_fn(|| { 203 + stack 204 + .redo(&mut live) 205 + .then(|| assert!(stack.past_len() <= 2, "redo must not grow past beyond capacity")) 206 + }) 207 + .for_each(drop); 208 + assert!(!stack.can_redo()); 209 + } 210 + 211 + #[test] 188 212 fn undo_redo_cycle_preserves_determinism() { 189 213 let a = base_doc(); 190 214 let b = with_sketch(a.clone(), sketch_id(1)); ··· 220 244 live, pre_extrude, 221 245 "inserting an extrude must change the document" 222 246 ); 247 + let Some(sketch_feature) = live.feature_tree().feature_of_sketch(sid) else { 248 + panic!("sketch feature present"); 249 + }; 250 + let Some(extrude_feature) = live.feature_tree().feature_of_extrude(xid) else { 251 + panic!("extrude feature present"); 252 + }; 253 + let wired = [FeatureEdge::SketchToExtrude { 254 + sketch: sketch_feature, 255 + extrude: extrude_feature, 256 + }]; 257 + assert_eq!( 258 + live.feature_tree().edges(), 259 + wired, 260 + "inserting an extrude wires the sketch-to-extrude edge" 261 + ); 223 262 224 263 assert!(stack.undo(&mut live)); 225 264 assert_eq!( ··· 234 273 live.header().extrudes.is_empty(), 235 274 "no extrude payload survives the undo" 236 275 ); 276 + assert!( 277 + live.feature_tree().edges().is_empty(), 278 + "undo drops the derived sketch-to-extrude edge" 279 + ); 237 280 238 281 assert!(stack.redo(&mut live)); 239 282 let Some(feature) = live.feature_tree().feature_of_extrude(xid) else { ··· 243 286 live.extrude_of_feature(feature), 244 287 Some(&blind_extrude(sid)), 245 288 "redo restores the extrude payload" 289 + ); 290 + assert_eq!( 291 + live.feature_tree().edges(), 292 + wired, 293 + "redo restores the derived edge even though it is never serialized" 246 294 ); 247 295 }