### from_value() Example Source: https://docs.rs/cgmath/0.18.0/cgmath/prelude/trait.Array.html Example demonstrating the usage of the `from_value()` method to construct a vector from a single value. ```APIDOC ## fn from_value(value: Self::Element) -> Self Construct a vector from a single value, replicating it. ```rust use cgmath::prelude::*; use cgmath::Vector3; assert_eq!(Vector3::from_value(1), Vector3::new(1, 1, 1)); ``` ``` -------------------------------- ### Relative Equality Comparison Examples Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Relative.html Demonstrates how to use the Relative struct's default settings and how to customize epsilon and max_relative for equality checks. These examples use the `eq` method. ```rust use std::f64; use approx::Relative; Relative::default().eq(&1.0, &1.0); Relative::default().epsilon(f64::EPSILON).eq(&1.0, &1.0); Relative::default().max_relative(1.0).eq(&1.0, &1.0); Relative::default().epsilon(f64::EPSILON).max_relative(1.0).eq(&1.0, &1.0); Relative::default().max_relative(1.0).epsilon(f64::EPSILON).eq(&1.0, &1.0); ``` -------------------------------- ### len() Example Source: https://docs.rs/cgmath/0.18.0/cgmath/prelude/trait.Array.html Example demonstrating the usage of the `len()` method to get the number of elements in a vector. ```APIDOC ## fn len() -> usize Get the number of elements in the array type ```rust use cgmath::prelude::*; use cgmath::Vector3; assert_eq!(Vector3::::len(), 3); ``` ``` -------------------------------- ### Basis2 Example Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Basis2.html Demonstrates how to use Basis2 for rotating a vector in a 2D plane. ```APIDOC ### Example ```rust use cgmath::Rad; use cgmath::Vector2; use cgmath::{Matrix, Matrix2}; use cgmath::{Rotation, Rotation2, Basis2}; use cgmath::UlpsEq; use std::f64; // For simplicity, we will rotate the unit x vector to the unit y vector -- // so the angle is 90 degrees, or π/2. let unit_x: Vector2 = Vector2::unit_x(); let rot: Basis2 = Rotation2::from_angle(Rad(0.5f64 * f64::consts::PI)); // Rotate the vector using the two-dimensional rotation matrix: let unit_y = rot.rotate_vector(unit_x); // Since sin(π/2) may not be exactly zero due to rounding errors, we can // use approx's assert_ulps_eq!() feature to show that it is close enough. // assert_ulps_eq!(&unit_y, &Vector2::unit_y()); // TODO: Figure out how to use this // This is exactly equivalent to using the raw matrix itself: let unit_y2: Matrix2<_> = rot.into(); let unit_y2 = unit_y2 * unit_x; assert_eq!(unit_y2, unit_y); // Note that we can also concatenate rotations: let rot_half: Basis2 = Rotation2::from_angle(Rad(0.25f64 * f64::consts::PI)); let unit_y3 = (rot_half * rot_half).rotate_vector(unit_x); // assert_ulps_eq!(&unit_y3, &unit_y2); // TODO: Figure out how to use this ``` ``` -------------------------------- ### Vector Addition Example Source: https://docs.rs/cgmath/0.18.0/cgmath/prelude/trait.VectorSpace.html Demonstrates vector addition, subtraction, and negation using the Add, Sub, and Neg traits. ```APIDOC ## Vector Addition Vectors can be added, subtracted, or negated via the following traits: * `Add` * `Sub` * `Neg` ```rust use cgmath::Vector3; let velocity0 = Vector3::new(1, 2, 0); let velocity1 = Vector3::new(1, 1, 0); let total_velocity = velocity0 + velocity1; let velocity_diff = velocity1 - velocity0; let reversed_velocity0 = -velocity0; ``` Vector spaces are also required to implement the additive identity trait, `Zero`. Adding this to another vector should have no effect: ```rust use cgmath::prelude::* use cgmath::Vector2; let v = Vector2::new(1, 2); assert_eq!(v + Vector2::zero(), v); ``` ``` -------------------------------- ### Ulps comparison examples Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Ulps.html Demonstrates how to use the Ulps struct with default and customized epsilon and max_ulps values for equality checks. Requires importing Ulps and f64::EPSILON. ```rust use std::f64; use approx::Ulps; Ulps::default().eq(&1.0, &1.0); Ulps::default().epsilon(f64::EPSILON).eq(&1.0, &1.0); Ulps::default().max_ulps(4).eq(&1.0, &1.0); Ulps::default().epsilon(f64::EPSILON).max_ulps(4).eq(&1.0, &1.0); Ulps::default().max_ulps(4).epsilon(f64::EPSILON).eq(&1.0, &1.0); ``` -------------------------------- ### AbsDiff Example Usage Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.AbsDiff.html Demonstrates how to use the AbsDiff struct for approximate equality checks. ```APIDOC ## §Example ``` use std::f64; use approx::AbsDiff; AbsDiff::default().eq(&1.0, &1.0); AbsDiff::default().epsilon(f64::EPSILON).eq(&1.0, &1.0); ``` ``` -------------------------------- ### Scalar Multiplication Example Source: https://docs.rs/cgmath/0.18.0/cgmath/prelude/trait.VectorSpace.html Illustrates scalar multiplication and division of vectors using the Mul and Div traits. ```APIDOC ## Scalar Multiplication Vectors can be multiplied or divided by their associated scalars via the following traits: * `Mul` * `Div` * `Rem` ```rust use cgmath::Vector2; let translation = Vector2::new(3.0, 4.0); let scale_factor = 2.0; let upscaled_translation = translation * scale_factor; let downscaled_translation = translation / scale_factor; ``` ``` -------------------------------- ### Point3 as_ref() to Array and Tuple Source: https://docs.rs/cgmath/0.18.0/src/cgmath/point.rs.html Demonstrates using as_ref() to get references to an array and a tuple from a Point3. ```rust let p = POINT3; { let p: &[i32; 3] = p.as_ref(); assert_eq!(p, &[1, 2, 3]); } { let p: &(i32, i32, i32) = p.as_ref(); assert_eq!(p, &(1, 2, 3)); } ``` -------------------------------- ### Point3 Slicing and Length Source: https://docs.rs/cgmath/0.18.0/src/cgmath/point.rs.html Demonstrates how to access slices of a Point3 and get their lengths. ```rust assert_eq!(&POINT3[2..], &[3]); assert_eq!(&POINT3[1..], &[2, 3]); assert_eq!(POINT3[2..].len(), 1); assert_eq!(POINT3[1..].len(), 2); assert_eq!(&POINT3[..], &[1, 2, 3]); assert_eq!(POINT3[..].len(), 3); ``` -------------------------------- ### EuclideanSpace for Point3 Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Point3.html Provides methods for Euclidean space operations on Point3, such as getting the origin, converting to/from vectors, and calculating midpoints. ```APIDOC ## EuclideanSpace for Point3 ### Description Provides methods for Euclidean space operations on Point3, such as getting the origin, converting to/from vectors, and calculating midpoints. ### Associated Types - **Scalar**: The associated scalar over which the space is defined. - **Diff**: The associated space of displacement vectors. ### Methods - **origin() -> Point3** The point at the origin of the Euclidean space. - **from_vec(v: Vector3) -> Point3** Convert a displacement vector to a point. - **to_vec(self) -> Vector3** Convert a point to a displacement vector. - **dot(self, v: Vector3) -> S** This is a weird one, but its useful for plane calculations. - **midpoint(self, other: Self) -> Self** Returns the middle point between two other points. - **centroid(points: &[Self]) -> Self** Returns the average position of all points in the slice. ``` -------------------------------- ### Scalar Multiplication Example Source: https://docs.rs/cgmath/0.18.0/cgmath/trait.VectorSpace.html Illustrates scalar multiplication and division of vectors using the Mul, Div, and Rem traits. ```APIDOC ## Scalar multiplication Vectors can be multiplied or divided by their associated scalars via the following traits: * `Mul` * `Div` * `Rem` ```rust use cgmath::Vector2; let translation = Vector2::new(3.0, 4.0); let scale_factor = 2.0; let upscaled_translation = translation * scale_factor; let downscaled_translation = translation / scale_factor; ``` ``` -------------------------------- ### AbsDiff Usage Example Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.AbsDiff.html Demonstrates basic usage of the AbsDiff struct for equality checks. The `default()` method creates an AbsDiff with a default epsilon, while `epsilon()` allows specifying a custom tolerance. ```rust use std::f64; use approx::AbsDiff; AbsDiff::default().eq(&1.0, &1.0); AbsDiff::default().epsilon(f64::EPSILON).eq(&1.0, &1.0); ``` -------------------------------- ### Test Quaternion Slerp Start Source: https://docs.rs/cgmath/0.18.0/src/cgmath/quaternion.rs.html Tests the slerp function with an interpolation factor of 0.0. The result should be the starting quaternion. ```rust #[test] fn test_slerp_start() { let q = Quaternion::from([0.5f64.sqrt(), 0.0, 0.5f64.sqrt(), 0.0]); let r = Quaternion::from([0.5, 0.5, 0.5, 0.5]); assert_ulps_eq!(q, q.slerp(r, 0.0)); } ``` -------------------------------- ### from Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Vector2.html Creates a new instance from a given value. ```APIDOC ## from ### Description Returns the argument unchanged. ### Signature `fn from(t: T) -> T` ``` -------------------------------- ### Test Quaternion Nlerp Start Source: https://docs.rs/cgmath/0.18.0/src/cgmath/quaternion.rs.html Tests the nlerp function with an interpolation factor of 0.0. The result should be the starting quaternion. ```rust #[test] fn test_nlerp_start() { let q = Quaternion::from([0.5f64.sqrt(), 0.0, 0.5f64.sqrt(), 0.0]); let r = Quaternion::from([0.5, 0.5, 0.5, 0.5]); assert_ulps_eq!(q, q.nlerp(r, 0.0)); } ``` -------------------------------- ### Get Array Length Source: https://docs.rs/cgmath/0.18.0/cgmath/trait.Array.html Demonstrates how to get the number of elements in an array type using the `len` method. This is a required method for the `Array` trait. ```rust use cgmath::prelude::* use cgmath::Vector3; assert_eq!(Vector3::::len(), 3); ``` -------------------------------- ### Get Array Length Source: https://docs.rs/cgmath/0.18.0/cgmath/prelude/trait.Array.html Demonstrates how to get the number of elements in an array type using the `len` method. Requires importing `cgmath::prelude::*`. ```rust use cgmath::prelude::*; use cgmath::Vector3; assert_eq!(Vector3::::len(), 3); ``` -------------------------------- ### Construct Array from Value Source: https://docs.rs/cgmath/0.18.0/cgmath/prelude/trait.Array.html Shows how to create an array where all elements are initialized to a single provided value using `from_value`. Requires importing `cgmath::prelude::*`. ```rust use cgmath::prelude::*; use cgmath::Vector3; assert_eq!(Vector3::from_value(1), Vector3::new(1, 1, 1)); ``` -------------------------------- ### Bounded Trait Definition Source: https://docs.rs/cgmath/0.18.0/cgmath/prelude/trait.Bounded.html The Bounded trait requires two methods: `min_value()` to get the smallest value and `max_value()` to get the largest value a type can represent. ```APIDOC ## Trait Bounded Numbers which have upper and lower bounds. ### Required Methods #### fn min_value() -> Self Returns the smallest finite number this type can represent. #### fn max_value() -> Self Returns the largest finite number this type can represent. ``` -------------------------------- ### Import cgmath Prelude Source: https://docs.rs/cgmath/0.18.0/cgmath/index.html Import the main traits from the cgmath prelude to avoid importing each trait individually. This allows for convenient access to common linear algebra operations. ```rust use cgmath::prelude::*; ``` -------------------------------- ### point1 Source: https://docs.rs/cgmath/0.18.0/cgmath/fn.point1.html The short constructor for Point1. ```APIDOC ## point1 ### Description The short constructor. ### Signature ```rust pub const fn point1(x: S) -> Point1 ``` ### Parameters * `x`: The value for the single component of the Point1. ``` -------------------------------- ### type_id Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Matrix3.html Gets the TypeId of the matrix. ```APIDOC #### fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. Read more Source ``` -------------------------------- ### CloneToUninit Implementation (Nightly) Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.PerspectiveFov.html Nightly-only experimental API for performing copy-assignment from self to an uninitialized destination. Use with caution. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### Any::type_id Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Matrix2.html Gets the `TypeId` of `self`. ```APIDOC ## fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. Read more ``` -------------------------------- ### Conversions to Vector2 Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Vector2.html Demonstrates how to convert various types into a Vector2. ```APIDOC ## From<&'a (S, S)> for &'a Vector2 ### Description Converts to this type from the input type. ### Method `from` ### Parameters - `v`: &'a (S, S) - The input tuple reference. ### Returns - &'a Vector2 - A reference to the created Vector2. ``` ```APIDOC ## From<&'a mut [S; 2]> for &'a mut Vector2 ### Description Converts to this type from the input type. ### Method `from` ### Parameters - `v`: &'a mut [S; 2] - The mutable input array reference. ### Returns - &'a mut Vector2 - A mutable reference to the created Vector2. ``` ```APIDOC ## From<&'a mut (S, S)> for &'a mut Vector2 ### Description Converts to this type from the input type. ### Method `from` ### Parameters - `v`: &'a mut (S, S) - The mutable input tuple reference. ### Returns - &'a mut Vector2 - A mutable reference to the created Vector2. ``` ```APIDOC ## From<[S; 2]> for Vector2 ### Description Converts to this type from the input type. ### Method `from` ### Parameters - `v`: [S; 2] - The input array. ### Returns - Vector2 - The created Vector2. ``` ```APIDOC ## From<(S, S)> for Vector2 ### Description Converts to this type from the input type. ### Method `from` ### Parameters - `v`: (S, S) - The input tuple. ### Returns - Vector2 - The created Vector2. ``` -------------------------------- ### type_id Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Point1.html Gets the TypeId of the Point1 instance. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Signature ```rust fn type_id(&self) -> TypeId ``` ``` -------------------------------- ### Any: type_id Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Point3.html Provides a method to get the TypeId of a type. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Method `type_id` ### Returns - TypeId - The TypeId of the object. ``` -------------------------------- ### Vector Constructors and Methods Source: https://docs.rs/cgmath/0.18.0/src/cgmath/vector.rs.html Provides details on the `new` and `map` methods for constructing and transforming vectors, as well as the `zip` method for element-wise operations between vectors. ```APIDOC ## Vector Methods ### `new` Construct a new vector, using the provided values. #### Signature ```rust pub const fn new(field1: S, field2: S, ...) -> VectorN ``` ### `map` Perform the given operation on each field in the vector, returning a new point constructed from the operations. #### Signature ```rust pub fn map(self, mut f: F) -> VectorN where F: FnMut(S) -> U ``` ### `zip` Construct a new vector where each component is the result of applying the given operation to each pair of components of the given vectors. #### Signature ```rust pub fn zip(self, v2: VectorN, mut f: F) -> VectorN where F: FnMut(S, S2) -> S3 ``` ``` -------------------------------- ### Mint Crate Conversions (Into/From) Source: https://docs.rs/cgmath/0.18.0/src/cgmath/matrix.rs.html Implementations for converting cgmath matrices to and from mint crate types. Requires the 'mint' feature to be enabled. ```Rust impl Into> for $MatrixN { #[inline] fn into(self) -> mint::$MintN { mint::$MintN { $($field: self.$field.into()),+ } } } impl From> for $MatrixN { #[inline] fn from(m: mint::$MintN) -> Self { $MatrixN { $($field: m.$field.into()),+ } } } ``` -------------------------------- ### as_ptr Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Vector2.html Gets a raw pointer to the first element of the vector. ```APIDOC ## fn as_ptr(&self) -> *const Self::Element ### Description Get the pointer to the first element of the array. ### Returns - *const Self::Element: A constant pointer to the first element. ``` -------------------------------- ### Converting between Points and Vectors Source: https://docs.rs/cgmath/0.18.0/src/cgmath/structure.rs.html Explains how to convert between points and displacement vectors using `EuclideanSpace::{from_vec, to_vec}`. ```APIDOC ## Converting between points and vectors Points can be converted to and from displacement vectors using the `EuclideanSpace::{from_vec, to_vec}` methods. These are inlined type conversions with no performance implications. ``` -------------------------------- ### into Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Vector2.html Converts the current instance into another type. ```APIDOC ## into ### Description Calls `U::from(self)`. That is, this conversion is whatever the implementation of `From for U` chooses to do. ### Signature `fn into(self) -> U` ``` -------------------------------- ### UpperBounded Trait Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Rad.html Provides functionality to get the maximum value representable by a type. ```APIDOC ### impl UpperBounded for T where T: Bounded, #### fn max_value() -> T Returns the largest finite number this type can represent ``` -------------------------------- ### Any::type_id Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Euler.html Gets the `TypeId` of `self`. This is a fundamental method for runtime type identification. ```APIDOC ## fn type_id(&self) -> TypeId ### Description Gets the `TypeId` of `self`. ### Returns A `TypeId` representing the type of `self`. ``` -------------------------------- ### Matrix2 Constructors Source: https://docs.rs/cgmath/0.18.0/src/cgmath/matrix.rs.html Provides methods for creating Matrix2 instances. ```APIDOC ## Matrix2::new ### Description Creates a new Matrix2 by specifying each element. ### Signature `pub const fn new(c0r0: S, c0r1: S, c1r0: S, c1r1: S) -> Matrix2` ## Matrix2::from_cols ### Description Creates a new Matrix2 from two column vectors. ### Signature `pub const fn from_cols(c0: Vector2, c1: Vector2) -> Matrix2` ``` -------------------------------- ### Product Calculation (`Product`) Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Matrix3.html Enables calculating the product of multiple Matrix3 instances. ```APIDOC ## Product Calculation (`Product`) Calculates the product of elements in an iterator. ### `product>>(iter: I) -> Matrix3` Takes an iterator of matrix references and returns their product. ### `product>>(iter: I) -> Matrix3` Takes an iterator of matrices and returns their product. ``` -------------------------------- ### Bounded Properties Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Vector4.html Provides methods to get the minimum and maximum representable values for Vector4. ```APIDOC ## fn min_value() -> Vector4 ### Description Returns the smallest finite number this type can represent. ### Method `min_value` ``` ```APIDOC ## fn max_value() -> Vector4 ### Description Returns the largest finite number this type can represent. ### Method `max_value` ``` -------------------------------- ### Conversions from Vector2 Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Vector2.html Demonstrates how to convert a Vector2 into other types. ```APIDOC ## Into<[S; 2]> for Vector2 ### Description Converts this type into an array of two elements. ### Method `into` ### Returns - `[S; 2]` - The array representation of the vector. ``` ```APIDOC ## Into<(S, S)> for Vector2 ### Description Converts this type into a tuple of two elements. ### Method `into` ### Returns - `(S, S)` - The tuple representation of the vector. ``` -------------------------------- ### UpperBounded for T Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Vector1.html Implementation of the UpperBounded trait, providing a method to get the maximum value a type can represent. ```APIDOC ## impl UpperBounded for T where T: Bounded ### Methods #### fn max_value() -> T ``` -------------------------------- ### Matrix3 Constructors Source: https://docs.rs/cgmath/0.18.0/src/cgmath/matrix.rs.html Provides methods for creating Matrix3 instances. ```APIDOC ## Matrix3::new ### Description Creates a new Matrix3 by specifying each element. ### Signature `pub const fn new(c0r0: S, c0r1: S, c0r2: S, c1r0: S, c1r1: S, c1r2: S, c2r0: S, c2r1: S, c2r2: S) -> Matrix3` ## Matrix3::from_cols ### Description Creates a new Matrix3 from three column vectors. ### Signature `pub const fn from_cols(c0: Vector3, c1: Vector3, c2: Vector3) -> Matrix3` ``` -------------------------------- ### From Conversions for Point1 Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Point1.html Shows how to convert various types into Point1. ```APIDOC ## From Conversions for Point1 This section outlines the `From` trait implementations for creating `Point1` instances. ### `impl<'a, S> From<&'a [S; 1]> for &'a Point1` - **Function**: `from(v: &'a [S; 1]) -> &'a Point1` - **Description**: Converts a reference to a 1-element array into a reference to `Point1`. ### `impl<'a, S> From<&'a (S,)> for &'a Point1` - **Function**: `from(v: &'a (S,)) -> &'a Point1` - **Description**: Converts a reference to a tuple of one element into a reference to `Point1`. ### `impl<'a, S> From<&'a mut [S; 1]> for &'a mut Point1` - **Function**: `from(v: &'a mut [S; 1]) -> &'a mut Point1` - **Description**: Converts a mutable reference to a 1-element array into a mutable reference to `Point1`. ### `impl<'a, S> From<&'a mut (S,)> for &'a mut Point1` - **Function**: `from(v: &'a mut (S,)) -> &'a mut Point1` - **Description**: Converts a mutable reference to a tuple of one element into a mutable reference to `Point1`. ### `impl From<[S; 1]> for Point1` - **Function**: `from(v: [S; 1]) -> Point1` - **Description**: Converts a 1-element array into `Point1`. ### `impl From<(S,)> for Point1` - **Function**: `from(v: (S,)) -> Point1` - **Description**: Converts a tuple of one element into `Point1`. ``` -------------------------------- ### Conversions from Slices and Tuples Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Vector3.html Demonstrates various ways to create a Vector3 from slices and tuples, including mutable and immutable references. ```APIDOC ## From<&'a [S; 3]> for &'a Vector3 Converts to this type from the input type. ### fn from(v: &'a [S; 3]) -> &'a Vector3 ## From<&'a (S, S, S)> for &'a Vector3 Converts to this type from the input type. ### fn from(v: &'a (S, S, S)) -> &'a Vector3 ## From<&'a mut [S; 3]> for &'a mut Vector3 Converts to this type from the input type. ### fn from(v: &'a mut [S; 3]) -> &'a mut Vector3 ## From<&'a mut (S, S, S)> for &'a mut Vector3 Converts to this type from the input type. ### fn from(v: &'a mut (S, S, S)) -> &'a mut Vector3 ## From<[S; 3]> for Vector3 Converts to this type from the input type. ### fn from(v: [S; 3]) -> Vector3 ## From<(S, S, S)> for Vector3 Converts to this type from the input type. ### fn from(v: (S, S, S)) -> Vector3 ``` -------------------------------- ### CloneToUninit: clone_to_uninit Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Point3.html Provides an experimental method for cloning data to uninitialized memory. ```APIDOC ## unsafe fn clone_to_uninit(&self, dest: *mut u8) ### Description Performs copy-assignment from `self` to `dest`. This is a nightly-only experimental API. ### Method `clone_to_uninit` ### Parameters - **dest** (*mut u8) - A mutable pointer to the destination memory. ``` -------------------------------- ### AsRef<[[S; 3]; 3]> for Matrix3 Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Matrix3.html Provides a way to get a reference to a 3x3 array representation of the Matrix3. ```APIDOC ## fn as_ref(&self) -> &[[S; 3]; 3] Converts this type into a shared reference of the (usually inferred) input type. ``` -------------------------------- ### Compute tangent of an angle Source: https://docs.rs/cgmath/0.18.0/src/cgmath/structure.rs.html Computes the tangent of the angle, returning a unitless ratio. Example usage with Rad type. ```rust /// ```rust /// use cgmath::prelude::*; /// use cgmath::Rad; /// /// let angle = Rad(35.0); /// let ratio: f32 = Rad::tan(angle); /// ``` fn tan(self) -> Self::Unitless; ``` -------------------------------- ### Short Constructor Source: https://docs.rs/cgmath/0.18.0/src/cgmath/vector.rs.html A concise constructor function for creating vectors. ```APIDOC ## Short Constructor ### `constructor_name` The short constructor. #### Signature ```rust pub const fn constructor_name(field1: S, field2: S, ...) -> VectorN ``` ``` -------------------------------- ### PartialEq Implementation for Perspective Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Perspective.html Enables comparison of two Perspective projections for equality. Use this to check if two projection configurations are identical. ```rust impl PartialEq for Perspective fn eq(&self, other: &Perspective) -> bool ``` -------------------------------- ### Compute cosine of an angle Source: https://docs.rs/cgmath/0.18.0/src/cgmath/structure.rs.html Computes the cosine of the angle, returning a unitless ratio. Example usage with Rad type. ```rust /// ```rust /// use cgmath::prelude::*; /// use cgmath::Rad; /// /// let angle = Rad(35.0); /// let ratio: f32 = Rad::cos(angle); /// ``` fn cos(self) -> Self::Unitless; ``` -------------------------------- ### Compute sine of an angle Source: https://docs.rs/cgmath/0.18.0/src/cgmath/structure.rs.html Computes the sine of the angle, returning a unitless ratio. Example usage with Rad type. ```rust /// ```rust /// use cgmath::prelude::*; /// use cgmath::Rad; /// /// let angle = Rad(35.0); /// let ratio: f32 = Rad::sin(angle); /// ``` fn sin(self) -> Self::Unitless; ``` -------------------------------- ### Into> for Quaternion Source: https://docs.rs/cgmath/0.18.0/src/cgmath/quaternion.rs.html Converts a cgmath::Quaternion into a mint::Quaternion. ```APIDOC ## Into> for Quaternion ### Description Converts a `cgmath::Quaternion` into a `mint::Quaternion`. This requires the `mint` feature to be enabled and the scalar type `S` to implement `Clone`. ### Method `into(self) -> mint::Quaternion` ### Parameters None ### Returns A `mint::Quaternion` instance. ``` -------------------------------- ### CloneToUninit Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Point1.html Performs copy-assignment from self to a destination pointer. This is an experimental, nightly-only API. ```APIDOC ## unsafe fn clone_to_uninit(&self, dest: *mut u8) ### Description Performs copy-assignment from `self` to `dest`. ### Signature ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` ``` -------------------------------- ### CloneToUninit::clone_to_uninit Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Matrix2.html Performs copy-assignment from `self` to `dest`. This is a nightly-only experimental API. ```APIDOC ## unsafe fn clone_to_uninit(&self, dest: *mut u8) 🔬This is a nightly-only experimental API. (`clone_to_uninit`) Performs copy-assignment from `self` to `dest`. Read more ``` -------------------------------- ### Vector4 Range Indexing Source: https://docs.rs/cgmath/0.18.0/src/cgmath/vector.rs.html Demonstrates slicing Vector4 using range indices for both start and end, and full range. ```rust #[test] fn test_index_range() { assert_eq!(&VECTOR4[..2], &[1, 2]); assert_eq!(&VECTOR4[..3], &[1, 2, 3]); assert_eq!(VECTOR4[..2].len(), 2); assert_eq!(VECTOR4[..3].len(), 3); assert_eq!(&VECTOR4[2..], &[3, 4]); assert_eq!(&VECTOR4[1..], &[2, 3, 4]); assert_eq!(VECTOR4[2..].len(), 2); assert_eq!(VECTOR4[1..].len(), 3); assert_eq!(&VECTOR4[..], &[1, 2, 3, 4]); assert_eq!(VECTOR4[..].len(), 4); } ``` -------------------------------- ### Mint Crate Conversion Macro Calls Source: https://docs.rs/cgmath/0.18.0/src/cgmath/matrix.rs.html Macro calls to generate mint conversions for Matrix2, Matrix3, and Matrix4. ```Rust #[cfg(feature = "mint")] mint_conversions!(Matrix2 { x, y }, ColumnMatrix2); #[cfg(feature = "mint")] mint_conversions!(Matrix3 { x, y, z }, ColumnMatrix3); #[cfg(feature = "mint")] mint_conversions!(Matrix4 { x, y, z, w }, ColumnMatrix4); ``` -------------------------------- ### Point3 as_mut() to Array and Tuple Source: https://docs.rs/cgmath/0.18.0/src/cgmath/point.rs.html Illustrates using as_mut() to get mutable references to an array and a tuple from a Point3. ```rust let mut p = POINT3; { let p: &mut [i32; 3] = p.as_mut(); assert_eq!(p, &mut [1, 2, 3]); } { let p: &mut (i32, i32, i32) = p.as_mut(); assert_eq!(p, &mut (1, 2, 3)); } ``` -------------------------------- ### Mint Conversions for Point2 Source: https://docs.rs/cgmath/0.18.0/src/cgmath/point.rs.html Implements conversions between cgmath's Point2 and mint's Point2, useful for interoperability with other libraries. ```rust #[cfg(feature = "mint")] impl_mint_conversions!(Point2 { x, y }, Point2); ``` -------------------------------- ### Bounded for PointN Source: https://docs.rs/cgmath/0.18.0/src/cgmath/point.rs.html Implements the Bounded trait for PointN, providing methods to get the minimum and maximum possible values. ```rust impl Bounded for $PointN { #[inline] fn min_value() -> $PointN { $PointN { $($field: S::min_value()),+ } } #[inline] fn max_value() -> $PointN { $PointN { $($field: S::max_value()),+ } } } ``` -------------------------------- ### Conversions to Vector1 Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Vector1.html Demonstrates how to convert other types into a Vector1. ```APIDOC ## From<&'a mut (S,)> for &'a mut Vector1 ### Description Converts to this type from the input type. ### Method `from` ### Parameters - `v`: &'a mut (S,) - The mutable tuple to convert from. ### Returns - &'a mut Vector1 - A mutable reference to the created Vector1. ``` ```APIDOC ## From<[S; 1]> for Vector1 ### Description Converts to this type from the input type. ### Method `from` ### Parameters - `v`: [S; 1] - The array of size 1 to convert from. ### Returns - Vector1 - The created Vector1. ``` ```APIDOC ## From<(S,)> for Vector1 ### Description Converts to this type from the input type. ### Method `from` ### Parameters - `v`: (S,) - The tuple containing a single element to convert from. ### Returns - Vector1 - The created Vector1. ``` -------------------------------- ### AsRef<[S; 9]> for Matrix3 Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Matrix3.html Provides a way to get a reference to a flat array of 9 elements representing the Matrix3. ```APIDOC ## fn as_ref(&self) -> &[S; 9] Converts this type into a shared reference of the (usually inferred) input type. ``` -------------------------------- ### as_mut_ptr() - Get mutable pointer Source: https://docs.rs/cgmath/0.18.0/cgmath/trait.Array.html The `as_mut_ptr()` method returns a raw, mutable pointer to the first element of the array. ```APIDOC ## fn as_mut_ptr(&mut self) -> *mut Self::Element Get a mutable pointer to the first element of the array. ``` -------------------------------- ### Vector3 Creation from Array and Tuple Source: https://docs.rs/cgmath/0.18.0/src/cgmath/vector.rs.html Demonstrates creating a Vector3 from a slice or tuple, including mutable references. Ensure the input has the correct number of elements. ```rust fn test_from() { assert_eq!(Vector3::from([1, 2, 3]), VECTOR3); { let v = &[1, 2, 3]; let v: &Vector3<_> = From::from(v); assert_eq!(v, &VECTOR3); } { let v = &mut [1, 2, 3]; let v: &mut Vector3<_> = From::from(v); assert_eq!(v, &VECTOR3); } assert_eq!(Vector3::from((1, 2, 3)), VECTOR3); { let v = &(1, 2, 3); let v: &Vector3<_> = From::from(v); assert_eq!(v, &VECTOR3); } { let v = &mut (1, 2, 3); let v: &mut Vector3<_> = From::from(v); assert_eq!(v, &VECTOR3); } } ``` -------------------------------- ### Conversions from Vector1 Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Vector1.html Demonstrates how to convert a Vector1 into other types. ```APIDOC ## Into<[S; 1]> for Vector1 ### Description Converts this type into the (usually inferred) input type. ### Method `into` ### Returns - [S; 1] - The array of size 1 representation of the Vector1. ``` ```APIDOC ## Into<(S,)> for Vector1 ### Description Converts this type into the (usually inferred) input type. ### Method `into` ### Returns - (S,) - The tuple representation of the Vector1. ``` -------------------------------- ### as_ptr() - Get immutable pointer Source: https://docs.rs/cgmath/0.18.0/cgmath/trait.Array.html The `as_ptr()` method returns a raw, immutable pointer to the first element of the array. ```APIDOC ## fn as_ptr(&self) -> *const Self::Element Get the pointer to the first element of the array. ``` -------------------------------- ### len() - Get array length Source: https://docs.rs/cgmath/0.18.0/cgmath/trait.Array.html The `len()` method returns the number of elements in the array type. This is a static method. ```APIDOC ## fn len() -> usize Get the number of elements in the array type. ### Example ```rust use cgmath::prelude::* use cgmath::Vector3; assert_eq!(Vector3::::len(), 3); ``` ``` -------------------------------- ### CloneToUninit for T Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Deg.html Provides the experimental `clone_to_uninit` method for copy-assignment to uninitialized memory. ```APIDOC ## unsafe fn clone_to_uninit(&self, dest: *mut u8) Performs copy-assignment from `self` to `dest`. ``` -------------------------------- ### Vector2 Creation from Array and Tuple Source: https://docs.rs/cgmath/0.18.0/src/cgmath/vector.rs.html Demonstrates creating a Vector2 from a slice or tuple, including mutable references. Ensure the input has the correct number of elements. ```rust fn test_from() { assert_eq!(Vector2::from([1, 2]), VECTOR2); { let v = &[1, 2]; let v: &Vector2<_> = From::from(v); assert_eq!(v, &VECTOR2); } { let v = &mut [1, 2]; let v: &mut Vector2<_> = From::from(v); assert_eq!(v, &VECTOR2); } assert_eq!(Vector2::from((1, 2)), VECTOR2); { let v = &(1, 2); let v: &Vector2<_> = From::from(v); assert_eq!(v, &VECTOR2); } { let v = &mut (1, 2); let v: &mut Vector2<_> = From::from(v); assert_eq!(v, &VECTOR2); } } ``` -------------------------------- ### Bounded Implementation Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Deg.html Implementation of the Bounded trait for Deg, providing methods to get the minimum and maximum representable values. ```APIDOC ### impl Bounded for Deg #### fn min_value() -> Deg Returns the smallest finite number this type can represent #### fn max_value() -> Deg Returns the largest finite number this type can represent ``` -------------------------------- ### Get Inverse Transformation Source: https://docs.rs/cgmath/0.18.0/cgmath/prelude/trait.Transform.html Computes and returns a transformation that reverses the effect of this transformation. Returns None if the transformation is not invertible. ```rust fn inverse_transform(&self) -> Option; ``` -------------------------------- ### Basis2 Product Methods Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Basis2.html Methods for calculating the product of multiple Basis2 instances. ```APIDOC ## fn product>>(iter: I) -> Basis2 Takes an iterator and generates `Self` from the elements by multiplying the items. ### Method `product` ### Parameters - `iter`: An iterator over `Basis2` references. ### Returns `Basis2`: The resulting `Basis2` after multiplying all items in the iterator. ``` ```APIDOC ## fn product>>(iter: I) -> Basis2 Takes an iterator and generates `Self` from the elements by multiplying the items. ### Method `product` ### Parameters - `iter`: An iterator over `Basis2` instances. ### Returns `Basis2`: The resulting `Basis2` after multiplying all items in the iterator. ``` -------------------------------- ### Bounded Trait Implementation Source: https://docs.rs/cgmath/0.18.0/src/cgmath/vector.rs.html Implements the `Bounded` trait for vectors, providing methods to get the minimum and maximum possible values. ```APIDOC ## Bounded Trait Implementation ### `min_value()` Returns a vector with each element set to the minimum value of the scalar type `S`. ### `max_value()` Returns a vector with each element set to the maximum value of the scalar type `S`. ``` -------------------------------- ### From> for Matrix4 Implementation Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Perspective.html Allows conversion from a Perspective projection to a Matrix4. ```APIDOC ### impl From> for Matrix4 #### fn from(persp: Perspective) -> Matrix4 Converts to this type from the input type. ``` -------------------------------- ### Array Trait for Vector2 Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Vector2.html Provides array-like functionality for Vector2, including getting the length, creating from a scalar, and summing elements. ```APIDOC ## Array Trait for Vector2 ### Description Provides array-like functionality for `Vector2`. ### Implementations * `impl Array for Vector2` ### Methods * `fn len() -> usize`: Get the number of elements in the array type. * `fn from_value(scalar: S) -> Vector2`: Construct a vector from a single value, replicating it. * `fn sum(self) -> S`: The sum of the elements of the array. ``` -------------------------------- ### Vector Constructor and Utility Methods Source: https://docs.rs/cgmath/0.18.0/src/cgmath/vector.rs.html Provides a constant constructor `new` for creating vectors, a `map` method for applying a function to each component, and a `zip` method for combining two vectors element-wise using a function. ```rust impl $VectorN { /// Construct a new vector, using the provided values. #[inline] pub const fn new($($field: S),+) -> $VectorN { $VectorN { $($field: $field),+ } } /// Perform the given operation on each field in the vector, returning a new point /// constructed from the operations. #[inline] pub fn map(self, mut f: F) where F: FnMut(S) -> U { $VectorN { $($field: f(self.$field)),+ } } /// Construct a new vector where each component is the result of /// applying the given operation to each pair of components of the /// given vectors. #[inline] pub fn zip(self, v2: $VectorN, mut f: F) where F: FnMut(S, S2) -> S3 { $VectorN { $($field: f(self.$field, v2.$field)),+ } } } ``` -------------------------------- ### Array for Point1 Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.Point1.html Provides array-like functionality for Point1, including getting length, creating from a value, summing, and accessing elements. ```APIDOC ## impl Array for Point1 ```rust type Element = S fn len() -> usize fn from_value(scalar: S) -> Point1 fn sum(self) -> S fn product(self) -> S fn is_finite(&self) -> bool fn as_ptr(&self) -> *const Self::Element fn as_mut_ptr(&mut self) -> *mut Self::Element fn swap_elements(&mut self, i: usize, j: usize) ``` Get the number of elements in the array type Read more Construct a vector from a single value, replicating it. Read more where S: Add, The sum of the elements of the array. where S: Mul, The product of the elements of the array. where S: Float, Whether all elements of the array are finite Get the pointer to the first element of the array. Get a mutable pointer to the first element of the array. Swap the elements at indices `i` and `j` in-place. ``` -------------------------------- ### From> for Quaternion Source: https://docs.rs/cgmath/0.18.0/src/cgmath/quaternion.rs.html Converts a mint::Quaternion into a cgmath::Quaternion. ```APIDOC ## From> for Quaternion ### Description Converts a `mint::Quaternion` into a `cgmath::Quaternion`. This requires the `mint` feature to be enabled. ### Method `from(q: mint::Quaternion)` ### Parameters - **q** (mint::Quaternion) - The mint quaternion to convert. ### Returns A `Quaternion` instance. ``` -------------------------------- ### PartialEq Implementation for PerspectiveFov Source: https://docs.rs/cgmath/0.18.0/cgmath/struct.PerspectiveFov.html Allows comparison of two PerspectiveFov instances for equality. This is used to check if two projection settings are identical. ```rust fn eq(&self, other: &PerspectiveFov) -> bool ``` -------------------------------- ### Compute cosecant of an angle Source: https://docs.rs/cgmath/0.18.0/src/cgmath/structure.rs.html Computes the cosecant of the angle. This is equivalent to calculating the reciprocal of the sine of the angle. Example usage with Rad type. ```rust /// ```rust /// use cgmath::prelude::*; /// use cgmath::Rad; /// ```