Struct geng::prelude::Angle

pub struct Angle<T = f32>
where T: Float,
{ /* private fields */ }
Expand description

This struct represents an angle in 2d space,

Implementations§

§

impl<T> Angle<T>
where T: Float,

pub const ZERO: Angle<T> = _

0 angle is pointing to positive x axis

pub fn map<U>(&self, f: impl Fn(T) -> U) -> Angle<U>
where U: Float,

Map inner value to a different type

pub fn acos(cos: T) -> Angle<T>

Computes the arccosine of a number as an angle.

Return value is in radians in the range [0, pi] or NaN if the number is outside the range [-1, 1].

pub fn asin(sin: T) -> Angle<T>

Computes the arcsine of a number as an angle.

Return value is in radians in the range [-pi/2, pi/2] or NaN if the number is outside the range [-1, 1].

pub fn atan(tan: T) -> Angle<T>

Computes the arctangent of a number as an angle.

Return value is in radians in the range [-pi/2, pi/2];

pub fn atan2(y: T, x: T) -> Angle<T>

Computes the four quadrant arctangent of self (y) and other (x) as an angle.

  • x = 0, y = 0: 0
  • x >= 0: arctan(y/x) -> [-pi/2, pi/2]
  • y >= 0: arctan(y/x) + pi -> (pi/2, pi]
  • y < 0: arctan(y/x) - pi -> (-pi, -pi/2)

pub fn sin(&self) -> T

Compute the sine

pub fn cos(&self) -> T

Compute the cosine

pub fn sin_cos(&self) -> (T, T)

Simultaneously computes the sine and cosine of the angle. Returns (sin(self), cos(self)).

pub fn tan(self) -> T

Computes the tangent of the angle.

pub fn from_radians(radians: T) -> Angle<T>

Create angle from value in radians

pub fn from_degrees(degrees: T) -> Angle<T>

Create angle from value in degrees

pub fn as_radians(&self) -> T

See angle value as radians

pub fn as_degrees(&self) -> T

See angle value as degrees

pub fn normalized_2pi(&self) -> Angle<T>

Normalize the angle to be in range 0..2*pi.

pub fn abs(&self) -> Angle<T>

Calculate absolute value

pub fn normalized_pi(&self) -> Angle<T>

Normalize the angle to be in range -pi..pi.

pub fn angle_from(&self, from: Angle<T>) -> Angle<T>

Calculates the angle between from and self in range -pi..pi.

pub fn angle_to(&self, target: Angle<T>) -> Angle<T>

Calculates the angle between self and target in range -pi..pi.

pub fn unit_vec(&self) -> vec2<T>

Returns a direction vector of unit length.

Trait Implementations§

§

impl<T> Add for Angle<T>
where T: Float,

§

type Output = Angle<T>

The resulting type after applying the + operator.
§

fn add(self, rhs: Angle<T>) -> <Angle<T> as Add>::Output

Performs the + operation. Read more
§

impl<T> AddAssign for Angle<T>
where T: Float,

§

fn add_assign(&mut self, rhs: Angle<T>)

Performs the += operation. Read more
§

impl<T> Clone for Angle<T>
where T: Clone + Float,

§

fn clone(&self) -> Angle<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<T> Debug for Angle<T>
where T: Debug + Float,

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<'de, T> Deserialize<'de> for Angle<T>
where T: Float + Deserialize<'de>,

§

fn deserialize<__D>( __deserializer: __D ) -> Result<Angle<T>, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl<T> Distribution<Angle<T>> for Standard
where T: Float,

§

fn sample<R>(&self, rng: &mut R) -> Angle<T>
where R: Rng + ?Sized,

Generate a random value of T, using rng as the source of randomness.
source§

fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
where R: Rng, Self: Sized,

Create an iterator that generates random values of T, using rng as the source of randomness. Read more
source§

fn map<F, S>(self, func: F) -> DistMap<Self, F, T, S>
where F: Fn(T) -> S, Self: Sized,

Create a distribution of values of ‘S’ by mapping the output of Self through the closure F Read more
§

impl<T> Div<T> for Angle<T>
where T: Float,

§

type Output = Angle<T>

The resulting type after applying the / operator.
§

fn div(self, rhs: T) -> <Angle<T> as Div<T>>::Output

Performs the / operation. Read more
§

impl<T> Mul<T> for Angle<T>
where T: Float,

§

type Output = Angle<T>

The resulting type after applying the * operator.
§

fn mul(self, rhs: T) -> <Angle<T> as Mul<T>>::Output

Performs the * operation. Read more
§

impl<T> Neg for Angle<T>
where T: Float,

§

type Output = Angle<T>

The resulting type after applying the - operator.
§

fn neg(self) -> <Angle<T> as Neg>::Output

Performs the unary - operation. Read more
§

impl<T> Ord for Angle<T>
where T: Ord + Float,

§

fn cmp(&self, other: &Angle<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
§

impl<T> PartialEq for Angle<T>
where T: PartialEq + Float,

§

fn eq(&self, other: &Angle<T>) -> 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.
§

impl<T> PartialOrd for Angle<T>
where T: PartialOrd + Float,

§

fn partial_cmp(&self, other: &Angle<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl<T> Serialize for Angle<T>
where T: Float + Serialize,

§

fn serialize<__S>( &self, __serializer: __S ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl<T> Sub for Angle<T>
where T: Float,

§

type Output = Angle<T>

The resulting type after applying the - operator.
§

fn sub(self, rhs: Angle<T>) -> <Angle<T> as Sub>::Output

Performs the - operation. Read more
§

impl<T> SubAssign for Angle<T>
where T: Float,

§

fn sub_assign(&mut self, rhs: Angle<T>)

Performs the -= operation. Read more
§

impl<T> Copy for Angle<T>
where T: Copy + Float,

§

impl<T> Eq for Angle<T>
where T: Eq + Float,

§

impl<T> StructuralEq for Angle<T>
where T: Float,

§

impl<T> StructuralPartialEq for Angle<T>
where T: Float,

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Angle<T>
where T: RefUnwindSafe,

§

impl<T> Send for Angle<T>
where T: Send,

§

impl<T> Sync for Angle<T>
where T: Sync,

§

impl<T> Unpin for Angle<T>
where T: Unpin,

§

impl<T> UnwindSafe for Angle<T>
where T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
§

impl<T> Clamp for T
where T: PartialOrd,

§

fn clamp_range(self, range: impl FixedRangeBounds<Self>) -> Self
where Self: Clone,

Clamps a value in range. Read more
§

fn clamp_abs(self, max: Self) -> Self
where Self: Neg<Output = Self> + Copy,

Clamp the absolute value. Same as self.clamp_range(-max..=max)
§

fn clamp_max(self, max: Self) -> Self

Clamp by maximum value Read more
§

fn clamp_min(self, min: Self) -> Self

Clamp by minimum value Read more
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. Read more
§

impl<T> Diff for T
where T: Debug + Serialize + DeserializeOwned + Sync + Send + Copy + PartialEq + 'static + Unpin,

§

type Delta = T

Object representing the difference between two states of Self
§

fn diff(&self, to: &T) -> T

Calculate the difference between two states
§

fn update(&mut self, new_value: &T)

Update the state using the delta Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

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

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.

§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

source§

impl<T> Message for T
where T: Debug + Serialize + for<'de> Deserialize<'de> + Send + 'static + Unpin,