Struct Vec2

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

2 dimensional vector.

Fields§

§x: T

x coordinate of the vector

§y: T

y coordinate of the vector

Implementations§

Source§

impl<T> Vec2<T>

Source

pub fn extend(self, z: T) -> Vec3<T>

Extend into a 3-d vector.

§Examples
use batbox::*;
assert_eq!(vec2(1, 2).extend(3), vec3(1, 2, 3));
Source

pub fn map<U, F>(self, f: F) -> Vec2<U>
where F: Fn(T) -> U,

Source§

impl<T> Vec2<T>
where T: Num + Copy,

Source

pub fn dot(a: Vec2<T>, b: Vec2<T>) -> T

Calculate dot product of two vectors.

§Examples
use batbox::*;
assert_eq!(Vec2::dot(vec2(1, 2), vec2(3, 4)), 11);
Source

pub fn skew(a: Vec2<T>, b: Vec2<T>) -> T

Calculate skew product of two vectors.

§Examples
use batbox::*;
assert_eq!(Vec2::skew(vec2(1, 2), vec2(3, 4)), -2);
Source§

impl<T> Vec2<T>
where T: Neg<Output = T>,

Source

pub fn rotate_90(self) -> Vec2<T>

Source§

impl<T> Vec2<T>
where T: Float,

Source

pub fn normalize(self) -> Vec2<T>

Normalize a vector.

§Examples
use batbox::*;
let v: Vec2<f64> = vec2(1.0, 2.0);
assert!((v.normalize().len() - 1.0).abs() < 1e-5);
Source

pub fn len(self) -> T

Calculate length of a vector.

Source

pub fn rotated(v: Vec2<T>, angle: T) -> Vec2<T>

Rotate a vector by a given angle.

Source

pub fn clamp(self, max_len: T) -> Vec2<T>

Source

pub fn arg(self) -> T

Trait Implementations§

Source§

impl<T> Add for Vec2<T>
where T: Add<Output = T>,

Source§

type Output = Vec2<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Vec2<T>) -> Vec2<T>

Performs the + operation. Read more
Source§

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

Source§

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

Performs the += operation. Read more
Source§

impl<U> AsUniform for Vec2<U>
where [U; 2]: Uniform,

Source§

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

Source§

fn clone(&self) -> Vec2<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 for Vec2<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> Deref for Vec2<T>

Source§

type Target = [T; 2]

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<T> DerefMut for Vec2<T>

Source§

fn deref_mut(&mut self) -> &mut [T; 2]

Mutably dereferences the value.
Source§

impl<'de, T> Deserialize<'de> for Vec2<T>
where T: Deserialize<'de>,

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Vec2<T>, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T> Display for Vec2<T>
where T: Display,

Source§

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

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

impl Distribution<Vec2<f32>> for UnitCircleInside

Source§

fn sample<R>(&self, rng: &mut R) -> Vec2<f32>
where R: Rng + ?Sized,

Generate a random value of T, using rng as the source of randomness.
Source§

fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
where R: Rng, Self: Sized,

Create an iterator that generates random values of T, using rng as the source of randomness. Read more
Source§

impl<T> Div<T> for Vec2<T>
where T: Copy + Div<Output = T>,

Source§

type Output = Vec2<T>

The resulting type after applying the / operator.
Source§

fn div(self, rhs: T) -> Vec2<T>

Performs the / operation. Read more
Source§

impl<T> DivAssign<T> for Vec2<T>
where T: Copy + DivAssign,

Source§

fn div_assign(&mut self, rhs: T)

Performs the /= operation. Read more
Source§

impl<T> From<[T; 2]> for Vec2<T>

Source§

fn from(v: [T; 2]) -> Vec2<T>

Converts to this type from the input type.
Source§

impl From<Vec2<f32>> for Vertex

Source§

fn from(v: Vec2<f32>) -> Vertex

Converts to this type from the input type.
Source§

impl<T> Hash for Vec2<T>
where T: Hash,

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> Mul<T> for Vec2<T>
where T: Copy + Mul<Output = T>,

Source§

type Output = Vec2<T>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: T) -> Vec2<T>

Performs the * operation. Read more
Source§

impl Mul<Vec2<f32>> for f32

