ascii_forge/math.rs
1/// A 2d Vector that has no math, is only used as a pretty version of a tuple of u16s
2/// Can be made from (u16, u16).
3/// Using a single u16.into() will create a vec2 where both values are the same.
4#[derive(Default, Debug, Eq, PartialEq, PartialOrd, Ord, Copy, Clone)]
5pub struct Vec2 {
6 pub x: u16,
7 pub y: u16,
8}
9
10impl From<(u16, u16)> for Vec2 {
11 fn from(value: (u16, u16)) -> Self {
12 vec2(value.0, value.1)
13 }
14}
15
16impl From<u16> for Vec2 {
17 fn from(value: u16) -> Self {
18 vec2(value, value)
19 }
20}
21
22/// Creates a Vec2 from the given inputs.
23pub fn vec2(x: u16, y: u16) -> Vec2 {
24 Vec2 { x, y }
25}