#[repr(C)]pub struct Complex<T> {
pub re: T,
pub im: T,
}Expand description
Complex number.
Fields§
§re: T§im: TImplementations§
Source§impl<T: Float> Complex<T>
impl<T: Float> Complex<T>
Sourcepub fn rotation_between(from: Vec2<T>, to: Vec2<T>) -> Complex<T>
pub fn rotation_between(from: Vec2<T>, to: Vec2<T>) -> Complex<T>
Returns the shortest rotation that aligns vector from with vector to.
The resulting complex number R satisfies:
R * from = toBoth vectors are expected to be normalized. The implementation avoids trigonometric functions.
The 2D rotation is uniquely defined even when the vectors are opposite, so this returns a 180° rotation in that case.
This is useful for constructing a 2D orientation that points one direction vector toward another.
let from = cvmath::Vec2(1.0, 1.0).norm();
let to = cvmath::Vec2(-1.0, 1.0).norm();
let rotation = cvmath::Complex::rotation_between(from, to);
let expected = to.cast::<f32>();
let actual = (rotation * from).cast::<f32>();
assert_eq!(expected, actual);Trait Implementations§
Source§impl<T: AddAssign> AddAssign for Complex<T>
impl<T: AddAssign> AddAssign for Complex<T>
Source§fn add_assign(&mut self, other: Complex<T>)
fn add_assign(&mut self, other: Complex<T>)
Performs the
+= operation. Read moreSource§impl<T: Copy + Mul<Output = T> + Div<Output = T> + Add<Output = T> + Sub<Output = T>> Div for Complex<T>
impl<T: Copy + Mul<Output = T> + Div<Output = T> + Add<Output = T> + Sub<Output = T>> Div for Complex<T>
Source§impl<T: Copy + DivAssign> DivAssign<T> for Complex<T>
impl<T: Copy + DivAssign> DivAssign<T> for Complex<T>
Source§fn div_assign(&mut self, rhs: T)
fn div_assign(&mut self, rhs: T)
Performs the
/= operation. Read moreSource§impl<T: Copy + Mul<Output = T> + Div<Output = T> + Add<Output = T> + Sub<Output = T>> DivAssign for Complex<T>
impl<T: Copy + Mul<Output = T> + Div<Output = T> + Add<Output = T> + Sub<Output = T>> DivAssign for Complex<T>
Source§fn div_assign(&mut self, other: Complex<T>)
fn div_assign(&mut self, other: Complex<T>)
Performs the
/= operation. Read moreSource§impl<T: Copy + Mul<Output = T> + Add<Output = T> + Sub<Output = T>> Mul<Vec2<T>> for Complex<T>
impl<T: Copy + Mul<Output = T> + Add<Output = T> + Sub<Output = T>> Mul<Vec2<T>> for Complex<T>
Source§impl<T: Copy + MulAssign> MulAssign<T> for Complex<T>
impl<T: Copy + MulAssign> MulAssign<T> for Complex<T>
Source§fn mul_assign(&mut self, rhs: T)
fn mul_assign(&mut self, rhs: T)
Performs the
*= operation. Read moreSource§impl<T: Copy + Mul<Output = T> + Add<Output = T> + Sub<Output = T>> MulAssign for Complex<T>
impl<T: Copy + Mul<Output = T> + Add<Output = T> + Sub<Output = T>> MulAssign for Complex<T>
Source§fn mul_assign(&mut self, other: Complex<T>)
fn mul_assign(&mut self, other: Complex<T>)
Performs the
*= operation. Read moreSource§impl<T: SubAssign> SubAssign for Complex<T>
impl<T: SubAssign> SubAssign for Complex<T>
Source§fn sub_assign(&mut self, other: Complex<T>)
fn sub_assign(&mut self, other: Complex<T>)
Performs the
-= operation. Read moreimpl<T: Copy> Copy for Complex<T>
impl<T> StructuralPartialEq for Complex<T>
Auto Trait Implementations§
impl<T> Freeze for Complex<T>where
T: Freeze,
impl<T> RefUnwindSafe for Complex<T>where
T: RefUnwindSafe,
impl<T> Send for Complex<T>where
T: Send,
impl<T> Sync for Complex<T>where
T: Sync,
impl<T> Unpin for Complex<T>where
T: Unpin,
impl<T> UnsafeUnpin for Complex<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Complex<T>where
T: UnwindSafe,
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