mirror of https://codeberg.org/topola/topola.git
layout: allow moving fixed dots
This commit is contained in:
parent
8bd0f20ee0
commit
35d713b5e6
|
|
@ -176,7 +176,7 @@ impl<'a> Draw<'a> {
|
||||||
#[debug_ensures(self.layout.node_count() == old(self.layout.node_count()))]
|
#[debug_ensures(self.layout.node_count() == old(self.layout.node_count()))]
|
||||||
fn extend_head(&mut self, head: Head, to: Point) -> Result<Head, Infringement> {
|
fn extend_head(&mut self, head: Head, to: Point) -> Result<Head, Infringement> {
|
||||||
if let Head::Segbend(head) = head {
|
if let Head::Segbend(head) = head {
|
||||||
self.layout.move_dot(head.face, to)?;
|
self.layout.move_dot(head.face.into(), to)?;
|
||||||
Ok(Head::Segbend(head))
|
Ok(Head::Segbend(head))
|
||||||
} else {
|
} else {
|
||||||
Ok(head)
|
Ok(head)
|
||||||
|
|
|
||||||
|
|
@ -439,8 +439,12 @@ 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_infringably(ends.0, from, &self.inner_bow_and_outer_bows(rail))?;
|
self.move_dot_infringably(
|
||||||
self.move_dot_infringably(ends.1, to, &self.inner_bow_and_outer_bows(rail))?;
|
ends.0.into(),
|
||||||
|
from,
|
||||||
|
&self.inner_bow_and_outer_bows(rail),
|
||||||
|
)?;
|
||||||
|
self.move_dot_infringably(ends.1.into(), to, &self.inner_bow_and_outer_bows(rail))?;
|
||||||
} else {
|
} else {
|
||||||
let core = primitive.core();
|
let core = primitive.core();
|
||||||
let from = guide
|
let from = guide
|
||||||
|
|
@ -449,8 +453,12 @@ 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_infringably(ends.0, from, &self.inner_bow_and_outer_bows(rail))?;
|
self.move_dot_infringably(
|
||||||
self.move_dot_infringably(ends.1, to, &self.inner_bow_and_outer_bows(rail))?;
|
ends.0.into(),
|
||||||
|
from,
|
||||||
|
&self.inner_bow_and_outer_bows(rail),
|
||||||
|
)?;
|
||||||
|
self.move_dot_infringably(ends.1.into(), to, &self.inner_bow_and_outer_bows(rail))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
maybe_rail = self.primitive(rail).outer();
|
maybe_rail = self.primitive(rail).outer();
|
||||||
|
|
@ -793,35 +801,47 @@ impl Layout {
|
||||||
|
|
||||||
#[debug_invariant(self.test_envelopes())]
|
#[debug_invariant(self.test_envelopes())]
|
||||||
impl Layout {
|
impl Layout {
|
||||||
pub fn move_dot(&mut self, dot: LooseDotIndex, to: Point) -> Result<(), Infringement> {
|
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
||||||
self.move_dot_infringably(
|
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
||||||
dot,
|
pub fn move_dot(&mut self, dot: DotIndex, to: Point) -> Result<(), Infringement> {
|
||||||
to,
|
match dot {
|
||||||
&self.inner_bow_and_outer_bow(self.primitive(dot).bend()),
|
DotIndex::Fixed(..) => self.move_dot_infringably(dot, to, &[]),
|
||||||
)
|
DotIndex::Loose(loose) => self.move_dot_infringably(
|
||||||
|
dot,
|
||||||
|
to,
|
||||||
|
&self.inner_bow_and_outer_bow(self.primitive(loose).bend()),
|
||||||
|
),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
#[debug_ensures(self.geometry.node_count() == old(self.geometry.node_count()))]
|
||||||
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
#[debug_ensures(self.geometry.edge_count() == old(self.geometry.edge_count()))]
|
||||||
pub fn move_dot_infringably(
|
fn move_dot_infringably(
|
||||||
&mut self,
|
&mut self,
|
||||||
dot: LooseDotIndex,
|
dot: DotIndex,
|
||||||
to: Point,
|
to: Point,
|
||||||
infringables: &[GeometryIndex],
|
infringables: &[GeometryIndex],
|
||||||
) -> Result<(), Infringement> {
|
) -> Result<(), Infringement> {
|
||||||
self.remove_from_rtree_with_dependents(dot.into());
|
self.remove_from_rtree_with_dependents(dot.into());
|
||||||
|
|
||||||
let mut dot_weight = self.primitive(dot).weight();
|
let mut weight = *self.geometry.node_weight(dot.node_index()).unwrap();
|
||||||
let old_weight = dot_weight;
|
let old_weight = weight;
|
||||||
|
|
||||||
dot_weight.circle.pos = to;
|
match weight {
|
||||||
*self.geometry.node_weight_mut(dot.node_index()).unwrap() =
|
GeometryWeight::FixedDot(ref mut fixed) => {
|
||||||
GeometryWeight::LooseDot(dot_weight);
|
fixed.circle.pos = to;
|
||||||
|
}
|
||||||
|
GeometryWeight::LooseDot(ref mut loose) => {
|
||||||
|
loose.circle.pos = to;
|
||||||
|
}
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
|
||||||
|
*self.geometry.node_weight_mut(dot.node_index()).unwrap() = 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.geometry.node_weight_mut(dot.node_index()).unwrap() =
|
*self.geometry.node_weight_mut(dot.node_index()).unwrap() = old_weight;
|
||||||
GeometryWeight::LooseDot(old_weight);
|
|
||||||
|
|
||||||
self.insert_into_rtree_with_dependents(dot.into());
|
self.insert_into_rtree_with_dependents(dot.into());
|
||||||
return Err(infringement);
|
return Err(infringement);
|
||||||
|
|
|
||||||
|
|
@ -647,7 +647,7 @@ fn render_times(
|
||||||
} else {
|
} else {
|
||||||
let _ = router
|
let _ = router
|
||||||
.layout
|
.layout
|
||||||
.move_dot(follower, (state.x() as f64, state.y() as f64).into());
|
.move_dot(follower.into(), (state.x() as f64, state.y() as f64).into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue