Struct Vector2

Source
#[repr(C)]
pub struct Vector2<T> { pub x: T, pub y: T, }

Fields§

§x: T§y: T

Implementations§

Source§

impl<T> Vector2<T>

Source

pub fn new(x: T, y: T) -> Vector2<T>

Examples found in repository?
examples/canvas.rs (line 17)
15    fn new() -> Self {
16        let canvas = Canvas::new(160, 95).unwrap();
17        MyGame { canvas, pos: Vec2::new(0.0, 16.0), time: 0.0 }
18    }
19
20    fn run(&mut self, dt: f32, render: &mut Self::Render) -> bool {
21        let speed = 80.0 * dt;
22        self.time = self.time + (dt * 30.0);
23        if cafe::keyboard::is_down(Scancode::Left) {
24            self.pos -= Vec2::new(speed, 0.0);
25        }
26        else if cafe::keyboard::is_down(Scancode::Right) {
27            self.pos += Vec2::new(speed, 0.0);
28        }
29        render.begin();
30        render.set_clear_color(Color::black());
31        render.clear();
32
33        render.set_canvas(Some(&self.canvas));
34        render.clear();
35        render.draw_rect(&Rect::new(self.pos.x, self.pos.y, 32.0, 64.0));
36        // render.hello_triangle();
37        render.set_canvas(None);
38
39        render.blit(&self.canvas, None, 0.0, 0.0);
40        render.blit_rotate(&self.canvas, None, 32.0, 64.0, self.time); 
41        render.fill_circle(32.0, 64.0, 8.0);
42        render.hello_triangle();
43
44        render.end();
45        true
46    }
Source

pub fn as_array(&self) -> [&T; 2]

Source

pub fn stride() -> usize

Trait Implementations§

Source§

impl<T> Add for Vector2<T>
where T: Add<Output = T> + Add,

Source§

type Output = Vector2<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Vector2<T>) -> <Vector2<T> as Add>::Output

Performs the + operation. Read more
Source§

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

Source§

fn add_assign(&mut self, rhs: Vector2<T>)

Performs the += operation. Read more
Source§

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

Source§

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

Returns a duplicate 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 for Vector2<T>
where T: Debug,

Source§

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

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

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

Source§

fn default() -> Vector2<T>

Returns the “default value” for a type. Read more
Source§

impl<T> GlAttrib for Vector2<T>
where T: GlEnum,

Source§

fn size() -> u32

Source§

fn stride() -> usize

Source§

fn get_size(&self) -> u32

Source§

fn get_stride(&self) -> usize

Source§

fn setup_attrib(index: u32, normalized: bool, stride: i32, start: i32)

Source§

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

Source§

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

Source§

fn uniform(location: i32, val: &Vector2<T>)

Source§

fn uniformv(location: i32, count: i32, ptr: *const Vector2<T>)

Source§

fn send_uniform(&self, location: i32)

Source§

impl GlslType for Vector2<bool>

Source§

impl GlslType for Vector2<f32>

Source§

impl GlslType for Vector2<i32>

Source§

impl GlslType for Vector2<u32>

Source§

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

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Sub for Vector2<T>
where T: Sub<Output = T> + Sub,

Source§

type Output = Vector2<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Vector2<T>) -> <Vector2<T> as Sub>::Output

Performs the - operation. Read more
Source§

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

Source§

fn sub_assign(&mut self, rhs: Vector2<T>)

Performs the -= operation. Read more
Source§

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

Source§

impl<T> StructuralPartialEq for Vector2<T>

Auto Trait Implementations§

§

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

§

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 T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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 T
where T: Clone,

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.