pub struct Vector2 {
pub x: f64,
pub y: f64,
}Expand description
A free vector in the plane.
Fields§
§x: f64X component.
y: f64Y component.
Implementations§
Source§impl Vector2
impl Vector2
Sourcepub const fn from_array([x, y]: [f64; 2]) -> Self
pub const fn from_array([x, y]: [f64; 2]) -> Self
A vector from an array.
Sourcepub fn dot(self, other: Self) -> f64
pub fn dot(self, other: Self) -> f64
Dot product.
Two terms, so no fused multiply-add; see Vector::cross for why.
Sourcepub fn cross(self, other: Self) -> f64
pub fn cross(self, other: Self) -> f64
The scalar cross product: the signed area of the parallelogram the two
vectors span. Positive when other is counter-clockwise from self.
Sourcepub fn square_magnitude(self) -> f64
pub fn square_magnitude(self) -> f64
Squared magnitude.
Sourcepub const fn perpendicular(self) -> Self
pub const fn perpendicular(self) -> Self
This vector rotated a quarter turn counter-clockwise. Exact: no trigonometry involved.
Sourcepub fn normalized(self, tol: Tolerances) -> OgeomResult<Self>
pub fn normalized(self, tol: Tolerances) -> OgeomResult<Self>
This vector scaled to unit length.
§Errors
OgeomError::Construction if the
magnitude is below tol.confusion(), or if any component is non-finite.
Sourcepub fn is_zero(self, tol: Tolerances) -> bool
pub fn is_zero(self, tol: Tolerances) -> bool
Whether the magnitude is within tol.confusion() of zero.
Sourcepub fn is_equal(self, other: Self, tol: Tolerances) -> bool
pub fn is_equal(self, other: Self, tol: Tolerances) -> bool
Whether two vectors agree component-wise within tol.confusion().
Sourcepub fn angle(self, other: Self, tol: Tolerances) -> OgeomResult<f64>
pub fn angle(self, other: Self, tol: Tolerances) -> OgeomResult<f64>
Angle to other, in (-π, π], positive counter-clockwise.
§Errors
OgeomError::Construction if either
vector is degenerate.
Trait Implementations§
Source§impl AddAssign for Vector2
impl AddAssign for Vector2
Source§fn add_assign(&mut self, o: Self)
fn add_assign(&mut self, o: Self)
+= operation. Read moreSource§impl AddAssign<Vector2> for Point2
impl AddAssign<Vector2> for Point2
Source§fn add_assign(&mut self, v: Vector2)
fn add_assign(&mut self, v: Vector2)
+= operation. Read moreimpl Copy for Vector2
Source§impl DivAssign<f64> for Vector2
impl DivAssign<f64> for Vector2
Source§fn div_assign(&mut self, s: f64)
fn div_assign(&mut self, s: f64)
/= operation. Read moreSource§impl From<Direction2> for Vector2
impl From<Direction2> for Vector2
Source§fn from(d: Direction2) -> Self
fn from(d: Direction2) -> Self
Source§impl MulAssign<f64> for Vector2
impl MulAssign<f64> for Vector2
Source§fn mul_assign(&mut self, s: f64)
fn mul_assign(&mut self, s: f64)
*= operation. Read moreimpl 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T, Right> ClosedAdd<Right> for T
impl<T, Right> ClosedAddAssign<Right> for Twhere
T: ClosedAdd<Right> + AddAssign<Right>,
impl<T, Right> ClosedDiv<Right> for T
impl<T, Right> ClosedDivAssign<Right> for Twhere
T: ClosedDiv<Right> + DivAssign<Right>,
impl<T, Right> ClosedMul<Right> for T
impl<T, Right> ClosedMulAssign<Right> for Twhere
T: ClosedMul<Right> + MulAssign<Right>,
impl<T> ClosedNeg for Twhere
T: Neg<Output = T>,
impl<T, Right> ClosedSub<Right> for T
impl<T, Right> ClosedSubAssign<Right> for Twhere
T: ClosedSub<Right> + SubAssign<Right>,
impl<T> Scalar for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.