Struct libreda_db::layout::prelude::Vector [−][src]
pub struct Vector<T> {
pub x: T,
pub y: T,
}
Expand description
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
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);
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);
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);
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);
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);
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);
Convert vector into a vector with floating point data type.
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);
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
Vector addition.
Performs the +=
operation. Read more
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<Vector<T>, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<Vector<T>, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Scalar division.
Scalar multiplication.
pub fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
pub 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
Vector subtraction.
Subtract a vector.
Performs the -=
operation. Read more
Compute the sum of all vectors in the iterator. If the iterator is empty, (0, 0) is returned.
impl<T, Dst> TryCastCoord<T, Dst> for Vector<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
impl<T, Dst> TryCastCoord<T, Dst> for Vector<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
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);
Output type of the cast. This is likely the same geometrical type just with other coordinate types. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for Vector<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Vector<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Rotate the geometrical shape by a multiple of 90 degrees.