pub struct Vector2 {
pub x: f64,
pub y: f64,
}Expand description
A 2D column vector.
Fields§
§x: f64The first component.
y: f64The second component.
Implementations§
Source§impl Vector2
impl Vector2
Sourcepub const fn new(x: f64, y: f64) -> Self
pub const fn new(x: f64, y: f64) -> Self
Creates a vector from two components.
Examples found in repository?
examples/basic_usage.rs (line 4)
3fn main() -> Result<(), use_linear::LinearError> {
4 let vector = Vector2::new(3.0, 4.0);
5 let basis = Matrix2::new(2.0, 1.0, 5.0, 3.0);
6 let rhs = Vector2::new(1.0, 2.0);
7
8 assert!((dot(vector, Vector2::new(-2.0, 1.0)) + 2.0).abs() < 1.0e-12);
9 assert!((vector.magnitude() - 5.0).abs() < 1.0e-12);
10 assert_eq!(
11 basis.mul_vector(Vector2::new(1.0, -1.0)),
12 Vector2::new(1.0, 2.0)
13 );
14 assert_eq!(basis * Matrix2::identity(), basis);
15 assert_eq!(solve_2x2(basis, rhs)?, Vector2::new(1.0, -1.0));
16
17 Ok(())
18}Sourcepub const fn magnitude_squared(self) -> f64
pub const fn magnitude_squared(self) -> f64
Returns the squared Euclidean norm.
Sourcepub fn magnitude(self) -> f64
pub fn magnitude(self) -> f64
Returns the Euclidean norm.
Examples found in repository?
examples/basic_usage.rs (line 9)
3fn main() -> Result<(), use_linear::LinearError> {
4 let vector = Vector2::new(3.0, 4.0);
5 let basis = Matrix2::new(2.0, 1.0, 5.0, 3.0);
6 let rhs = Vector2::new(1.0, 2.0);
7
8 assert!((dot(vector, Vector2::new(-2.0, 1.0)) + 2.0).abs() < 1.0e-12);
9 assert!((vector.magnitude() - 5.0).abs() < 1.0e-12);
10 assert_eq!(
11 basis.mul_vector(Vector2::new(1.0, -1.0)),
12 Vector2::new(1.0, 2.0)
13 );
14 assert_eq!(basis * Matrix2::identity(), basis);
15 assert_eq!(solve_2x2(basis, rhs)?, Vector2::new(1.0, -1.0));
16
17 Ok(())
18}Trait Implementations§
impl Copy for Vector2
impl StructuralPartialEq for Vector2
Auto Trait Implementations§
impl Freeze for Vector2
impl RefUnwindSafe for Vector2
impl Send for Vector2
impl Sync for Vector2
impl Unpin for Vector2
impl UnsafeUnpin for Vector2
impl UnwindSafe for Vector2
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more