[Bf-blender-cvs] [f567d6b] mesh-transfer-data: Cleanup: move tri sample into RNG (some other random/math functions there already)

Campbell Barton noreply at git.blender.org
Mon Nov 17 11:56:38 CET 2014


Commit: f567d6b10f3e7bc58e29f5a671087e8404b1e64f
Author: Campbell Barton
Date:   Mon Nov 17 11:55:07 2014 +0100
Branches: mesh-transfer-data
https://developer.blender.org/rBf567d6b10f3e7bc58e29f5a671087e8404b1e64f

Cleanup: move tri sample into RNG (some other random/math functions there already)

===================================================================

M	source/blender/blenkernel/intern/mesh_mapping.c
M	source/blender/blenlib/BLI_math_geom.h
M	source/blender/blenlib/BLI_rand.h
M	source/blender/blenlib/intern/math_geom.c
M	source/blender/blenlib/intern/rand.c

===================================================================

diff --git a/source/blender/blenkernel/intern/mesh_mapping.c b/source/blender/blenkernel/intern/mesh_mapping.c
index 0fcada1..d3b5f01 100644
--- a/source/blender/blenkernel/intern/mesh_mapping.c
+++ b/source/blender/blenkernel/intern/mesh_mapping.c
@@ -2110,7 +2110,7 @@ void BKE_dm2mesh_mapping_polys_compute(
 						int n = (ray_radius > 0.0f) ? M2MMAP_RAYCAST_APPROXIMATE_NR : 1;
 						float w = 1.0f;
 
-						BLI_tri_v2_sample_random_point(v1, v2, v3, rng, tmp_co);
+						BLI_rng_get_tri_sample_float_v2(rng, v1, v2, v3, tmp_co);
 
 						tmp_co[2] = poly_dst_2d_z;
 						mul_m3_v3(from_pnor_2d_mat, tmp_co);
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index 1495ffa..ba32b29 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -42,8 +42,6 @@ extern "C" {
 #  pragma GCC diagnostic ignored "-Wredundant-decls"
 #endif
 
-struct RNG;
-
 /********************************** Polygons *********************************/
 
 void cent_tri_v3(float r[3], const float a[3], const float b[3], const float c[3]);
@@ -65,8 +63,6 @@ float cotangent_tri_weight_v3(const float v1[3], const float v2[3], const float
 MINLINE float cross_tri_v2(const float v1[2], const float v2[2], const float v3[2]);
 float cross_poly_v2(const float verts[][2], unsigned int nr);
 
-void BLI_tri_v2_sample_random_point(const float v1[2], const float v2[2], const float v3[2], struct RNG *rng, float r_pt[2]);
-
 /********************************* Planes **********************************/
 
 void  plane_from_point_normal_v3(float r_plane[4], const float plane_co[3], const float plane_no[3]);
diff --git a/source/blender/blenlib/BLI_rand.h b/source/blender/blenlib/BLI_rand.h
index 879af44..7b84ddd 100644
--- a/source/blender/blenlib/BLI_rand.h
+++ b/source/blender/blenlib/BLI_rand.h
@@ -55,6 +55,9 @@ double      BLI_rng_get_double(struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NON
 float       BLI_rng_get_float(struct RNG *rng) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
 void        BLI_rng_get_float_unit_v2(struct RNG *rng, float v[2]) ATTR_NONNULL(1, 2);
 void        BLI_rng_get_float_unit_v3(struct RNG *rng, float v[3]) ATTR_NONNULL(1, 2);
+void        BLI_rng_get_tri_sample_float_v2(
+        struct RNG *rng, const float v1[2], const float v2[2], const float v3[2],
+        float r_pt[2]) ATTR_NONNULL();
 void        BLI_rng_shuffle_array(struct RNG *rng, void *data, unsigned int elem_size_i, unsigned int elem_tot) ATTR_NONNULL(1, 2);
 
 /** Note that skipping is as slow as generating n numbers! */
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index c50c3c6..0153134 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -31,7 +31,6 @@
 
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
-#include "BLI_rand.h"
 
 #include "BLI_strict_flags.h"
 
@@ -209,29 +208,6 @@ float cotangent_tri_weight_v3(const float v1[3], const float v2[3], const float
 	}
 }
 
-/**
- * Generate a random point inside given tri.
- */
-void BLI_tri_v2_sample_random_point(const float v1[2], const float v2[2], const float v3[2], RNG *rng, float r_pt[2])
-{
-	float u = BLI_rng_get_float(rng);
-	float v = BLI_rng_get_float(rng);
-
-	float uside[2], vside[2];
-
-	if ((u + v) > 1.0f) {
-		u = 1.0f - u;
-		v = 1.0f - v;
-	}
-
-	sub_v2_v2v2(uside, v2, v1);
-	sub_v2_v2v2(vside, v3, v1);
-
-	copy_v2_v2(r_pt, v1);
-	madd_v2_v2fl(r_pt, uside, u);
-	madd_v2_v2fl(r_pt, vside, v);
-}
-
 /********************************* Planes **********************************/
 
 /**
diff --git a/source/blender/blenlib/intern/rand.c b/source/blender/blenlib/intern/rand.c
index 59ccf38..7657cec 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;




More information about the Bf-blender-cvs mailing list