pub struct Vec2<T>(pub T, pub T);
Expand description

2次元ベクトル

Tuple Fields§

§0: T§1: T

Implementations§

source§

impl Vec2<f64>

source

pub fn dist(&self, other: Self) -> f64

2点間のユークリッド距離を求める

\|\boldsymbol{a} - \boldsymbol{b}\| = \sqrt{(a_x - b_x)^2 + (a_y - b_y)^2}
source

pub fn norm(&self) -> f64

ノルムを求める

\|\boldsymbol{a}\| = \sqrt{a_x^2 + a_y^2}
source

pub fn unit(&self) -> Self

同じ向きの単位ベクトルを求める

source

pub fn normal(&self) -> Self

法線ベクトル (90度回転させたベクトル) を求める

source

pub fn rotate_o(&self, theta: f64) -> Self

原点周りに $\theta$ 回転させた点を求める

source§

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

source

pub fn dot(&self, other: Self) -> T

2つのベクトルのドット積を求める

\boldsymbol{a}\cdot\boldsymbol{b} = a_x b_x + a_y b_y
source

pub fn norm2(&self) -> T

ノルムの2乗を求める

\|\boldsymbol{a}\|^2 = a_x^2 + a_y^2
source

pub fn dist2(&self, other: Self) -> T

ベクトル同士の距離の2乗を求める

\|\boldsymbol{a} - \boldsymbol{b}\|^2 = (a_x - b_x)^2 + (a_y - b_y)^2
source

pub fn cross(&self, other: Self) -> T

クロス積を求める

\boldsymbol{a} \times \boldsymbol{b} = a_x b_y - a_y b_x

Trait Implementations§

source§

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

§

type Output = Vec2<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> Clone for Vec2<T>

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> Debug for Vec2<T>

source§

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

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

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

§

type Output = Vec2<T>

The resulting type after applying the / operator.
source§

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

Performs the / operation. Read more
source§

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

source§

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

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: Mul<Output = T> + Clone,

§

type Output = Vec2<T>

The resulting type after applying the * operator.
source§

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

Performs the * operation. Read more
source§

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

§

type Output = Vec2<T>

The resulting type after applying the - operator.
source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
source§

impl<T: PrimInt> PartialEq<Vec2<T>> for Vec2<T>

source§

fn eq(&self, other: &Self) -> 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 PartialEq<Vec2<f64>> for Point

source§

fn eq(&self, other: &Self) -> 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<T> Sub<Vec2<T>> for Vec2<T>where T: Sub<Output = T>,

§

type Output = Vec2<T>

The resulting type after applying the - operator.
source§

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

Performs the - operation. Read more
source§

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

source§

impl<T: PrimInt> Eq for Vec2<T>

Auto Trait Implementations§

§

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 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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · 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.
const: unstable · source§

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

Performs the conversion.
§

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

§

fn vzip(self) -> V