mirror of https://codeberg.org/topola/topola.git
Display mesh edges
This commit is contained in:
parent
a077dfbca2
commit
c480111624
|
|
@ -402,4 +402,15 @@ impl Layout {
|
|||
.nodes()
|
||||
.map(|ni| untag!(ni, self.mesh.primitive(ni).shape()))
|
||||
}
|
||||
|
||||
pub fn edges(&self) -> impl Iterator<Item = (Point, Point)> + '_ {
|
||||
self.mesh.edges().map(|endpoints| {
|
||||
let index0 = endpoints.0;
|
||||
let index1 = endpoints.1;
|
||||
(
|
||||
untag!(index0, self.mesh.primitive(index0).shape().center()),
|
||||
untag!(index1, self.mesh.primitive(index1).shape().center()),
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
11
src/main.rs
11
src/main.rs
|
|
@ -412,6 +412,17 @@ fn render_times(
|
|||
Color::RGB(100, 100, 100),
|
||||
);
|
||||
}
|
||||
|
||||
for edge in layout.edges() {
|
||||
dbg!(edge);
|
||||
let _ = canvas.line(
|
||||
edge.0.x() as i16,
|
||||
edge.0.y() as i16,
|
||||
edge.1.x() as i16,
|
||||
edge.1.y() as i16,
|
||||
Color::RGB(250, 250, 250),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
if let Err(err) = result {
|
||||
|
|
|
|||
12
src/mesh.rs
12
src/mesh.rs
|
|
@ -213,6 +213,18 @@ impl Mesh {
|
|||
self.rtree.iter().map(|wrapper| wrapper.data)
|
||||
}
|
||||
|
||||
pub fn edges(&self) -> impl Iterator<Item = (TaggedIndex, TaggedIndex)> + '_ {
|
||||
self.graph.edge_indices().map(|edge| {
|
||||
let endpoints = self.graph.edge_endpoints(edge).unwrap();
|
||||
(
|
||||
Index::<Label>::new(endpoints.0)
|
||||
.retag(self.graph.node_weight(endpoints.0).unwrap()),
|
||||
Index::<Label>::new(endpoints.1)
|
||||
.retag(self.graph.node_weight(endpoints.1).unwrap()),
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
pub fn primitive<Weight>(&self, index: Index<Weight>) -> Primitive<Weight> {
|
||||
Primitive::new(index, &self.graph)
|
||||
}
|
||||
|
|
|
|||
19
src/shape.rs
19
src/shape.rs
|
|
@ -1,5 +1,3 @@
|
|||
use std::mem;
|
||||
|
||||
use geo::{point, polygon, EuclideanDistance, Intersects, Point, Polygon, Rotate};
|
||||
use rstar::{RTreeObject, AABB};
|
||||
|
||||
|
|
@ -21,10 +19,10 @@ pub struct SegShape {
|
|||
impl SegShape {
|
||||
fn polygon(&self) -> Polygon {
|
||||
let tangent_vector = self.to - self.from;
|
||||
let tangent_vector_norm = tangent_vector.euclidean_distance(&point! {x: 0., y: 0.});
|
||||
let tangent_vector_norm = tangent_vector.euclidean_distance(&point! {x: 0.0, y: 0.0});
|
||||
let unit_tangent_vector = tangent_vector / tangent_vector_norm;
|
||||
|
||||
let normal = unit_tangent_vector.rotate_around_point(-90., point! {x: 0., y: 0.});
|
||||
let normal = unit_tangent_vector.rotate_around_point(-90., point! {x: 0.0, y: 0.0});
|
||||
|
||||
let p1 = self.from - normal * (self.width / 2.);
|
||||
let p2 = self.from + normal * (self.width / 2.);
|
||||
|
|
@ -84,6 +82,19 @@ impl Shape {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn center(&self) -> Point {
|
||||
match self {
|
||||
Shape::Dot(dot) => dot.c.pos,
|
||||
Shape::Seg(seg) => (seg.from + seg.to) / 2.0,
|
||||
Shape::Bend(bend) => {
|
||||
let sum = (bend.from - bend.center) + (bend.to - bend.center);
|
||||
let r = bend.from.euclidean_distance(&bend.center);
|
||||
|
||||
bend.center + (sum / sum.euclidean_distance(&point! {x: 0.0, y: 0.0})) * r
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn priority(&self) -> i64 {
|
||||
match self {
|
||||
Shape::Dot(..) => 3,
|
||||
|
|
|
|||
Loading…
Reference in New Issue