pub struct Edge { /* private fields */ }
Expand description
An edge of a rectangle.
Implementations§
source§impl Edge
impl Edge
sourcepub fn side(&self) -> Side
pub fn side(&self) -> Side
The side (of a rectangle) to which this edge corresponds.
§Example
let edge = Edge::new(Side::Left, 20, Span::new(40, 100));
assert_eq!(edge.side(), Side::Left);
sourcepub fn coord(&self) -> i64
pub fn coord(&self) -> i64
The coordinate of the edge.
For left/right edges, this will be the x coordinate of the edge. For top/bottom edges, this will be the y coordinate of the edge.
§Example
let edge = Edge::new(Side::Left, 20, Span::new(40, 100));
assert_eq!(edge.coord(), 20);
sourcepub fn span(&self) -> Span
pub fn span(&self) -> Span
The span of the edge.
For left/right edges, this will be the range of y-coordinates encompassed by the edge. For top/bottom edges, this will be the range of x-coordinates encompassed by the edge.
§Example
let edge = Edge::new(Side::Left, 20, Span::new(40, 100));
assert_eq!(edge.span(), Span::new(40, 100));
sourcepub fn with_span(&self, span: Span) -> Edge
pub fn with_span(&self, span: Span) -> Edge
Returns an Edge
with the same properties as the provided Edge
but with a new span.
§Example
let edge = Edge::new(Side::Left, 20, Span::new(40, 100));
assert_eq!(edge.span(), Span::new(40, 100));
let edge_new = edge.with_span(Span::new(20, 100));
assert_eq!(edge_new.span(), Span::new(20, 100));
sourcepub fn norm_dir(&self) -> Dir
pub fn norm_dir(&self) -> Dir
The direction perpendicular to the edge.
For left/right edges, this will be Dir::Horiz
.
For top/bottom edges, this will be Dir::Vert
.
§Example
let edge = Edge::new(Side::Left, 20, Span::new(40, 100));
assert_eq!(edge.norm_dir(), Dir::Horiz);
let edge = Edge::new(Side::Right, 20, Span::new(40, 100));
assert_eq!(edge.norm_dir(), Dir::Horiz);
let edge = Edge::new(Side::Top, 20, Span::new(40, 100));
assert_eq!(edge.norm_dir(), Dir::Vert);
let edge = Edge::new(Side::Bot, 20, Span::new(40, 100));
assert_eq!(edge.norm_dir(), Dir::Vert);
sourcepub fn edge_dir(&self) -> Dir
pub fn edge_dir(&self) -> Dir
The direction parallel to the edge.
For left/right edges, this will be Dir::Vert
.
For top/bottom edges, this will be Dir::Horiz
.
§Example
let edge = Edge::new(Side::Left, 20, Span::new(40, 100));
assert_eq!(edge.edge_dir(), Dir::Vert);
let edge = Edge::new(Side::Right, 20, Span::new(40, 100));
assert_eq!(edge.edge_dir(), Dir::Vert);
let edge = Edge::new(Side::Top, 20, Span::new(40, 100));
assert_eq!(edge.edge_dir(), Dir::Horiz);
let edge = Edge::new(Side::Bot, 20, Span::new(40, 100));
assert_eq!(edge.edge_dir(), Dir::Horiz);
sourcepub fn offset(&self, offset: i64) -> Edge
pub fn offset(&self, offset: i64) -> Edge
Returns a new Edge
offset some amount away from this edge.
Left edges will be offset to the left; right edges will be offset to the right. Top edges will be offset upwards; bottom edges will be offset downwards.
§Example
let edge = Edge::new(Side::Left, 20, Span::new(40, 100));
assert_eq!(edge.offset(10), Edge::new(Side::Left, 10, Span::new(40, 100)));
let edge = Edge::new(Side::Top, 20, Span::new(40, 100));
assert_eq!(edge.offset(10), Edge::new(Side::Top, 30, Span::new(40, 100)));