Source§

type Output = Vec2<f32>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec2<f32>) -> Vec2<f32>

Performs the * operation. Read more
Source§

impl Mul<Vec2<f64>> for f64

Source§

type Output = Vec2<f64>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec2<f64>) -> Vec2<f64>

Performs the * operation. Read more
Source§

impl Mul<Vec2<i16>> for i16

Source§

type Output = Vec2<i16>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec2<i16>) -> Vec2<i16>

Performs the * operation. Read more
Source§

impl Mul<Vec2<i32>> for i32

Source§

type Output = Vec2<i32>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec2<i32>) -> Vec2<i32>

Performs the * operation. Read more
Source§

impl Mul<Vec2<i64>> for i64

Source§

type Output = Vec2<i64>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec2<i64>) -> Vec2<i64>

Performs the * operation. Read more
Source§

impl Mul<Vec2<i8>> for i8

Source§

type Output = Vec2<i8>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec2<i8>) -> Vec2<i8>

Performs the * operation. Read more
Source§

impl Mul<Vec2<isize>> for isize

Source§

type Output = Vec2<isize>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec2<isize>) -> Vec2<isize>

Performs the * operation. Read more
Source§

impl Mul<Vec2<u16>> for u16

Source§

type Output = Vec2<u16>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec2<u16>) -> Vec2<u16>

Performs the * operation. Read more
Source§

impl Mul<Vec2<u32>> for u32

Source§

type Output = Vec2<u32>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec2<u32>) -> Vec2<u32>

Performs the * operation. Read more
Source§

impl Mul<Vec2<u64>> for u64

Source§

type Output = Vec2<u64>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec2<u64>) -> Vec2<u64>

Performs the * operation. Read more
Source§

impl Mul<Vec2<u8>> for u8

Source§

type Output = Vec2<u8>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec2<u8>) -> Vec2<u8>

Performs the * operation. Read more
Source§

impl Mul<Vec2<usize>> for usize

Source§

type Output = Vec2<usize>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Vec2<usize>) -> Vec2<usize>

Performs the * operation. Read more
Source§

impl<T> MulAssign<T> for Vec2<T>
where T: Copy + MulAssign,

Source§

fn mul_assign(&mut self, rhs: T)

Performs the *= operation. Read more
Source§

impl<T> Neg for Vec2<T>
where T: Neg<Output = T>,

Source§

type Output = Vec2<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Vec2<T>

Performs the unary - operation. Read more
Source§

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

Source§

fn eq(&self, other: &Vec2<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> Serialize for Vec2<T>
where T: Serialize,

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T> Sub for Vec2<T>
where T: Sub<Output = T>,

Source§

type Output = Vec2<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Vec2<T>) -> Vec2<T>

Performs the - operation. Read more
Source§

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

Source§

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

Performs the -= operation. Read more
Source§

impl<T> Trans for Vec2<T>
where T: Trans,

Source§

fn create_schema() -> Schema

Source§

fn write_to(&self, writer: &mut dyn Write) -> Result<(), Error>

Source§

fn read_from(reader: &mut dyn Read) -> Result<Vec2<T>, Error>

Source§

impl VertexAttribute for Vec2<f32>

Source§

const SIZE: usize = 2usize

Source§

const TYPE: AttributeType = AttributeType::Float

Source§

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

Source§

impl<T> Eq for Vec2<T>
where T: Eq,

Source§

impl<T> StructuralPartialEq for Vec2<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Vec2<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> Configurable for T
where T: ToString + Clone,

Source§

type Config = ShowValue<T>

Source§

fn config(theme: &Rc<Theme>, value: T) -> ShowValue<T>

Source§

impl<T> Diff for T
where T: Debug + Serialize + for<'de> Deserialize<'de> + Trans + Sync + Send + Copy + PartialEq + 'static,

Source§

type Delta = T

Source§

fn diff(&self, to: &T) -> T

Source§

fn update(&mut self, new_value: &T)

Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<T> Uniform for T
where T: AsUniform,

Source§

fn apply(&self, gl: &Context, info: &UniformInfo)

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> Message for T
where T: Debug + Serialize + for<'de> Deserialize<'de> + Send + 'static,