Enum tmn::Nums

source ·
pub enum Nums {
    Real(f32),
    Complex(CNum),
    Quaternion(QNum),
}
Expand description

Enum for convenient work with different types of numbers

Перечисление для удобной работы с разными видами чисел

Variants§

§

Real(f32)

§

Complex(CNum)

§

Quaternion(QNum)

Implementations§

source§

impl Nums

source

pub fn conj(&self) -> Self

The method for obtaining the conjugate number

Метод для получения сопряженного числа

Example
 use tmn::Nums;
 use tmn::quaternion::QNum;
 let a = Nums::Quaternion(QNum::make_from_r(1_f32, 1_f32, 1_f32, 1_f32));
 let b = a.conj();
 match b{
    Nums::Quaternion(qnum)=>{
        assert_eq!((1_f32, -1_f32, -1_f32, -1_f32), qnum.get())
    },
    _=>panic!("WrongType of Nums")
 }
use tmn::Nums;
use tmn::complex::CNum;
let a = Nums::Complex(CNum::make(1_f32, 1_f32));
let b = a.conj();
match b{
   Nums::Complex(cnum)=>{
       assert_eq!((1_f32, -1_f32), cnum.get())
   },
   _=>panic!("WrongType of Nums")
}
source

pub fn rot(&self, ang: f32, o: (f32, f32, f32)) -> Self

The method for rotating a number around the axis given by the vector ‘o’ by the angle ‘ang’ (Angle in degrees). The axis of rotation only affects the rotation of the quaternion.

Метод для вращения числа вокруг оси, заданной вектором ‘o’ на угол ‘ang’ (Угол в градусах). Ось вращения влияет только на поворот кватерниона.

Example
 use tmn::Nums;
 use tmn::quaternion::QNum;
 let mut a = Nums::Quaternion(QNum::make_from_r(0_f32, 1_f32, 0_f32, 0_f32));
 a = a.rot(90_f32, (0_f32, 0_f32, 1_f32));
 match a {
    Nums::Quaternion(qnum)=>{
        let (r, i, j, k) = qnum.get();//0.0000001 - точность расчетов
        //Ожидаемый ответ 0, 0, 1, 0
        assert!((r-0_f32).abs() < 0.0000001);
        assert!((i-0_f32).abs() < 0.0000001);
        assert!((j-1_f32).abs() < 0.0000001);
        assert!((k-0_f32).abs() < 0.0000001);
    },
    _=>panic!("WrongType of Nums")
 }
source

pub fn set(&self, c: u8, v: f32) -> Self

The method for setting values to specific coefficients

Метод для установки значений в конкретные коэффициенты

Example
 use tmn::{Nums, complex};
 use tmn::complex::CNum;
 let mut a = Nums::Complex(CNum::make_zero());
 a = a.set(complex::R|complex::I, 3_f32);
 assert!(Nums::Complex(CNum::make(3_f32, 3_f32))==a);
source

pub fn clone(&self) -> Self

The method for cloning the Nums element

Метод для клонирования элемента Nums

Example
 use tmn::Nums;
 use tmn::quaternion::QNum;
 let a = Nums::Quaternion(QNum::make_zero());
 let b = a.clone();
 assert!(a==b);

Trait Implementations§

source§

impl Add<Nums> for Nums

source§

fn add(self, rhs: Self) -> Self::Output

The method returns the sum of two Nums elements

Метод возвращает сумму двух элементов Nums

Examples
 use tmn::Nums;
 use tmn::complex::CNum;
 use tmn::quaternion::QNum;

 let a = Nums::Quaternion(QNum::make_from_r(0_f32, 0_f32, 1_f32, 1_f32));
 let b = Nums::Complex(CNum::make(1_f32, 1_f32));

 let c = a+b;
 assert!(Nums::Quaternion(QNum::make_from_r(1_f32,1_f32,1_f32,1_f32))==c);
§

type Output = Nums

The resulting type after applying the + operator.
source§

impl Mul<Nums> for Nums

source§

fn mul(self, rhs: Self) -> Self::Output

The method returns the product of two Nums elements

Метод возвращает произведение двух элементов Nums

Examples
 use tmn::Nums;
 use tmn::complex::CNum;
 use tmn::quaternion::QNum;

 let a = Nums::Quaternion(QNum::make_from_r(0_f32, 4_f32, 7_f32, 1_f32));
 let b = Nums::Complex(CNum::make(43_f32, 2_f32));

 let c = a*b;
 assert!(Nums::Quaternion(QNum::make_from_r(-8_f32, 172_f32, 303_f32, 29_f32))==c);
§

type Output = Nums

The resulting type after applying the * operator.
source§

impl Neg for Nums

source§

fn neg(self) -> Self::Output

Redefined negative operator

Переопределенный оператор отрицательного значения

Example
 use tmn::Nums;
 use tmn::quaternion::QNum;
 let qnum = Nums::Quaternion(-QNum::make_from_r(3_f32, 4_f32, 1_f32, 2_f32));
 assert!(qnum== Nums::Quaternion(QNum::make_from_r(-3_f32, -4_f32, -1_f32, -2_f32)));
§

type Output = Nums

The resulting type after applying the - operator.
source§

impl PartialEq<Nums> for Nums

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl RefUnwindSafe for Nums

§

impl Send for Nums

§

impl Sync for Nums

§

impl Unpin for Nums

§

impl UnwindSafe for Nums

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.