diff --git a/src/mesh.rs b/src/mesh.rs index 8d578ea..b43f54c 100644 --- a/src/mesh.rs +++ b/src/mesh.rs @@ -35,7 +35,7 @@ impl Mesh { pub fn add_seg(&mut self, from: DotIndex, to: DotIndex, weight: SegWeight) -> SegIndex { let seg = SegIndex::new(self.graph.add_node(TaggedWeight::Seg(weight))); - self.graph.add_edge(seg.index, from.index, Label::End); + self.graph.add_edge(from.index, seg.index, Label::End); self.graph.add_edge(seg.index, to.index, Label::End); self.rtree.insert(RTreeWrapper::new(self.primitive(seg).shape(), TaggedIndex::Seg(seg))); @@ -59,7 +59,7 @@ impl Mesh { pub fn add_core_bend(&mut self, from: DotIndex, to: DotIndex, core: DotIndex, weight: BendWeight) -> BendIndex { let bend = BendIndex::new(self.graph.add_node(TaggedWeight::Bend(weight))); - self.graph.add_edge(bend.index, from.index, Label::End); + self.graph.add_edge(from.index, bend.index, Label::End); self.graph.add_edge(bend.index, to.index, Label::End); self.graph.add_edge(bend.index, core.index, Label::Core); diff --git a/src/primitive.rs b/src/primitive.rs index 8f21d6a..68ca38f 100644 --- a/src/primitive.rs +++ b/src/primitive.rs @@ -49,9 +49,23 @@ impl<'a, Weight> Primitive<'a, Weight> { } } - pub fn ends(&self) -> Vec { - self.graph.neighbors(self.index.index) + pub fn next(&self) -> Option { + self.graph.neighbors_directed(self.index.index, Outgoing) + .filter(|ni| self.graph.edge_weight(self.graph.find_edge(*ni, self.index.index).unwrap()).unwrap().is_end()) + .map(|ni| Index::