blockworx/document_ng/route_edge.rs
1use super::{GridPos, RouteDirection};
2
3/// A single straight (horizontal or vertical) segment of a route, in grid space.
4/// Pure data; the pixel-space helpers (`length`, `distance`) live in the
5/// `RouteEdgeExt` trait in [`crate::widget::edge`].
6#[derive(Clone, PartialEq, Debug)]
7pub struct RouteEdge {
8 pub start: GridPos,
9 pub end: GridPos,
10}
11
12impl RouteEdge {
13 /// Whether this segment runs more horizontally or vertically. Pure grid
14 /// arithmetic, so it stays on the data type.
15 pub fn direction(&self) -> RouteDirection {
16 if (self.end.x - self.start.x).abs() > (self.end.y - self.start.y).abs() {
17 RouteDirection::Horizontal
18 } else {
19 RouteDirection::Vertical
20 }
21 }
22}