Struct iron_shapes::vector::Vector [−][src]
Vector
defines a two dimensional vector with x and y components in the Euclidean plane.
Fields
x: T
x
coordinate.
y: T
y
coordinate.
Implementations
impl<T: CoordinateType> Vector<T>
[src]
pub fn new(x: T, y: T) -> Self
[src]
Create a new vector with x
and y
coordinates.
Examples
use iron_shapes::vector::Vector; let a = Vector::new(2, 3); assert_eq!(a.x, 2); assert_eq!(a.y, 3);
pub fn norm1(&self) -> T
[src]
Get 1-norm of vector, i.e. the sum of the absolute values of its components.
Examples
use iron_shapes::vector::Vector; let a = Vector::new(-2, 3); assert_eq!(a.norm1(), 5);
pub fn norm2_squared(&self) -> T
[src]
Get squared 2-norm of vector.
Examples
use iron_shapes::vector::Vector; let a = Vector::new(2, 3); assert_eq!(a.norm2_squared(), 2*2+3*3);
pub fn dot(&self, other: Self) -> T
[src]
Calculate scalar product.
Examples
use iron_shapes::vector::Vector; let a = Vector::new(1, 2); let b = Vector::new(3, 4); assert_eq!(a.dot(b), 1*3 + 2*4);
pub fn cross_prod(&self, other: Self) -> T
[src]
Calculate cross product.
Examples
use iron_shapes::vector::Vector; let a = Vector::new(2, 0); let b = Vector::new(0, 2); assert_eq!(a.cross_prod(b), 4); assert_eq!(b.cross_prod(a), -4);
pub fn orientation_of(&self, other: Self) -> Orientation
[src]
Check if other
is oriented clockwise or counter-clockwise respective to self
.
Examples
use iron_shapes::vector::Vector; use iron_shapes::types::Orientation; let a = Vector::new(1, 0); let b = Vector::new(1, 1); let c = Vector::new(1, -1); let d = Vector::new(2, 0); assert_eq!(a.orientation_of(b), Orientation::CounterClockWise); assert_eq!(a.orientation_of(c), Orientation::ClockWise); assert_eq!(a.orientation_of(d), Orientation::Straight);
impl<T: CoordinateType + NumCast> Vector<T>
[src]
pub fn cast_to_float<F: CoordinateType + Float + NumCast>(&self) -> Vector<F>
[src]
Convert vector into a vector with floating point data type.
impl<T: CoordinateType + Float> Vector<T>
[src]
pub fn norm2(&self) -> T
[src]
Get 2-norm of vector (length of vector).
Examples
use iron_shapes::vector::Vector; let a = Vector::new(2.0, 3.0); let norm2 = a.norm2(); let norm2_sq = norm2 * norm2; let expected = a.norm2_squared(); assert!(norm2_sq < expected + 1e-12); assert!(norm2_sq > expected - 1e-12);
pub fn normalized(&self) -> Self
[src]
pub fn normal(&self) -> Self
[src]
Return the normal vector onto this vector. The normal has length 0.
Panics
Panics if the vector has length 0.
impl<T: CoordinateType + NumCast> Vector<T>
[src]
pub fn length<F: Float>(&self) -> F
[src]
Calculate length of vector.
Similar to Vector::norm2
but does potentially return another data type for the length.
Examples
use iron_shapes::vector::Vector; let a = Vector::new(2.0, 3.0); let length: f64 = a.length(); let norm2_sq = length * length; let expected = a.norm2_squared(); assert!(norm2_sq < expected + 1e-12); assert!(norm2_sq > expected - 1e-12);
Trait Implementations
impl<T> Add<Vector<T>> for Vector<T> where
T: CoordinateType + Add<Output = T>,
[src]
T: CoordinateType + Add<Output = T>,
Vector addition.
type Output = Self
The resulting type after applying the +
operator.
fn add(self, rhs: Self) -> Self
[src]
impl<T> AddAssign<Vector<T>> for Vector<T> where
T: CoordinateType + AddAssign,
[src]
T: CoordinateType + AddAssign,
fn add_assign(&mut self, rhs: Self)
[src]
impl<T: Clone> Clone for Vector<T>
[src]
impl<T: Copy> Copy for Vector<T>
[src]
impl<T> Debug for Vector<T> where
T: Debug + Copy,
[src]
T: Debug + Copy,
impl<T: Default> Default for Vector<T>
[src]
impl<T> Display for Vector<T> where
T: Display + Copy,
[src]
T: Display + Copy,
impl<T> Div<T> for Vector<T> where
T: CoordinateType + Div<Output = T>,
[src]
T: CoordinateType + Div<Output = T>,
Scalar division.
type Output = Self
The resulting type after applying the /
operator.
fn div(self, rhs: T) -> Self
[src]
impl<T: Eq> Eq for Vector<T>
[src]
impl<T: CoordinateType> From<&'_ Vector<T>> for Point<T>
[src]
impl<'a, T: CoordinateType> From<&'a (T, T)> for Vector<T>
[src]
impl<'a, T: CoordinateType> From<&'a Vector<T>> for Vector<T>
[src]
impl<T: CoordinateType> From<[T; 2]> for Vector<T>
[src]
impl<T: CoordinateType> From<(T, T)> for Vector<T>
[src]
impl<T: CoordinateType> From<Vector<T>> for Point<T>
[src]
impl<T: Hash> Hash for Vector<T>
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T: CoordinateType> Into<(T, T)> for Vector<T>
[src]
impl<T: CoordinateType> Into<(T, T)> for &Vector<T>
[src]
impl<T: CoordinateType> Into<Vector<T>> for Point<T>
[src]
impl<T: CoordinateType> MapPointwise<T> for Vector<T>
[src]
impl<T> Mul<T> for Vector<T> where
T: CoordinateType + Mul<Output = T>,
[src]
T: CoordinateType + Mul<Output = T>,
Scalar multiplication.
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, rhs: T) -> Self
[src]
impl<T> MulAssign<T> for Vector<T> where
T: CoordinateType + MulAssign<T>,
[src]
T: CoordinateType + MulAssign<T>,
In-place scalar multiplication.
fn mul_assign(&mut self, rhs: T)
[src]
impl<T> Neg for Vector<T> where
T: CoordinateType,
[src]
T: CoordinateType,
impl<T: PartialEq> PartialEq<Vector<T>> for Vector<T>
[src]
impl<T> StructuralEq for Vector<T>
[src]
impl<T> StructuralPartialEq for Vector<T>
[src]
impl<T> Sub<Vector<T>> for Vector<T> where
T: CoordinateType + Sub<Output = T>,
[src]
T: CoordinateType + Sub<Output = T>,
Vector subtraction.
type Output = Self
The resulting type after applying the -
operator.
fn sub(self, rhs: Self) -> Self
[src]
impl<T> Sub<Vector<T>> for Point<T> where
T: CoordinateType + Sub<Output = T>,
[src]
T: CoordinateType + Sub<Output = T>,
Subtract a vector.
type Output = Point<T>
The resulting type after applying the -
operator.
fn sub(self, rhs: Vector<T>) -> Self::Output
[src]
impl<T> SubAssign<Vector<T>> for Vector<T> where
T: CoordinateType + SubAssign,
[src]
T: CoordinateType + SubAssign,
fn sub_assign(&mut self, rhs: Self)
[src]
impl<T: CoordinateType> Sum<Vector<T>> for Vector<T>
[src]
Compute the sum of all vectors in the iterator. If the iterator is empty, (0, 0) is returned.
impl<T: CoordinateType + NumCast, Dst: CoordinateType + NumCast> TryCastCoord<T, Dst> for Vector<T>
[src]
type Output = Vector<Dst>
Output type of the cast. This is likely the same geometrical type just with other coordinate types. Read more
fn try_cast(&self) -> Option<Self::Output>
[src]
Try to cast to vector of target data type.
Conversion from float to int can fail and will return None
.
Float values like infinity or non-a-number
have no integer representation.
Examples
use iron_shapes::vector::Vector; use iron_shapes::traits::TryCastCoord; let v_int = Vector::new(1,2); let maybe_v_float: Option<Vector<f64>> = v_int.try_cast(); assert_eq!(maybe_v_float, Some(Vector::new(1.0, 2.0))); // Conversion from float to int can fail. let w_float = Vector::new(42.0, 0. / 0.); let maybe_w_int: Option<Vector<i32>> = w_float.try_cast(); assert_eq!(maybe_w_int, None);
fn cast(&self) -> Self::Output
[src]
impl<T: CoordinateType> Zero for Vector<T>
[src]
fn zero() -> Self
[src]
Get zero-vector.
Examples
use iron_shapes::vector::{Vector, Zero}; let a = Vector::zero(); let b = Vector::new(0, 0); assert_eq!(a, b);
fn is_zero(&self) -> bool
[src]
Check if this is the zero-vector.
Examples
use iron_shapes::vector::{Vector, Zero}; assert!(Vector::<usize>::zero().is_zero());
pub fn set_zero(&mut self)
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Vector<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Vector<T> where
T: Send,
T: Send,
impl<T> Sync for Vector<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Vector<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Vector<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<S, T> Mirror<T> for S where
T: CoordinateType,
S: MapPointwise<T>,
[src]
T: CoordinateType,
S: MapPointwise<T>,
pub fn mirror_x(&Self) -> S
[src]
Return the geometrical object mirrored at the x
axis.
pub fn mirror_y(&Self) -> S
[src]
Return the geometrical object mirrored at the y
axis.
impl<S, T> RotateOrtho<T> for S where
T: CoordinateType,
S: MapPointwise<T>,
[src]
T: CoordinateType,
S: MapPointwise<T>,
pub fn rotate_ortho(&Self, Angle) -> S
[src]
impl<S, T> Scale<T> for S where
T: CoordinateType,
S: MapPointwise<T>,
[src]
T: CoordinateType,
S: MapPointwise<T>,
impl<T> TextType for T where
T: Clone + Eq + Debug + Hash,
[src]
T: Clone + Eq + Debug + Hash,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<S, T> Translate<T> for S where
T: CoordinateType,
S: MapPointwise<T>,
[src]
T: CoordinateType,
S: MapPointwise<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,