Struct lds_rs::lds::Sphere

source ·
pub struct Sphere { /* private fields */ }
Expand description

Sphere sequence generator

The Sphere struct is a generator for a sequence of points on a sphere.

Properties:

  • vdc: The vdc property is an instance of the VdCorput struct. It is used to generate a Van der Corput sequence, which is a low-discrepancy sequence used for sampling points in a unit interval.
  • cirgen: The cirgen property is an instance of the Circle struct. It is responsible for generating points on a circle.

Examples

use lds_rs::Sphere;

let mut sgen = Sphere::new(&[2, 3]);
sgen.reseed(1);
let result = sgen.pop();
assert_eq!(result[2], -0.5);

Implementations§

source§

impl Sphere

source

pub fn new(base: &[usize]) -> Self

Creates a new Sphere.

The function new creates a new Sphere object with a given base.

Arguments:

  • base: The base parameter is an array of usize values. It is used to initialize the Sphere struct. The first element of the base array is used to create a new VdCorput struct, and the second element is used to create a new `Circle

Returns:

The new function is returning an instance of the Sphere struct.

source

pub fn pop(&mut self) -> [f64; 3]

Returns the pop of this Sphere.

The pop function returns a random point on a sphere using the VDC and cirgen generators.

Returns:

an array of three f64 values, representing the coordinates of a point on a sphere. The first two values (sinphi * c and sinphi * s) represent the x and y coordinates, while the third value (cosphi) represents the z coordinate.

Examples
use lds_rs::lds::Sphere;
use approx_eq::assert_approx_eq;

let mut sphere = Sphere::new(&[2, 3]);
let result = sphere.pop();
assert_approx_eq!(result[0], 0.8660254037844387);
assert_approx_eq!(result[1], -0.5);
assert_approx_eq!(result[2], 0.0);
source

pub fn reseed(&mut self, seed: usize)

The below code is a Rust function called reseed that is used to reset the state of a sequence generator to a specific seed value. This allows the sequence generator to start generating the sequence from the beginning or from a specific point in the sequence, depending on the value of the seed.

Trait Implementations§

source§

impl Debug for Sphere

source§

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

Formats the value using the given formatter. Read more
source§

impl PartialEq<Sphere> for Sphere

source§

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

impl Eq for Sphere

source§

impl StructuralEq for Sphere

source§

impl StructuralPartialEq for Sphere

Auto Trait Implementations§

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,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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.

source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.