Skip to main content

blockworx_router/
segment.rs

1use crate::{
2    coord::{CoordX, CoordY},
3    cost::Cost,
4};
5
6// A linear segment is a start and end coordinate and a cost.
7// A segment is either horizontal or vertical, and the cost is
8// the cost of routing through that segment.
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
10pub struct Segment<P> {
11    pub start: P,
12    pub end: P,
13    pub cost: Cost,
14}
15
16pub type HSegment = Segment<CoordX>;
17pub type VSegment = Segment<CoordY>;
18
19pub fn hseg(start: impl Into<CoordX>, end: impl Into<CoordX>, cost: impl Into<Cost>) -> HSegment {
20    HSegment {
21        start: start.into(),
22        end: end.into(),
23        cost: cost.into(),
24    }
25}
26
27pub fn vseg(start: impl Into<CoordY>, end: impl Into<CoordY>, cost: impl Into<Cost>) -> VSegment {
28    VSegment {
29        start: start.into(),
30        end: end.into(),
31        cost: cost.into(),
32    }
33}