Implement Vector3::FromScalar() RandomDir() RandomSphere() RandomBox()
Some checks are pending
Run tests / Explore-Gitea-Actions (push) Waiting to run
Build Docs With Doxygen / Explore-Gitea-Actions (push) Waiting to run

This commit is contained in:
2024-05-31 15:19:45 -04:00
parent e0ba266444
commit 312d039001
2 changed files with 46 additions and 1 deletions

View File

@@ -5,6 +5,10 @@
#include <cstddef>
#include <cstdlib>
#include <J3ML/LinearAlgebra/Angle2D.h>
#include <J3ML/Algorithm/RNG.h>
using namespace J3ML::Algorithm;
namespace J3ML::LinearAlgebra {
@@ -95,7 +99,23 @@ public:
/// Constructs a new Vector3 with the value (scalar, scalar, scalar).
explicit Vector3(float scalar);
/// Generates a new Vector3 by fillings its entries by the given scalar.
/// @see Vector3::Vector3(float scalar), SetFromScalar()
static Vector3 FromScalar(float scalar);
/// Generates a direction vector of the given length.
/** The returned vector points at a uniformly random direction.
@see RandomSphere(), RandomBox() */
static Vector3 RandomDir(RNG& rng, float length = 1.f);
static Vector3 RandomSphere(RNG& rng, const Vector3& center, float radius);
static Vector3 RandomBox(RNG& rng, float xmin, float xmax, float ymin, float ymax, float zmin, float zmax);
static Vector3 RandomBox(RNG& rng, const Vector3& min, const Vector3 &max);
static Vector3 RandomBox(RNG& rng, float min, float max);
static inline Vector3 RandomGeneral(RNG& rng, float minElem, float maxElem) { return RandomBox(rng, minElem, maxElem); }
public:
/// Casts this float3 to a C array.
/** This function does not allocate new memory or make a copy of this Vector3. This function simply
returns a C pointer view to this data structure. Use ptr()[0] to access the x component of this float3,
@@ -172,7 +192,7 @@ public:
float MinElement() const;
static float MinElement(const Vector3& of);
// Normalizes this Vector3.
/// Normalizes this Vector3.
/** In the case of failure, this vector is set to (1, 0, 0), so calling this function will never result in an
unnormalized vector.
@note If this function fails to normalize the vector, no error message is printed, the vector is set to (1,0,0) and