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
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-07-07 02:48:28 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-07-07 02:48:28 +0400
commit3a0593cc3d5de33248b3a7b913a45729c37dc1b4 (patch)
tree88fcddc5e3c060c87a6313d853315f0efa484a52 /source
parent2336aadb80f8602f001b2c5b0bcaacf3ad858f83 (diff)
code cleanup: dont use function calls like dot_v3v3, pow and sqrt within macros which results in calling the function multiple times needlessly.
also added some comments.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/intern/armature.c3
-rw-r--r--source/blender/blenkernel/intern/collision.c2
-rw-r--r--source/blender/blenkernel/intern/displist.c11
-rw-r--r--source/blender/blenkernel/intern/font.c2
-rw-r--r--source/blender/blenkernel/intern/smoke.c4
-rw-r--r--source/blender/blenkernel/intern/softbody.c6
-rw-r--r--source/blender/blenkernel/intern/tracking.c6
-rw-r--r--source/blender/blenlib/intern/freetypefont.c18
-rw-r--r--source/blender/bmesh/operators/bmo_hull.c7
-rw-r--r--source/blender/editors/interface/interface_handlers.c2
-rw-r--r--source/blender/editors/mesh/editmesh_knife.c5
-rw-r--r--source/blender/editors/space_view3d/view3d_draw.c2
-rw-r--r--source/blender/editors/transform/transform.c4
-rw-r--r--source/blender/editors/transform/transform_conversions.c2
-rw-r--r--source/blender/editors/uvedit/uvedit_smart_stitch.c4
-rw-r--r--source/blender/render/intern/source/shadeoutput.c5
-rw-r--r--source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp2
-rw-r--r--source/gameengine/Ketsji/KX_ObstacleSimulation.cpp5
18 files changed, 53 insertions, 37 deletions
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 5822b296a8a..c10b1e2d4f4 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -2049,7 +2049,8 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o
cross_v3_v3v3(raxis, rmat[1], splineVec);
rangle = dot_v3v3(rmat[1], splineVec);
- rangle = acos(MAX2(-1.0f, MIN2(1.0f, rangle)));
+ CLAMP(rangle, -1.0f, 1.0f);
+ rangle = acosf(rangle);
/* multiply the magnitude of the angle by the influence of the constraint to
* control the influence of the SplineIK effect
diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c
index d99c36b6c91..7acbcbf6c93 100644
--- a/source/blender/blenkernel/intern/collision.c
+++ b/source/blender/blenkernel/intern/collision.c
@@ -274,7 +274,7 @@ static int cloth_collision_response_static ( ClothModifierData *clmd, CollisionM
// Decrease in magnitude of relative tangential velocity due to coulomb friction
// in original formula "magrelVel" should be the "change of relative velocity in normal direction"
- magtangent = MIN2(clmd->coll_parms->friction * 0.01f * magrelVel, sqrtf(dot_v3v3(vrel_t_pre, vrel_t_pre)));
+ magtangent = minf(clmd->coll_parms->friction * 0.01f * magrelVel, sqrtf(dot_v3v3(vrel_t_pre, vrel_t_pre)));
// Apply friction impulse.
if ( magtangent > ALMOST_ZERO ) {
diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c
index 2493507dca4..6e5d6ffb0e9 100644
--- a/source/blender/blenkernel/intern/displist.c
+++ b/source/blender/blenkernel/intern/displist.c
@@ -1386,17 +1386,18 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
ListBase top_capbase = {NULL, NULL};
for (dlb = dlbev.first; dlb; dlb = dlb->next) {
- int i, start, steps;
- float bevfac1 = MIN2(cu->bevfac1, cu->bevfac2), bevfac2 = MAX2(cu->bevfac1, cu->bevfac2);
+ const float bevfac1 = minf(cu->bevfac1, cu->bevfac2);
+ const float bevfac2 = maxf(cu->bevfac1, cu->bevfac2);
float firstblend = 0.0f, lastblend = 0.0f;
+ int i, start, steps;
- if (cu->bevfac1 - cu->bevfac2 == 0.0f)
+ if (bevfac2 - bevfac1 == 0.0f)
continue;
start = (int)(bevfac1 * (bl->nr - 1));
steps = 2 + (int)((bevfac2) * (bl->nr - 1)) - start;
- firstblend = 1.0f - ((float)bevfac1 * (bl->nr - 1) - (int)((float)bevfac1 * (bl->nr - 1)));
- lastblend = (float)bevfac2 * (bl->nr - 1) - (int)((float)bevfac2 * (bl->nr - 1));
+ firstblend = 1.0f - (bevfac1 * (bl->nr - 1) - (int)(bevfac1 * (bl->nr - 1)));
+ lastblend = bevfac2 * (bl->nr - 1) - (int)(bevfac2 * (bl->nr - 1));
if (steps > bl->nr) {
steps = bl->nr;
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c
index 061530965ef..5d33c8fbcbf 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -699,7 +699,7 @@ makebreak:
yof -= linedist;
- maxlen = MAX2(maxlen, (xof - tb->x / cu->fsize));
+ maxlen = maxf(maxlen, (xof - tb->x / cu->fsize));
linedata[lnr] = xof - tb->x / cu->fsize;
linedata2[lnr] = cnr;
linedata3[lnr] = tb->w / cu->fsize;
diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c
index 32def1be647..ddcba509301 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -141,7 +141,7 @@ struct SmokeModifierData;
/* forward declerations */
static void calcTriangleDivs(Object *ob, MVert *verts, int numverts, MFace *tris, int numfaces, int numtris, int **tridivs, float cell_len);
-static void get_cell(float *p0, int res[3], float dx, float *pos, int *cell, int correct);
+static void get_cell(const float p0[3], const int res[3], float dx, const float pos[3], int cell[3], int correct);
static void fill_scs_points(Object *ob, DerivedMesh *dm, SmokeCollSettings *scs);
#else /* WITH_SMOKE */
@@ -1977,7 +1977,7 @@ static void bresenham_linie_3D(int x1, int y1, int z1, int x2, int y2, int z2, f
cb(result, input, res, pixel, tRay, correct);
}
-static void get_cell(float *p0, int res[3], float dx, float *pos, int *cell, int correct)
+static void get_cell(const float p0[3], const int res[3], float dx, const float pos[3], int cell[3], int correct)
{
float tmp[3];
diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c
index 63f0a29821f..1d6895a8c71 100644
--- a/source/blender/blenkernel/intern/softbody.c
+++ b/source/blender/blenkernel/intern/softbody.c
@@ -1718,15 +1718,15 @@ static int choose_winner(float*w, float* pos, float*a, float*b, float*c, float*c
{
float mindist, cp;
int winner =1;
- mindist = ABS(dot_v3v3(pos, a));
+ mindist = fabsf(dot_v3v3(pos, a));
- cp = ABS(dot_v3v3(pos, b));
+ cp = fabsf(dot_v3v3(pos, b));
if ( mindist < cp ) {
mindist = cp;
winner =2;
}
- cp = ABS(dot_v3v3(pos, c));
+ cp = fabsf(dot_v3v3(pos, c));
if (mindist < cp ) {
mindist = cp;
winner =3;
diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c
index 6167536fb9b..4342eb20d55 100644
--- a/source/blender/blenkernel/intern/tracking.c
+++ b/source/blender/blenkernel/intern/tracking.c
@@ -2315,10 +2315,10 @@ static int tracking_check_marker_margin(MovieTrackingTrack *track, MovieTracking
/* margin from frame boundaries */
BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
sub_v2_v2v2(dim, pat_max, pat_min);
- margin[0] = margin[1] = MAX2(dim[0], dim[1]) / 2.0f;
+ margin[0] = margin[1] = maxf(dim[0], dim[1]) / 2.0f;
- margin[0] = MAX2(margin[0], (float)track->margin / frame_width);
- margin[1] = MAX2(margin[1], (float)track->margin / frame_height);
+ margin[0] = maxf(margin[0], (float)track->margin / frame_width);
+ margin[1] = maxf(margin[1], (float)track->margin / frame_height);
/* do not track markers which are too close to boundary */
if (marker->pos[0] < margin[0] || marker->pos[0] > 1.0f - margin[0] ||
diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c
index eb2070bce76..10eeda96b5d 100644
--- a/source/blender/blenlib/intern/freetypefont.c
+++ b/source/blender/blenlib/intern/freetypefont.c
@@ -266,17 +266,19 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf
}
}
- // get the handles that are aligned, tricky...
- // dist_to_line_v2, check if the three beztriple points are on one line
- // len_squared_v2v2, see if there's a distance between the three points
- // len_squared_v2v2 again, to check the angle between the handles
- // finally, check if one of them is a vector handle
- if ((dist_to_line_v2(bezt->vec[0], bezt->vec[1], bezt->vec[2]) < 0.001f) &&
+ /* get the handles that are aligned, tricky...
+ * dist_to_line_v2, check if the three beztriple points are on one line
+ * len_squared_v2v2, see if there's a distance between the three points
+ * len_squared_v2v2 again, to check the angle between the handles
+ * finally, check if one of them is a vector handle */
+ if ((bezt->h1 != HD_VECT && bezt->h2 != HD_VECT) &&
+ (dist_to_line_v2(bezt->vec[0], bezt->vec[1], bezt->vec[2]) < 0.001f) &&
(len_squared_v2v2(bezt->vec[0], bezt->vec[1]) > 0.0001f * 0.0001f) &&
(len_squared_v2v2(bezt->vec[1], bezt->vec[2]) > 0.0001f * 0.0001f) &&
(len_squared_v2v2(bezt->vec[0], bezt->vec[2]) > 0.0002f * 0.0001f) &&
- (len_squared_v2v2(bezt->vec[0], bezt->vec[2]) > MAX2(len_squared_v2v2(bezt->vec[0], bezt->vec[1]), len_squared_v2v2(bezt->vec[1], bezt->vec[2]))) &&
- bezt->h1 != HD_VECT && bezt->h2 != HD_VECT)
+ (len_squared_v2v2(bezt->vec[0], bezt->vec[2]) >
+ maxf(len_squared_v2v2(bezt->vec[0], bezt->vec[1]),
+ len_squared_v2v2(bezt->vec[1], bezt->vec[2]))))
{
bezt->h1 = bezt->h2 = HD_ALIGN;
}
diff --git a/source/blender/bmesh/operators/bmo_hull.c b/source/blender/bmesh/operators/bmo_hull.c
index d4f63ab7557..b22bdf60210 100644
--- a/source/blender/bmesh/operators/bmo_hull.c
+++ b/source/blender/bmesh/operators/bmo_hull.c
@@ -31,6 +31,13 @@
#include "BLI_math.h"
#include "BLI_utildefines.h"
+/*XXX: This operator doesn't work well (at all?) for flat surfaces with
+ * >3 sides - creating overlapping faces at times.
+ * An easy workaround is to add in some noise but this is
+ * weak and unreliable, ideally this would detect flat surfaces
+ * (possibly making them into ngons) - see
+ */
+
/* XXX: using 128 for totelem and pchunk of mempool, no idea what good
* values would be though */
#include "BLI_mempool.h"
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 30c5f2fbe40..3a64ad22062 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -3833,7 +3833,7 @@ static int ui_numedit_but_HISTOGRAM(uiBut *but, uiHandleButtonData *data, int mx
}
else {
/* scale histogram values */
- const float yfac = MIN2(powf(hist->ymax, 2.f), 1.f) * 0.5f;
+ const float yfac = minf(powf(hist->ymax, 2.0f), 1.0f) * 0.5f;
hist->ymax += dy * yfac;
CLAMP(hist->ymax, 1.f, 100.f);
diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c
index 2ceb8aeef26..882d3115ba0 100644
--- a/source/blender/editors/mesh/editmesh_knife.c
+++ b/source/blender/editors/mesh/editmesh_knife.c
@@ -1400,9 +1400,10 @@ static float knife_snap_size(KnifeTool_OpData *kcd, float maxsize)
{
float density = (float)knife_sample_screen_density(kcd, maxsize * 2.0f);
- density = MAX2(density, 1);
+ if (density < 1.0f)
+ density = 1.0f;
- return MIN2(maxsize / (density * 0.5f), maxsize);
+ return minf(maxsize / (density * 0.5f), maxsize);
}
/* p is closest point on edge to the mouse cursor */
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index e6ea42aa5ba..3079719efe0 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -1574,6 +1574,8 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
else if (bgpic->source == V3D_BGPIC_MOVIE) {
clip = NULL;
+ /* TODO: skip drawing when out of frame range (as image sequences do above) */
+
if (bgpic->flag & V3D_BGPIC_CAMERACLIP) {
if (scene->camera)
clip = BKE_object_movieclip_get(scene, scene->camera, 1);
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index 44860258c89..35281168c2e 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -1392,8 +1392,8 @@ static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata)
float dx = t->mval[0] - cent[0], dy = t->mval[1] - cent[1];
float angle = atan2f(dy, dx);
float dist = sqrtf(dx * dx + dy * dy);
- float delta_angle = MIN2(15.0f / dist, (float)M_PI / 4.0f);
- float spacing_angle = MIN2(5.0f / dist, (float)M_PI / 12.0f);
+ float delta_angle = minf(15.0f / dist, (float)M_PI / 4.0f);
+ float spacing_angle = minf(5.0f / dist, (float)M_PI / 12.0f);
UI_ThemeColor(TH_WIRE);
setlinestyle(3);
diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c
index af0b33d58ae..d7241555cc7 100644
--- a/source/blender/editors/transform/transform_conversions.c
+++ b/source/blender/editors/transform/transform_conversions.c
@@ -1829,7 +1829,7 @@ static void editmesh_set_connectivity_distance(BMEditMesh *em, float mtx[][3], f
d2 = d + len_v3(vec);
if (dists[BM_elem_index_get(v3)] != FLT_MAX)
- dists[BM_elem_index_get(v3)] = MIN2(d2, dists[BM_elem_index_get(v3)]);
+ dists[BM_elem_index_get(v3)] = minf(d2, dists[BM_elem_index_get(v3)]);
else
dists[BM_elem_index_get(v3)] = d2;
diff --git a/source/blender/editors/uvedit/uvedit_smart_stitch.c b/source/blender/editors/uvedit/uvedit_smart_stitch.c
index 43f3e81ae92..5c2e57cf27f 100644
--- a/source/blender/editors/uvedit/uvedit_smart_stitch.c
+++ b/source/blender/editors/uvedit/uvedit_smart_stitch.c
@@ -403,7 +403,9 @@ static void stitch_island_calculate_edge_rotation(UvEdge *edge, StitchState *sta
edgecos = uv1[0] * uv2[0] + uv1[1] * uv2[1];
edgesin = uv1[0] * uv2[1] - uv2[0] * uv1[1];
- rotation = (edgesin > 0.0f) ? acosf(MAX2(-1.0f, MIN2(1.0f, edgecos))) : -acosf(MAX2(-1.0f, MIN2(1.0f, edgecos)));
+ rotation = (edgesin > 0.0f) ?
+ +acosf(maxf(-1.0f, minf(1.0f, edgecos))) :
+ -acosf(maxf(-1.0f, minf(1.0f, edgecos)));
island_stitch_data[element1->island].num_rot_elements++;
island_stitch_data[element1->island].rotation += rotation;
diff --git a/source/blender/render/intern/source/shadeoutput.c b/source/blender/render/intern/source/shadeoutput.c
index 82f2add7c3d..b208df74de9 100644
--- a/source/blender/render/intern/source/shadeoutput.c
+++ b/source/blender/render/intern/source/shadeoutput.c
@@ -798,7 +798,6 @@ static float OrenNayar_Diff(float nl, const float n[3], const float l[3], const
/* Minnaert diffuse */
static float Minnaert_Diff(float nl, const float n[3], const float v[3], float darkness)
{
-
float i, nv;
/* nl = dot product between surface normal and light vector */
@@ -806,12 +805,12 @@ static float Minnaert_Diff(float nl, const float n[3], const float v[3], float d
return 0.0f;
/* nv = dot product between surface normal and view vector */
- nv = n[0]*v[0]+n[1]*v[1]+n[2]*v[2];
+ nv = dot_v3v3(n, v);
if (nv < 0.0f)
nv = 0.0f;
if (darkness <= 1.0f)
- i = nl * pow(MAX2(nv*nl, 0.1f), (darkness - 1.0f) ); /*The Real model*/
+ i = nl * pow(maxf(nv * nl, 0.1f), (darkness - 1.0f) ); /*The Real model*/
else
i = nl * pow( (1.001f - nv), (darkness - 1.0f) ); /*Nvidia model*/
diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
index 46ebd0ecc4f..ea4ac1e150b 100644
--- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
+++ b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
@@ -311,7 +311,7 @@ int SCA_Joystick::pAxisTest(int axisnum)
short i2= m_axis_array[(axisnum*2)+1];
/* long winded way to do
- * return MAX2(abs(i1), abs(i2))
+ * return maxf(absf(i1), absf(i2))
* avoid abs from math.h */
if (i1 < 0) i1 = -i1;
if (i2 < 0) i2 = -i2;
diff --git a/source/gameengine/Ketsji/KX_ObstacleSimulation.cpp b/source/gameengine/Ketsji/KX_ObstacleSimulation.cpp
index fd47587e2c8..a942f87856c 100644
--- a/source/gameengine/Ketsji/KX_ObstacleSimulation.cpp
+++ b/source/gameengine/Ketsji/KX_ObstacleSimulation.cpp
@@ -378,13 +378,14 @@ static MT_Point3 nearestPointToObstacle(MT_Point3& pos ,KX_Obstacle* obstacle)
MT_Vector3 ab = obstacle->m_pos2 - obstacle->m_pos;
if (!ab.fuzzyZero())
{
+ const MT_Scalar dist = ab.length();
MT_Vector3 abdir = ab.normalized();
MT_Vector3 v = pos - obstacle->m_pos;
MT_Scalar proj = abdir.dot(v);
- CLAMP(proj, 0, ab.length());
+ CLAMP(proj, 0, dist);
MT_Point3 res = obstacle->m_pos + abdir*proj;
return res;
- }
+ }
}
case KX_OBSTACLE_CIRCLE :
default: