mirror of https://codeberg.org/topola/topola.git
fix(geometry): fix bend joint order and correct tangent clockwiseness
Now bends should cease to seemingly randomly invert their order.
This commit is contained in:
parent
2703f662ac
commit
b8adfec817
|
|
@ -6,7 +6,7 @@ use geo::Point;
|
||||||
use petgraph::{
|
use petgraph::{
|
||||||
stable_graph::{NodeIndex, StableDiGraph},
|
stable_graph::{NodeIndex, StableDiGraph},
|
||||||
visit::EdgeRef,
|
visit::EdgeRef,
|
||||||
Direction::Incoming,
|
Direction::{self, Incoming},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
@ -489,22 +489,6 @@ impl<
|
||||||
.map(|ni| self.primitive_weight(ni).retag(ni))
|
.map(|ni| self.primitive_weight(ni).retag(ni))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn seg_joints(&self, seg: SI) -> (DI, DI) {
|
|
||||||
let v: Vec<_> = self.joineds(seg.into()).collect();
|
|
||||||
(
|
|
||||||
v[0].try_into().unwrap_or_else(|_| unreachable!()),
|
|
||||||
v[1].try_into().unwrap_or_else(|_| unreachable!()),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn bend_joints(&self, bend: BI) -> (DI, DI) {
|
|
||||||
let v: Vec<_> = self.joineds(bend.into()).collect();
|
|
||||||
(
|
|
||||||
v[0].try_into().unwrap_or_else(|_| unreachable!()),
|
|
||||||
v[1].try_into().unwrap_or_else(|_| unreachable!()),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn joined_segs(&self, dot: DI) -> impl Iterator<Item = SI> + '_ {
|
pub fn joined_segs(&self, dot: DI) -> impl Iterator<Item = SI> + '_ {
|
||||||
self.joineds(dot.into()).filter_map(|ni| ni.try_into().ok())
|
self.joineds(dot.into()).filter_map(|ni| ni.try_into().ok())
|
||||||
}
|
}
|
||||||
|
|
@ -513,6 +497,55 @@ impl<
|
||||||
self.joineds(dot.into()).filter_map(|ni| ni.try_into().ok())
|
self.joineds(dot.into()).filter_map(|ni| ni.try_into().ok())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn joints(&self, node: PI) -> (DI, DI) {
|
||||||
|
(
|
||||||
|
self.graph
|
||||||
|
.neighbors_directed(node.petgraph_index(), Direction::Incoming)
|
||||||
|
.find(move |ni| {
|
||||||
|
matches!(
|
||||||
|
self.graph
|
||||||
|
.edge_weight(
|
||||||
|
self.graph
|
||||||
|
.find_edge_undirected(node.petgraph_index(), *ni)
|
||||||
|
.unwrap()
|
||||||
|
.0,
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
GeometryLabel::Joined
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.map(|ni| self.primitive_weight(ni).retag(ni))
|
||||||
|
.map(|pi| pi.try_into().unwrap_or_else(|_| unreachable!()))
|
||||||
|
.unwrap(),
|
||||||
|
self.graph
|
||||||
|
.neighbors_directed(node.petgraph_index(), Direction::Outgoing)
|
||||||
|
.find(move |ni| {
|
||||||
|
matches!(
|
||||||
|
self.graph
|
||||||
|
.edge_weight(
|
||||||
|
self.graph
|
||||||
|
.find_edge_undirected(node.petgraph_index(), *ni)
|
||||||
|
.unwrap()
|
||||||
|
.0,
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
GeometryLabel::Joined
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.map(|ni| self.primitive_weight(ni).retag(ni))
|
||||||
|
.map(|pi| pi.try_into().unwrap_or_else(|_| unreachable!()))
|
||||||
|
.unwrap(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn seg_joints(&self, seg: SI) -> (DI, DI) {
|
||||||
|
self.joints(seg.into())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn bend_joints(&self, bend: BI) -> (DI, DI) {
|
||||||
|
self.joints(bend.into())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn compound_members(&self, compound: GenericIndex<CW>) -> impl Iterator<Item = PI> + '_ {
|
pub fn compound_members(&self, compound: GenericIndex<CW>) -> impl Iterator<Item = PI> + '_ {
|
||||||
self.graph
|
self.graph
|
||||||
.neighbors_directed(compound.petgraph_index(), Incoming)
|
.neighbors_directed(compound.petgraph_index(), Incoming)
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ pub fn tangent_segments(
|
||||||
let cross2 =
|
let cross2 =
|
||||||
seq_cross_product(tangent_point_pair.0, tangent_point_pair.1, circle2.pos);
|
seq_cross_product(tangent_point_pair.0, tangent_point_pair.1, circle2.pos);
|
||||||
|
|
||||||
if (cw2 && cross2 <= 0.0) || (!cw2 && cross2 >= 0.0) {
|
if (cw2 && cross2 >= 0.0) || (!cw2 && cross2 <= 0.0) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue