Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2015-01-09 13:54:51 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2015-01-09 15:03:55 +0300
commit2e72d756c4909cd77f9313909159e368a26ccc92 (patch)
tree2b26168b6d2e448ac7b625774e04de43a32bc66b /source/blender/blenlib/intern/rand.c
parent88ee44a9ac3676db44181c5dac9bab442c2a6e1a (diff)
BLI_rand: add a function returning a random point whithin given 2D triangle.
Needed by transfer data.
Diffstat (limited to 'source/blender/blenlib/intern/rand.c')
-rw-r--r--source/blender/blenlib/intern/rand.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/rand.c b/source/blender/blenlib/intern/rand.c
index 59ccf381f29..7657cec8cfd 100644
--- a/source/blender/blenlib/intern/rand.c
+++ b/source/blender/blenlib/intern/rand.c
@@ -144,6 +144,31 @@ void BLI_rng_get_float_unit_v3(RNG *rng, float v[3])
}
}
+/**
+ * Generate a random point inside given tri.
+ */
+void BLI_rng_get_tri_sample_float_v2(
+ RNG *rng, const float v1[2], const float v2[2], const float v3[2],
+ float r_pt[2])
+{
+ float u = BLI_rng_get_float(rng);
+ float v = BLI_rng_get_float(rng);
+
+ float side_u[2], side_v[2];
+
+ if ((u + v) > 1.0f) {
+ u = 1.0f - u;
+ v = 1.0f - v;
+ }
+
+ sub_v2_v2v2(side_u, v2, v1);
+ sub_v2_v2v2(side_v, v3, v1);
+
+ copy_v2_v2(r_pt, v1);
+ madd_v2_v2fl(r_pt, side_u, u);
+ madd_v2_v2fl(r_pt, side_v, v);
+}
+
void BLI_rng_shuffle_array(RNG *rng, void *data, unsigned int elem_size_i, unsigned int elem_tot)
{
const size_t elem_size = (unsigned int)elem_size_i;