layout: restore infringability in `.move_dot()`

It was temporarily disabled earlier.
This commit is contained in:
Mikolaj Wielgus 2023-12-27 21:56:55 +00:00
parent 90972136da
commit 0b3fe216db
2 changed files with 37 additions and 17 deletions

View File

@ -239,6 +239,29 @@ impl Layout {
v v
} }
#[debug_ensures(self.graph.node_count() == old(self.graph.node_count()))]
#[debug_ensures(self.graph.edge_count() == old(self.graph.edge_count()))]
fn inner_bow_and_outer_bows(&self, bend: LooseBendIndex) -> Vec<Index> {
let bend_primitive = self.primitive(bend);
let mut v = vec![];
if let Some(inner) = bend_primitive.inner() {
v.append(&mut self.bow(inner.into()));
} else {
let core = bend_primitive.core();
v.push(core.into());
}
let mut rail = bend;
while let Some(outer) = self.primitive(rail).outer() {
v.append(&mut self.bow(outer.into()));
rail = outer;
}
v
}
#[debug_ensures(self.graph.node_count() == old(self.graph.node_count()))] #[debug_ensures(self.graph.node_count() == old(self.graph.node_count()))]
#[debug_ensures(self.graph.edge_count() == old(self.graph.edge_count()))] #[debug_ensures(self.graph.edge_count() == old(self.graph.edge_count()))]
fn this_and_wraparound_bow(&self, around: WraparoundableIndex) -> Vec<Index> { fn this_and_wraparound_bow(&self, around: WraparoundableIndex) -> Vec<Index> {
@ -387,8 +410,8 @@ impl Layout {
let to = guide let to = guide
.head_around_bend_segment(&to_head.into(), inner.into(), cw, 6.0)? .head_around_bend_segment(&to_head.into(), inner.into(), cw, 6.0)?
.end_point(); .end_point();
self.move_dot(ends.0, from)?; self.move_dot_infringably(ends.0, from, &self.inner_bow_and_outer_bows(rail))?;
self.move_dot(ends.1, to)?; self.move_dot_infringably(ends.1, to, &self.inner_bow_and_outer_bows(rail))?;
} else { } else {
let core = primitive.core(); let core = primitive.core();
let from = guide let from = guide
@ -397,19 +420,10 @@ impl Layout {
let to = guide let to = guide
.head_around_dot_segment(&to_head.into(), core.into(), cw, 6.0)? .head_around_dot_segment(&to_head.into(), core.into(), cw, 6.0)?
.end_point(); .end_point();
self.move_dot(ends.0, from)?; self.move_dot_infringably(ends.0, from, &self.inner_bow_and_outer_bows(rail))?;
self.move_dot(ends.1, to)?; self.move_dot_infringably(ends.1, to, &self.inner_bow_and_outer_bows(rail))?;
} }
/*let from = guide
.head_around_bend_segment(&from_head.into(), rail.into(), !cw, 0.0)?
.end_point();
let to = guide
.head_around_bend_segment(&to_head.into(), rail.into(), cw, 0.0)?
.end_point();
self.move_dot(ends.0, from)?;
self.move_dot(ends.1, to)?;*/
maybe_rail = self.primitive(rail).outer(); maybe_rail = self.primitive(rail).outer();
} }
@ -746,7 +760,7 @@ impl Layout {
dot_weight.circle.pos = to; dot_weight.circle.pos = to;
*self.graph.node_weight_mut(dot.node_index()).unwrap() = Weight::LooseDot(dot_weight); *self.graph.node_weight_mut(dot.node_index()).unwrap() = Weight::LooseDot(dot_weight);
/*if let Some(infringement) = self.detect_infringement_except(dot.into(), infringables) { if let Some(infringement) = self.detect_infringement_except(dot.into(), infringables) {
// Restore original state. // Restore original state.
*self.graph.node_weight_mut(dot.node_index()).unwrap() = Weight::LooseDot(old_weight); *self.graph.node_weight_mut(dot.node_index()).unwrap() = Weight::LooseDot(old_weight);
@ -756,7 +770,7 @@ impl Layout {
.seg() .seg()
.map(|seg| self.insert_into_rtree(seg.into())); .map(|seg| self.insert_into_rtree(seg.into()));
return Err(infringement); return Err(infringement);
}*/ }
self.insert_into_rtree(dot.into()); self.insert_into_rtree(dot.into());
self.insert_into_rtree(self.primitive(dot).bend().into()); self.insert_into_rtree(self.primitive(dot).bend().into());
@ -767,10 +781,14 @@ impl Layout {
Ok(()) Ok(())
} }
#[debug_ensures(self.graph.node_count() == old(self.graph.node_count()))]
#[debug_ensures(self.graph.edge_count() == old(self.graph.edge_count()))]
pub fn primitive<W>(&self, index: GenericIndex<W>) -> GenericPrimitive<W> { pub fn primitive<W>(&self, index: GenericIndex<W>) -> GenericPrimitive<W> {
GenericPrimitive::new(index, self) GenericPrimitive::new(index, self)
} }
#[debug_ensures(self.graph.node_count() == old(self.graph.node_count()))]
#[debug_ensures(self.graph.edge_count() == old(self.graph.edge_count()))]
fn detect_infringement_except(&self, index: Index, except: &[Index]) -> Option<Infringement> { fn detect_infringement_except(&self, index: Index, except: &[Index]) -> Option<Infringement> {
let shape = index.primitive(self).shape(); let shape = index.primitive(self).shape();
@ -788,6 +806,8 @@ impl Layout {
} }
// TODO: Collision and infringement are the same for now. Change this. // TODO: Collision and infringement are the same for now. Change this.
#[debug_ensures(self.graph.node_count() == old(self.graph.node_count()))]
#[debug_ensures(self.graph.edge_count() == old(self.graph.edge_count()))]
fn detect_collision(&self, index: Index) -> Option<Collision> { fn detect_collision(&self, index: Index) -> Option<Collision> {
let shape = index.primitive(self).shape(); let shape = index.primitive(self).shape();

View File

@ -486,8 +486,8 @@ fn main() {
let _ = router.enroute( let _ = router.enroute(
dot_start, dot_start,
dot_end, dot_end,
//&mut EmptyRouterObserver, &mut EmptyRouterObserver,
&mut DebugRouterObserver::new(&mut event_pump, &window, &mut renderer, &font_context), //&mut DebugRouterObserver::new(&mut event_pump, &window, &mut renderer, &font_context),
); );
render_times( render_times(