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
: Thevdc
property is an instance of theVdCorput
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
: Thecirgen
property is an instance of theCircle
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
impl Sphere
Sourcepub fn new(base: &[usize]) -> Self
pub fn new(base: &[usize]) -> Self
Creates a new Sphere
.
The function new
creates a new Sphere
object with a given base.
Arguments:
base
: Thebase
parameter is an array ofusize
values. It is used to initialize theSphere
struct. The first element of thebase
array is used to create a newVdCorput
struct, and the second element is used to create a new `Circle
Returns:
The new
function is returning an instance of the Sphere
struct.
Sourcepub fn pop(&mut self) -> [f64; 3]
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.5);
assert_approx_eq!(result[1], 0.8660254037844387);
assert_approx_eq!(result[2], 0.0);
Sourcepub fn reseed(&mut self, seed: usize)
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.