mirror of https://codeberg.org/topola/topola.git
Add `Stretch` object to hold bend together withs neighboring segs, bends
This commit is contained in:
parent
9c75151d3a
commit
7c86b902aa
|
|
@ -32,7 +32,7 @@ impl Layout {
|
||||||
Head {dot: from, bend: None}
|
Head {dot: from, bend: None}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn route_end(&mut self, head: Head, to: DotIndex, width: f64) {
|
pub fn route_stop(&mut self, head: Head, to: DotIndex, width: f64) {
|
||||||
let from_circle = self.head_guidecircle(&head, width);
|
let from_circle = self.head_guidecircle(&head, width);
|
||||||
|
|
||||||
let conditions = Conditions {
|
let conditions = Conditions {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ extern crate sdl2;
|
||||||
mod layout;
|
mod layout;
|
||||||
mod rules;
|
mod rules;
|
||||||
mod mesh;
|
mod mesh;
|
||||||
|
mod stretch;
|
||||||
mod primitive;
|
mod primitive;
|
||||||
mod shape;
|
mod shape;
|
||||||
mod weight;
|
mod weight;
|
||||||
|
|
@ -71,7 +72,7 @@ fn main() {
|
||||||
let head = layout.route_around_dot(head, obstacle_dot1, true, 5.0);
|
let head = layout.route_around_dot(head, obstacle_dot1, true, 5.0);
|
||||||
let dot3_1 = head.dot;
|
let dot3_1 = head.dot;
|
||||||
let bend3_1 = head.bend.unwrap();
|
let bend3_1 = head.bend.unwrap();
|
||||||
layout.route_end(head, dot4, 5.0);
|
layout.route_stop(head, dot4, 5.0);
|
||||||
|
|
||||||
let head = layout.route_start(dot2);
|
let head = layout.route_start(dot2);
|
||||||
let head = layout.route_around_dot(head, dot3, true, 5.0);
|
let head = layout.route_around_dot(head, dot3, true, 5.0);
|
||||||
|
|
@ -80,12 +81,12 @@ fn main() {
|
||||||
let head = layout.route_around_bend(head, bend3_1, true, 5.0);
|
let head = layout.route_around_bend(head, bend3_1, true, 5.0);
|
||||||
let dot2_2 = head.dot;
|
let dot2_2 = head.dot;
|
||||||
let bend2_2 = head.bend.unwrap();
|
let bend2_2 = head.bend.unwrap();
|
||||||
layout.route_end(head, dot5, 5.0);
|
layout.route_stop(head, dot5, 5.0);
|
||||||
|
|
||||||
let head = layout.route_start(dot1);
|
let head = layout.route_start(dot1);
|
||||||
let head = layout.route_around_bend(head, bend2_1, true, 5.0);
|
let head = layout.route_around_bend(head, bend2_1, true, 5.0);
|
||||||
let head = layout.route_around_bend(head, bend2_2, true, 5.0);
|
let head = layout.route_around_bend(head, bend2_2, true, 5.0);
|
||||||
layout.route_end(head, dot6, 5.0);
|
layout.route_stop(head, dot6, 5.0);
|
||||||
|
|
||||||
'running: loop {
|
'running: loop {
|
||||||
i = (i + 1) % 255;
|
i = (i + 1) % 255;
|
||||||
|
|
|
||||||
|
|
@ -95,14 +95,6 @@ impl Mesh {
|
||||||
self.insert_into_rtree(dot.tag());
|
self.insert_into_rtree(dot.tag());
|
||||||
self.insert_into_rtree(bend.tag());
|
self.insert_into_rtree(bend.tag());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*pub fn shift_bend(&mut self, bend: BendIndex, offset: f64) {
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*pub fn position_bend(&mut self, bend: BendIndex, uI*/
|
|
||||||
|
|
||||||
//pub fn reposition_bend
|
|
||||||
|
|
||||||
pub fn reoffset_bend(&mut self, bend: BendIndex, offset: f64) {
|
pub fn reoffset_bend(&mut self, bend: BendIndex, offset: f64) {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,13 @@ use crate::graph::{Set, DotIndex, SegIndex, BendIndex, TaggedIndex, Tag, Index,
|
||||||
use crate::shape::Shape;
|
use crate::shape::Shape;
|
||||||
|
|
||||||
pub struct Primitive<'a, Weight> {
|
pub struct Primitive<'a, Weight> {
|
||||||
index: Index<Weight>,
|
pub index: Index<Weight>,
|
||||||
graph: &'a StableDiGraph<TaggedWeight, Label, usize>,
|
graph: &'a StableDiGraph<TaggedWeight, Label, usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, Weight> Primitive<'a, Weight> {
|
impl<'a, Weight> Primitive<'a, Weight> {
|
||||||
pub fn new(index: Index<Weight>, graph: &'a StableDiGraph<TaggedWeight, Label, usize>) -> Primitive<Weight> {
|
pub fn new(index: Index<Weight>, graph: &'a StableDiGraph<TaggedWeight, Label, usize>) -> Self {
|
||||||
Primitive::<Weight> {index, graph}
|
Self {index, graph}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn shape(&self) -> Shape {
|
pub fn shape(&self) -> Shape {
|
||||||
|
|
@ -109,9 +109,9 @@ impl<'a, Weight> Set for Primitive<'a, Weight> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Dot<'a> = Primitive<'a, DotWeight>;
|
pub type Dot<'a> = Primitive<'a, DotWeight>;
|
||||||
type Seg<'a> = Primitive<'a, SegWeight>;
|
pub type Seg<'a> = Primitive<'a, SegWeight>;
|
||||||
type Bend<'a> = Primitive<'a, BendWeight>;
|
pub type Bend<'a> = Primitive<'a, BendWeight>;
|
||||||
|
|
||||||
impl<'a> Dot<'a> {
|
impl<'a> Dot<'a> {
|
||||||
pub fn weight(&self) -> DotWeight {
|
pub fn weight(&self) -> DotWeight {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,99 @@
|
||||||
|
use petgraph::stable_graph::StableDiGraph;
|
||||||
|
|
||||||
|
use crate::primitive::{Dot, Seg, Bend};
|
||||||
|
use crate::graph::{TaggedIndex, DotIndex, SegIndex, BendIndex, TaggedWeight, Label, Set};
|
||||||
|
|
||||||
|
pub struct Stretch<'a> {
|
||||||
|
bend1_dot1: DotIndex,
|
||||||
|
bend1: BendIndex,
|
||||||
|
bend1_dot2: DotIndex,
|
||||||
|
seg1: SegIndex,
|
||||||
|
bend2_dot1: DotIndex,
|
||||||
|
bend2: BendIndex,
|
||||||
|
bend2_dot2: DotIndex,
|
||||||
|
seg2: SegIndex,
|
||||||
|
bend3_dot1: DotIndex,
|
||||||
|
bend3: BendIndex,
|
||||||
|
bend3_dot2: DotIndex,
|
||||||
|
graph: &'a StableDiGraph<TaggedWeight, Label, usize>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Stretch<'a> {
|
||||||
|
pub fn new(index: BendIndex, graph: &'a StableDiGraph<TaggedWeight, Label, usize>) -> Self {
|
||||||
|
let bend2 = index;
|
||||||
|
|
||||||
|
let bend2_dot1 = *Bend::new(bend2, graph).prev().unwrap().as_dot().unwrap();
|
||||||
|
let seg1 = *Dot::new(bend2_dot1, graph).prev().unwrap().as_seg().unwrap();
|
||||||
|
let bend1_dot2 = *Seg::new(seg1, graph).prev().unwrap().as_dot().unwrap();
|
||||||
|
let bend1 = *Dot::new(bend1_dot2, graph).prev().unwrap().as_bend().unwrap();
|
||||||
|
let bend1_dot1 = *Bend::new(bend1, graph).prev().unwrap().as_dot().unwrap();
|
||||||
|
|
||||||
|
let bend2_dot2 = *Bend::new(bend2, graph).next().unwrap().as_dot().unwrap();
|
||||||
|
let seg2 = *Dot::new(bend2_dot1, graph).next().unwrap().as_seg().unwrap();
|
||||||
|
let bend3_dot1 = *Seg::new(seg1, graph).next().unwrap().as_dot().unwrap();
|
||||||
|
let bend3 = *Dot::new(bend1_dot2, graph).next().unwrap().as_bend().unwrap();
|
||||||
|
let bend3_dot2 = *Bend::new(bend1, graph).next().unwrap().as_dot().unwrap();
|
||||||
|
|
||||||
|
Self {
|
||||||
|
bend1_dot1,
|
||||||
|
bend1,
|
||||||
|
bend1_dot2,
|
||||||
|
seg1,
|
||||||
|
bend2_dot1,
|
||||||
|
bend2,
|
||||||
|
bend2_dot2,
|
||||||
|
seg2,
|
||||||
|
bend3_dot1,
|
||||||
|
bend3,
|
||||||
|
bend3_dot2,
|
||||||
|
graph,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Set for Stretch<'a> {
|
||||||
|
fn interior(&self) -> Vec<TaggedIndex> {
|
||||||
|
vec![
|
||||||
|
TaggedIndex::Bend(self.bend1),
|
||||||
|
TaggedIndex::Dot(self.bend1_dot2),
|
||||||
|
|
||||||
|
TaggedIndex::Seg(self.seg1),
|
||||||
|
|
||||||
|
TaggedIndex::Dot(self.bend2_dot1),
|
||||||
|
TaggedIndex::Bend(self.bend2),
|
||||||
|
TaggedIndex::Dot(self.bend2_dot2),
|
||||||
|
|
||||||
|
TaggedIndex::Seg(self.seg2),
|
||||||
|
|
||||||
|
TaggedIndex::Dot(self.bend3_dot1),
|
||||||
|
TaggedIndex::Bend(self.bend3),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn closure(&self) -> Vec<TaggedIndex> {
|
||||||
|
vec![
|
||||||
|
TaggedIndex::Dot(self.bend1_dot1),
|
||||||
|
TaggedIndex::Bend(self.bend1),
|
||||||
|
TaggedIndex::Dot(self.bend1_dot2),
|
||||||
|
|
||||||
|
TaggedIndex::Seg(self.seg1),
|
||||||
|
|
||||||
|
TaggedIndex::Dot(self.bend2_dot1),
|
||||||
|
TaggedIndex::Bend(self.bend2),
|
||||||
|
TaggedIndex::Dot(self.bend2_dot2),
|
||||||
|
|
||||||
|
TaggedIndex::Seg(self.seg2),
|
||||||
|
|
||||||
|
TaggedIndex::Dot(self.bend3_dot1),
|
||||||
|
TaggedIndex::Bend(self.bend3),
|
||||||
|
TaggedIndex::Dot(self.bend3_dot2),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
fn boundary(&self) -> Vec<DotIndex> {
|
||||||
|
vec![
|
||||||
|
self.bend1_dot1,
|
||||||
|
self.bend3_dot2,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue