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:
authorCampbell Barton <ideasman42@gmail.com>2013-06-10 01:25:27 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-06-10 01:25:27 +0400
commita91964e0e2f6758e076b522724bb1bc63933cb91 (patch)
tree7cd61d572570250f65e12afbbd1e6867c378f15e
parenteabb30a2367808c163a90d658c5be586530098ec (diff)
code cleanup: use boolean for intersection functions.
-rw-r--r--source/blender/blenkernel/BKE_object.h8
-rw-r--r--source/blender/blenkernel/intern/object.c30
-rw-r--r--source/blender/blenlib/BLI_math_geom.h44
-rw-r--r--source/blender/blenlib/intern/math_geom.c64
-rw-r--r--source/blender/editors/gpencil/gpencil_edit.c2
5 files changed, 76 insertions, 72 deletions
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index db93e4f419e..c9668295173 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -97,7 +97,7 @@ void BKE_object_to_mat3(struct Object *ob, float mat[3][3]);
void BKE_object_to_mat4(struct Object *ob, float mat[4][4]);
void BKE_object_apply_mat4(struct Object *ob, float mat[4][4], const bool use_compat, const bool use_parent);
-int BKE_object_pose_context_check(struct Object *ob);
+bool BKE_object_pose_context_check(struct Object *ob);
struct Object *BKE_object_pose_armature_get(struct Object *ob);
void BKE_object_where_is_calc(struct Scene *scene, struct Object *ob);
@@ -110,15 +110,15 @@ void BKE_object_where_is_calc_mat4(struct Scene *scene, struct Object *ob, float
/* possibly belong in own moduke? */
struct BoundBox *BKE_boundbox_alloc_unit(void);
-void BKE_boundbox_init_from_minmax(struct BoundBox *bb, float min[3], float max[3]);
-int BKE_boundbox_ray_hit_check(struct BoundBox *bb, float ray_start[3], float ray_normal[3]);
+void BKE_boundbox_init_from_minmax(struct BoundBox *bb, const float min[3], const float max[3]);
+bool BKE_boundbox_ray_hit_check(struct BoundBox *bb, const float ray_start[3], const float ray_normal[3]);
struct BoundBox *BKE_object_boundbox_get(struct Object *ob);
void BKE_object_dimensions_get(struct Object *ob, float vec[3]);
void BKE_object_dimensions_set(struct Object *ob, const float *value);
void BKE_object_boundbox_flag(struct Object *ob, int flag, int set);
void BKE_object_minmax(struct Object *ob, float r_min[3], float r_max[3], const bool use_hidden);
-int BKE_object_minmax_dupli(struct Scene *scene, struct Object *ob, float r_min[3], float r_max[3], const bool use_hidden);
+bool BKE_object_minmax_dupli(struct Scene *scene, struct Object *ob, float r_min[3], float r_max[3], const bool use_hidden);
/* sometimes min-max isn't enough, we need to loop over each point */
void BKE_object_foreach_display_point(struct Object *ob, float obmat[4][4],
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 9a08254157e..e556e6f23c3 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -1139,7 +1139,7 @@ static void copy_object_pose(Object *obn, Object *ob)
}
}
-int BKE_object_pose_context_check(Object *ob)
+bool BKE_object_pose_context_check(Object *ob)
{
if ((ob) &&
(ob->type == OB_ARMATURE) &&
@@ -2223,7 +2223,7 @@ void BKE_object_workob_calc_parent(Scene *scene, Object *ob, Object *workob)
BoundBox *BKE_boundbox_alloc_unit(void)
{
BoundBox *bb;
- float min[3] = {-1.0f, -1.0f, -1.0f}, max[3] = {-1.0f, -1.0f, -1.0f};
+ const float min[3] = {-1.0f, -1.0f, -1.0f}, max[3] = {-1.0f, -1.0f, -1.0f};
bb = MEM_callocN(sizeof(BoundBox), "OB-BoundBox");
BKE_boundbox_init_from_minmax(bb, min, max);
@@ -2231,7 +2231,7 @@ BoundBox *BKE_boundbox_alloc_unit(void)
return bb;
}
-void BKE_boundbox_init_from_minmax(BoundBox *bb, float min[3], float max[3])
+void BKE_boundbox_init_from_minmax(BoundBox *bb, const float min[3], const float max[3])
{
bb->vec[0][0] = bb->vec[1][0] = bb->vec[2][0] = bb->vec[3][0] = min[0];
bb->vec[4][0] = bb->vec[5][0] = bb->vec[6][0] = bb->vec[7][0] = max[0];
@@ -2412,9 +2412,9 @@ void BKE_object_minmax(Object *ob, float min_r[3], float max_r[3], const bool us
}
}
-int BKE_object_minmax_dupli(Scene *scene, Object *ob, float r_min[3], float r_max[3], const bool use_hidden)
+bool BKE_object_minmax_dupli(Scene *scene, Object *ob, float r_min[3], float r_max[3], const bool use_hidden)
{
- int ok = FALSE;
+ bool ok = false;
if ((ob->transflag & OB_DUPLI) == 0) {
return ok;
}
@@ -2874,15 +2874,17 @@ int BKE_object_obdata_texspace_get(Object *ob, short **r_texflag, float **r_loc,
* Test a bounding box for ray intersection
* assumes the ray is already local to the boundbox space
*/
-int BKE_boundbox_ray_hit_check(struct BoundBox *bb, float ray_start[3], float ray_normal[3])
-{
- static int triangle_indexes[12][3] = {{0, 1, 2}, {0, 2, 3},
- {3, 2, 6}, {3, 6, 7},
- {1, 2, 6}, {1, 6, 5},
- {5, 6, 7}, {4, 5, 7},
- {0, 3, 7}, {0, 4, 7},
- {0, 1, 5}, {0, 4, 5}};
- int result = 0;
+bool BKE_boundbox_ray_hit_check(struct BoundBox *bb, const float ray_start[3], const float ray_normal[3])
+{
+ const int triangle_indexes[12][3] = {
+ {0, 1, 2}, {0, 2, 3},
+ {3, 2, 6}, {3, 6, 7},
+ {1, 2, 6}, {1, 6, 5},
+ {5, 6, 7}, {4, 5, 7},
+ {0, 3, 7}, {0, 4, 7},
+ {0, 1, 5}, {0, 4, 5}};
+
+ bool result = false;
int i;
for (i = 0; i < 12 && result == 0; i++) {
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index 4ebb1a1a1d9..96652c0e78d 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -111,30 +111,30 @@ int isect_seg_seg_v2(const float v1[2], const float v2[2], const float v3[2], co
int isect_line_line_v3(const float v1[3], const float v2[3],
const float v3[3], const float v4[3],
float i1[3], float i2[3]);
-int isect_line_line_strict_v3(const float v1[3], const float v2[3],
- const float v3[3], const float v4[3],
- float vi[3], float *r_lambda);
+bool isect_line_line_strict_v3(const float v1[3], const float v2[3],
+ const float v3[3], const float v4[3],
+ float vi[3], float *r_lambda);
-int isect_ray_plane_v3(const float p1[3], const float d[3],
- const float v0[3], const float v1[3], const float v2[3],
- float *r_lambda, const int clip);
+bool isect_ray_plane_v3(const float p1[3], const float d[3],
+ const float v0[3], const float v1[3], const float v2[3],
+ float *r_lambda, const int clip);
-int isect_line_plane_v3(float out[3], const float l1[3], const float l2[3],
- const float plane_co[3], const float plane_no[3], const bool no_flip);
+bool isect_line_plane_v3(float out[3], const float l1[3], const float l2[3],
+ const float plane_co[3], const float plane_no[3], const bool no_flip);
void isect_plane_plane_v3(float r_isect_co[3], float r_isect_no[3],
const float plane_a_co[3], const float plane_a_no[3],
const float plane_b_co[3], const float plane_b_no[3]);
/* line/ray triangle */
-int isect_line_tri_v3(const float p1[3], const float p2[3],
+bool isect_line_tri_v3(const float p1[3], const float p2[3],
+ const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float r_uv[2]);
+bool isect_ray_tri_v3(const float p1[3], const float d[3],
const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float r_uv[2]);
-int isect_ray_tri_v3(const float p1[3], const float d[3],
- const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float r_uv[2]);
-int isect_ray_tri_threshold_v3(const float p1[3], const float d[3],
- const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float r_uv[2], const float threshold);
-int isect_ray_tri_epsilon_v3(const float p1[3], const float d[3],
- const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float r_uv[2], const float epsilon);
+bool isect_ray_tri_threshold_v3(const float p1[3], const float d[3],
+ const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float r_uv[2], const float threshold);
+bool isect_ray_tri_epsilon_v3(const float p1[3], const float d[3],
+ const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float r_uv[2], const float epsilon);
/* point in polygon */
bool isect_point_poly_v2(const float pt[2], const float verts[][2], const int nr);
@@ -145,14 +145,14 @@ int isect_point_quad_v2(const float p[2], const float a[2], const float b[2], co
int isect_point_tri_v2(const float pt[2], const float v1[2], const float v2[2], const float v3[2]);
int isect_point_tri_v2_cw(const float pt[2], const float v1[2], const float v2[2], const float v3[2]);
int isect_point_tri_v2_int(const int x1, const int y1, const int x2, const int y2, const int a, const int b);
-int isect_point_tri_prism_v3(const float p[3], const float v1[3], const float v2[3], const float v3[3]);
+bool isect_point_tri_prism_v3(const float p[3], const float v1[3], const float v2[3], const float v3[3]);
void isect_point_quad_uv_v2(const float v0[2], const float v1[2], const float v2[2], const float v3[2],
const float pt[2], float r_uv[2]);
void isect_point_face_uv_v2(const int isquad, const float v0[2], const float v1[2], const float v2[2],
const float v3[2], const float pt[2], float r_uv[2]);
/* axis-aligned bounding box */
-int isect_aabb_aabb_v3(const float min1[3], const float max1[3], const float min2[3], const float max2[3]);
+bool isect_aabb_aabb_v3(const float min1[3], const float max1[3], const float min2[3], const float max2[3]);
typedef struct {
float ray_start[3];
@@ -161,14 +161,14 @@ typedef struct {
} IsectRayAABBData;
void isect_ray_aabb_initialize(IsectRayAABBData *data, const float ray_start[3], const float ray_direction[3]);
-int isect_ray_aabb(const IsectRayAABBData *data, const float bb_min[3], const float bb_max[3], float *tmin);
+bool isect_ray_aabb(const IsectRayAABBData *data, const float bb_min[3], const float bb_max[3], float *tmin);
/* other */
-int isect_sweeping_sphere_tri_v3(const float p1[3], const float p2[3], const float radius,
- const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float ipoint[3]);
+bool isect_sweeping_sphere_tri_v3(const float p1[3], const float p2[3], const float radius,
+ const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float ipoint[3]);
-int isect_axial_line_tri_v3(const int axis, const float co1[3], const float co2[3],
- const float v0[3], const float v1[3], const float v2[3], float *r_lambda);
+bool isect_axial_line_tri_v3(const int axis, const float co1[3], const float co2[3],
+ const float v0[3], const float v1[3], const float v2[3], float *r_lambda);
bool clip_segment_v3_plane(float p1[3], float p2[3], const float plane[4]);
bool clip_segment_v3_plane_n(float p1[3], float p2[3], float plane_array[][4], const int plane_tot);
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 5811bb51012..fff5bc52003 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -888,9 +888,9 @@ int isect_point_quad_v2(const float pt[2], const float v1[2], const float v2[2],
* test if the line starting at p1 ending at p2 intersects the triangle v0..v2
* return non zero if it does
*/
-int isect_line_tri_v3(const float p1[3], const float p2[3],
- const float v0[3], const float v1[3], const float v2[3],
- float *r_lambda, float r_uv[2])
+bool isect_line_tri_v3(const float p1[3], const float p2[3],
+ const float v0[3], const float v1[3], const float v2[3],
+ float *r_lambda, float r_uv[2])
{
float p[3], s[3], d[3], e1[3], e2[3], q[3];
@@ -930,9 +930,9 @@ int isect_line_tri_v3(const float p1[3], const float p2[3],
* test if the ray starting at p1 going in d direction intersects the triangle v0..v2
* return non zero if it does
*/
-int isect_ray_tri_v3(const float p1[3], const float d[3],
- const float v0[3], const float v1[3], const float v2[3],
- float *r_lambda, float r_uv[2])
+bool isect_ray_tri_v3(const float p1[3], const float d[3],
+ const float v0[3], const float v1[3], const float v2[3],
+ float *r_lambda, float r_uv[2])
{
float p[3], s[3], e1[3], e2[3], q[3];
float a, f, u, v;
@@ -972,9 +972,9 @@ int isect_ray_tri_v3(const float p1[3], const float d[3],
* if clip is nonzero, will only return true if lambda is >= 0.0
* (i.e. intersection point is along positive d)
*/
-int isect_ray_plane_v3(const float p1[3], const float d[3],
- const float v0[3], const float v1[3], const float v2[3],
- float *r_lambda, const int clip)
+bool isect_ray_plane_v3(const float p1[3], const float d[3],
+ const float v0[3], const float v1[3], const float v2[3],
+ float *r_lambda, const int clip)
{
float p[3], s[3], e1[3], e2[3], q[3];
float a, f;
@@ -1004,9 +1004,9 @@ int isect_ray_plane_v3(const float p1[3], const float d[3],
return 1;
}
-int isect_ray_tri_epsilon_v3(const float p1[3], const float d[3],
- const float v0[3], const float v1[3], const float v2[3],
- float *r_lambda, float uv[2], const float epsilon)
+bool isect_ray_tri_epsilon_v3(const float p1[3], const float d[3],
+ const float v0[3], const float v1[3], const float v2[3],
+ float *r_lambda, float uv[2], const float epsilon)
{
float p[3], s[3], e1[3], e2[3], q[3];
float a, f, u, v;
@@ -1040,9 +1040,9 @@ int isect_ray_tri_epsilon_v3(const float p1[3], const float d[3],
return 1;
}
-int isect_ray_tri_threshold_v3(const float p1[3], const float d[3],
- const float v0[3], const float v1[3], const float v2[3],
- float *r_lambda, float r_uv[2], const float threshold)
+bool isect_ray_tri_threshold_v3(const float p1[3], const float d[3],
+ const float v0[3], const float v1[3], const float v2[3],
+ float *r_lambda, float r_uv[2], const float threshold)
{
float p[3], s[3], e1[3], e2[3], q[3];
float a, f, u, v;
@@ -1100,9 +1100,9 @@ int isect_ray_tri_threshold_v3(const float p1[3], const float d[3],
* \param plane_no The direction of the plane (does not need to be normalized).
* \param no_flip When true, the intersection point will always be from l1 to l2, even if this is not on the plane.
*/
-int isect_line_plane_v3(float out[3],
- const float l1[3], const float l2[3],
- const float plane_co[3], const float plane_no[3], const bool no_flip)
+bool isect_line_plane_v3(float out[3],
+ const float l1[3], const float l2[3],
+ const float plane_co[3], const float plane_no[3], const bool no_flip)
{
float l_vec[3]; /* l1 -> l2 normalized vector */
float p_no[3]; /* 'plane_no' normalized */
@@ -1174,7 +1174,7 @@ void isect_plane_plane_v3(float r_isect_co[3], float r_isect_no[3],
/* Adapted from the paper by Kasper Fauerby */
/* "Improved Collision detection and Response" */
-static int getLowestRoot(const float a, const float b, const float c, const float maxR, float *root)
+static bool getLowestRoot(const float a, const float b, const float c, const float maxR, float *root)
{
/* Check if a solution exists */
float determinant = b * b - 4.0f * a * c;
@@ -1208,15 +1208,15 @@ static int getLowestRoot(const float a, const float b, const float c, const floa
return 0;
}
-int isect_sweeping_sphere_tri_v3(const float p1[3], const float p2[3], const float radius,
- const float v0[3], const float v1[3], const float v2[3],
- float *r_lambda, float ipoint[3])
+bool isect_sweeping_sphere_tri_v3(const float p1[3], const float p2[3], const float radius,
+ const float v0[3], const float v1[3], const float v2[3],
+ float *r_lambda, float ipoint[3])
{
float e1[3], e2[3], e3[3], point[3], vel[3], /*dist[3],*/ nor[3], temp[3], bv[3];
float a, b, c, d, e, x, y, z, radius2 = radius * radius;
float elen2, edotv, edotbv, nordotv;
float newLambda;
- int found_by_sweep = 0;
+ bool found_by_sweep = false;
sub_v3_v3v3(e1, v1, v0);
sub_v3_v3v3(e2, v2, v0);
@@ -1396,8 +1396,8 @@ int isect_sweeping_sphere_tri_v3(const float p1[3], const float p2[3], const flo
return found_by_sweep;
}
-int isect_axial_line_tri_v3(const int axis, const float p1[3], const float p2[3],
- const float v0[3], const float v1[3], const float v2[3], float *r_lambda)
+bool isect_axial_line_tri_v3(const int axis, const float p1[3], const float p2[3],
+ const float v0[3], const float v1[3], const float v2[3], float *r_lambda)
{
float p[3], e1[3], e2[3];
float u, v, f;
@@ -1513,7 +1513,9 @@ int isect_line_line_v3(const float v1[3], const float v2[3], const float v3[3],
/* Intersection point strictly between the two lines
* 0 when no intersection is found
* */
-int isect_line_line_strict_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3], float vi[3], float *r_lambda)
+bool isect_line_line_strict_v3(const float v1[3], const float v2[3],
+ const float v3[3], const float v4[3],
+ float vi[3], float *r_lambda)
{
float a[3], b[3], c[3], ab[3], cb[3], ca[3], dir1[3], dir2[3];
float d;
@@ -1561,7 +1563,7 @@ int isect_line_line_strict_v3(const float v1[3], const float v2[3], const float
}
}
-int isect_aabb_aabb_v3(const float min1[3], const float max1[3], const float min2[3], const float max2[3])
+bool isect_aabb_aabb_v3(const float min1[3], const float max1[3], const float min2[3], const float max2[3])
{
return (min1[0] < max2[0] && min1[1] < max2[1] && min1[2] < max2[2] &&
min2[0] < max1[0] && min2[1] < max1[1] && min2[2] < max1[2]);
@@ -1581,8 +1583,8 @@ void isect_ray_aabb_initialize(IsectRayAABBData *data, const float ray_start[3],
}
/* Adapted from http://www.gamedev.net/community/forums/topic.asp?topic_id=459973 */
-int isect_ray_aabb(const IsectRayAABBData *data, const float bb_min[3],
- const float bb_max[3], float *tmin_out)
+bool isect_ray_aabb(const IsectRayAABBData *data, const float bb_min[3],
+ const float bb_max[3], float *tmin_out)
{
float bbox[2][3];
float tmin, tmax, tymin, tymax, tzmin, tzmax;
@@ -1913,7 +1915,7 @@ int isect_point_tri_v2_int(const int x1, const int y1, const int x2, const int y
return isect_point_tri_v2(p, v1, v2, v3);
}
-static int point_in_slice(const float p[3], const float v1[3], const float l1[3], const float l2[3])
+static bool point_in_slice(const float p[3], const float v1[3], const float l1[3], const float l2[3])
{
/*
* what is a slice ?
@@ -1962,7 +1964,7 @@ static int point_in_slice_m(float p[3], float origin[3], float normal[3], float
}
#endif
-int isect_point_tri_prism_v3(const float p[3], const float v1[3], const float v2[3], const float v3[3])
+bool isect_point_tri_prism_v3(const float p[3], const float v1[3], const float v2[3], const float v3[3])
{
if (!point_in_slice(p, v1, v2, v3)) return 0;
if (!point_in_slice(p, v2, v3, v1)) return 0;
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 9ee1f59fe21..2d24b34e60b 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -1268,7 +1268,7 @@ static void gp_stroke_norm_curve_weights(Curve *cu, const float minmax_weights[2
int i;
/* when delta == minmax_weights[0] == minmax_weights[1], we get div by zero [#35686] */
- if (IS_EQ(delta, minmax_weights[1]))
+ if (IS_EQF(delta, minmax_weights[1]))
fac = 1.0f;
else
fac = 1.0f / (minmax_weights[1] - delta);