pub struct Vector { /* private fields */ }Expand description
An immutable vector in 2-space. This represents size and direction.
See Point
Implementations§
Source§impl Vector
impl Vector
pub fn new(x: f64, y: f64) -> Self
pub fn up() -> Self
pub fn down() -> Self
pub fn zero() -> Self
pub fn norm(&self) -> f64
pub fn x(&self) -> f64
pub fn y(&self) -> f64
Sourcepub fn rotate(&self, degrees: f64) -> Self
pub fn rotate(&self, degrees: f64) -> Self
Returns a vector rotated by the given degrees.
Here is an example of how to make use of rotations. Note
that rust has built in support for converting between degrees and radians.
See f64::to_radians and f64::to_degrees.
use rusty_systems::geometry::Vector;
let up = Vector::up();
let left = up.rotate(90.0);
assert!((up - Vector::new(0.0, 1.0)).norm() < 0.001); // The up vector is (0, 1)
assert!((left - Vector::new(-1.0, 0.0)).norm() < 0.001) // rotated by 90º, it points (-1, 0)Trait Implementations§
impl Copy for Vector
impl StructuralPartialEq for Vector
Auto Trait Implementations§
impl Freeze for Vector
impl RefUnwindSafe for Vector
impl Send for Vector
impl Sync for Vector
impl Unpin for Vector
impl UnwindSafe for Vector
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