pub struct Vector2<T: Clone> {
    pub x: T,
    pub y: T,
}
Expand description

Raw Vector2 type

Fields§

§x: T§y: T

Implementations§

source§

impl<T: Clone> Vector2<T>

source

pub const fn new(x: T, y: T) -> Self

Examples found in repository?
examples/multi-movement.rs (line 14)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const BLOCK_SIZE: Vec2D = Vec2D::new(4, 2);
const FILL_CHAR: ColChar = ColChar::SOLID;

fn main() {
    let mut view = View::new(50, 12, ColChar::BACKGROUND);

    let mut blocks = vec![
        Rect::new(Vec2D::new(0, 0), BLOCK_SIZE, FILL_CHAR),
        Rect::new(Vec2D::new(0, 2), BLOCK_SIZE, FILL_CHAR),
        Rect::new(Vec2D::new(0, 4), BLOCK_SIZE, FILL_CHAR),
        Rect::new(Vec2D::new(0, 6), BLOCK_SIZE, FILL_CHAR),
        Rect::new(Vec2D::new(0, 8), BLOCK_SIZE, FILL_CHAR),
        Rect::new(Vec2D::new(0, 10), BLOCK_SIZE, FILL_CHAR),
    ];

    let mut i = 0;
    fps_gameloop!(
        {
            i += 1;
            for j in 0..blocks.len() {
                if i % 2_u32.pow(j as u32) == 0 {
                    blocks[j].pos.x += 1;
                }
            }
        },
        {
            view.clear();
            for block in &blocks {
                view.blit(block, Wrapping::Wrap);
            }
            view.display_render().unwrap();

            if blocks.iter().all(|b| b.pos.x % view.width as isize == 0) {
                thread::sleep(Duration::from_secs(2));
            };
        },
        200.0
    );
}
source

pub fn as_tuple(&self) -> (T, T)

source§

impl Vector2<isize>

source

pub const ZERO: Vec2D = _

A Vec2D of (0,0)

Trait Implementations§

source§

impl<T: Clone + Add<Output = T>> Add<Vector2<T>> for Vector2<T>

§

type Output = Vector2<T>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
source§

impl<T: Clone + AddAssign> AddAssign<Vector2<T>> for Vector2<T>

source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
source§

impl<T: Clone + Clone> Clone for Vector2<T>

source§

fn clone(&self) -> Vector2<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug + Clone> Debug for Vector2<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Clone + Div<Output = T>> Div<T> for Vector2<T>

§

type Output = Vector2<T>

The resulting type after applying the / operator.
source§

fn div(self, rhs: T) -> Self::Output

Performs the / operation. Read more
source§

impl<T: Clone + DivAssign> DivAssign<T> for Vector2<T>

source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
source§

impl<T: Clone> From<(T, T)> for Vector2<T>

source§

fn from(value: (T, T)) -> Self

Converts to this type from the input type.
source§

impl<T: PartialEq + Clone> PartialEq<Vector2<T>> for Vector2<T>

source§

fn eq(&self, other: &Vector2<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Rem<Vector2<isize>> for Vec2D

§

type Output = Vector2<isize>

The resulting type after applying the % operator.
source§

fn rem(self, rhs: Self) -> Self::Output

Performs the % operation. Read more
source§

impl RemAssign<Vector2<isize>> for Vec2D

source§

fn rem_assign(&mut self, rhs: Self)

Performs the %= operation. Read more
source§

impl<T: Clone + Sub<Output = T>> Sub<Vector2<T>> for Vector2<T>

§

type Output = Vector2<T>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
source§

impl<T: Clone + SubAssign> SubAssign<Vector2<T>> for Vector2<T>

source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
source§

impl<T: Copy + Clone> Copy for Vector2<T>

source§

impl<T: Clone> StructuralPartialEq for Vector2<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Vector2<T>where T: RefUnwindSafe,

§

impl<T> Send for Vector2<T>where T: Send,

§

impl<T> Sync for Vector2<T>where T: Sync,

§

impl<T> Unpin for Vector2<T>where T: Unpin,

§

impl<T> UnwindSafe for Vector2<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.