Cleanup: Use C++ math functions instead of macros

And remove the unused or now-unused macros.
This commit is contained in:
Hans Goudey
2024-01-04 15:24:03 -05:00
parent 53e2dcadec
commit 709dcc50cf
7 changed files with 39 additions and 95 deletions

View File

@@ -24,6 +24,7 @@
#include "BLI_math_matrix.h"
#include "BLI_math_rotation.h"
#include "BLI_math_vector.h"
#include "BLI_math_vector.hh"
#include "BLI_memarena.h"
#include "BLI_string_utils.hh"
#include "BLI_utildefines.h"
@@ -1085,7 +1086,7 @@ static void closest_latice(int r[3], const float pos[3], const float size)
static void find_first_points(PROCESS *process, const uint em)
{
const MetaElem *ml;
int center[3], lbn[3], rtf[3], it[3], dir[3], add[3];
blender::int3 center, lbn, rtf, it, dir, add;
float tmp[3], a, b;
ml = process->mainb[em];
@@ -1116,7 +1117,7 @@ static void find_first_points(PROCESS *process, const uint em)
add[0] = it[0] - dir[0];
add[1] = it[1] - dir[1];
add[2] = it[2] - dir[2];
DO_MIN(it, add);
add = blender::math::min(add, it);
add_cube(process, add[0], add[1], add[2]);
break;
}
@@ -1255,7 +1256,7 @@ static void init_meta(Depsgraph *depsgraph, PROCESS *process, Scene *scene, Obje
if (!(ml->flag & MB_HIDE)) {
float pos[4][4], rot[4][4];
float expx, expy, expz;
float tempmin[3], tempmax[3];
blender::float3 tempmin, tempmax;
MetaElem *new_ml;
@@ -1352,7 +1353,7 @@ static void init_meta(Depsgraph *depsgraph, PROCESS *process, Scene *scene, Obje
/* Find max and min of transformed bounding-box. */
INIT_MINMAX(tempmin, tempmax);
for (i = 0; i < 8; i++) {
DO_MINMAX(new_ml->bb->vec[i], tempmin, tempmax);
blender::math::min_max(blender::float3(new_ml->bb->vec[i]), tempmin, tempmax);
}
/* Set only point 0 and 6 - AABB of meta-elem. */

View File

@@ -187,13 +187,14 @@ static void sample_nearest_weights(const Span<float3> vert_positions,
}
}
const int3 &tri = corner_tris[tri_indices[i]];
bary_coords[i] = MIN3_PAIR(
const std::array<float, 3> distances{
math::distance_squared(sample_positions[i], vert_positions[corner_verts[tri[0]]]),
math::distance_squared(sample_positions[i], vert_positions[corner_verts[tri[1]]]),
math::distance_squared(sample_positions[i], vert_positions[corner_verts[tri[2]]]),
float3(1, 0, 0),
float3(0, 1, 0),
float3(0, 0, 1));
};
const int index = std::min_element(distances.begin(), distances.end()) - distances.begin();
const std::array<float3, 3> weights{float3(1, 0, 0), float3(0, 1, 0), float3(0, 0, 1)};
bary_coords[i] = weights[index];
});
}

View File

@@ -104,13 +104,6 @@ extern "C" {
# define MAX4(a, b, c, d) (MAX2(MAX2((a), (b)), MAX2((c), (d))))
#endif
/* min/max that return a value of our choice */
#define MAX3_PAIR(cmp_a, cmp_b, cmp_c, ret_a, ret_b, ret_c) \
((cmp_a > cmp_b) ? ((cmp_a > cmp_c) ? ret_a : ret_c) : ((cmp_b > cmp_c) ? ret_b : ret_c))
#define MIN3_PAIR(cmp_a, cmp_b, cmp_c, ret_a, ret_b, ret_c) \
((cmp_a < cmp_b) ? ((cmp_a < cmp_c) ? ret_a : ret_c) : ((cmp_b < cmp_c) ? ret_b : ret_c))
#define INIT_MINMAX(min, max) \
{ \
(min)[0] = (min)[1] = (min)[2] = 1.0e30f; \
@@ -123,70 +116,6 @@ extern "C" {
(max)[0] = (max)[1] = -1.0e30f; \
} \
(void)0
#define DO_MIN(vec, min) \
{ \
if ((min)[0] > (vec)[0]) { \
(min)[0] = (vec)[0]; \
} \
if ((min)[1] > (vec)[1]) { \
(min)[1] = (vec)[1]; \
} \
if ((min)[2] > (vec)[2]) { \
(min)[2] = (vec)[2]; \
} \
} \
(void)0
#define DO_MAX(vec, max) \
{ \
if ((max)[0] < (vec)[0]) { \
(max)[0] = (vec)[0]; \
} \
if ((max)[1] < (vec)[1]) { \
(max)[1] = (vec)[1]; \
} \
if ((max)[2] < (vec)[2]) { \
(max)[2] = (vec)[2]; \
} \
} \
(void)0
#define DO_MINMAX(vec, min, max) \
{ \
if ((min)[0] > (vec)[0]) { \
(min)[0] = (vec)[0]; \
} \
if ((min)[1] > (vec)[1]) { \
(min)[1] = (vec)[1]; \
} \
if ((min)[2] > (vec)[2]) { \
(min)[2] = (vec)[2]; \
} \
if ((max)[0] < (vec)[0]) { \
(max)[0] = (vec)[0]; \
} \
if ((max)[1] < (vec)[1]) { \
(max)[1] = (vec)[1]; \
} \
if ((max)[2] < (vec)[2]) { \
(max)[2] = (vec)[2]; \
} \
} \
(void)0
#define DO_MINMAX2(vec, min, max) \
{ \
if ((min)[0] > (vec)[0]) { \
(min)[0] = (vec)[0]; \
} \
if ((min)[1] > (vec)[1]) { \
(min)[1] = (vec)[1]; \
} \
if ((max)[0] < (vec)[0]) { \
(max)[0] = (vec)[0]; \
} \
if ((max)[1] < (vec)[1]) { \
(max)[1] = (vec)[1]; \
} \
} \
(void)0
/** \} */

View File

@@ -8,6 +8,8 @@
#pragma once
#include "BLI_math_vector_types.hh"
struct Object;
struct PTCacheEdit;
struct ParticleEditSettings;
@@ -31,8 +33,11 @@ PTCacheEdit *PE_get_current_from_psys(ParticleSystem *psys);
PTCacheEdit *PE_get_current(Depsgraph *depsgraph, Scene *scene, Object *ob);
PTCacheEdit *PE_create_current(Depsgraph *depsgraph, Scene *scene, Object *ob);
void PE_current_changed(Depsgraph *depsgraph, Scene *scene, Object *ob);
int PE_minmax(
Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, float min[3], float max[3]);
int PE_minmax(Depsgraph *depsgraph,
Scene *scene,
ViewLayer *view_layer,
blender::float3 &min,
blender::float3 &max);
ParticleEditSettings *PE_settings(Scene *scene);
/* update calls */

View File

@@ -168,8 +168,11 @@ void PE_free_ptcache_edit(PTCacheEdit *edit)
MEM_freeN(edit);
}
int PE_minmax(
Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, float min[3], float max[3])
int PE_minmax(Depsgraph *depsgraph,
Scene *scene,
ViewLayer *view_layer,
blender::float3 &min,
blender::float3 &max)
{
BKE_view_layer_synced_ensure(scene, view_layer);
Object *ob = BKE_view_layer_active_object_get(view_layer);
@@ -201,7 +204,7 @@ int PE_minmax(
LOOP_SELECTED_KEYS {
copy_v3_v3(co, key->co);
mul_m4_v3(mat, co);
DO_MINMAX(co, min, max);
blender::math::min_max(blender::float3(co), min, max);
ok = 1;
}
}
@@ -4159,7 +4162,9 @@ static int particle_intersect_mesh(Depsgraph *depsgraph,
{
const MFace *mface = nullptr;
int i, totface, intersect = 0;
float cur_d, cur_uv[2], v1[3], v2[3], v3[3], v4[3], min[3], max[3], p_min[3], p_max[3];
float cur_d;
blender::float2 cur_uv;
blender::float3 v1, v2, v3, v4, min, max, p_min, p_max;
float cur_ipoint[3];
if (mesh == nullptr) {
@@ -4216,11 +4221,11 @@ static int particle_intersect_mesh(Depsgraph *depsgraph,
if (face_minmax == nullptr) {
INIT_MINMAX(min, max);
DO_MINMAX(v1, min, max);
DO_MINMAX(v2, min, max);
DO_MINMAX(v3, min, max);
blender::math::min_max(blender::float3(v1), min, max);
blender::math::min_max(blender::float3(v2), min, max);
blender::math::min_max(blender::float3(v3), min, max);
if (mface->v4) {
DO_MINMAX(v4, min, max);
blender::math::min_max(blender::float3(v4), min, max);
}
if (isect_aabb_aabb_v3(min, max, p_min, p_max) == 0) {
continue;
@@ -4713,7 +4718,7 @@ static int brush_edit_init(bContext *C, wmOperator *op)
PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob);
ARegion *region = CTX_wm_region(C);
BrushEdit *bedit;
float min[3], max[3];
blender::float3 min, max;
/* set the 'distance factor' for grabbing (used in comb etc) */
INIT_MINMAX(min, max);

View File

@@ -321,7 +321,7 @@ static int viewselected_exec(bContext *C, wmOperator *op)
const bool is_gp_edit = gpd_eval ? GPENCIL_ANY_MODE(gpd_eval) : false;
const bool is_face_map = ((is_gp_edit == false) && region->gizmo_map &&
WM_gizmomap_is_any_selected(region->gizmo_map));
float min[3], max[3];
float3 min, max;
bool ok = false, ok_dist = true;
const bool use_all_regions = RNA_boolean_get(op->ptr, "use_all_regions");
const bool skip_camera = (ED_view3d_camera_lock_check(v3d, rv3d) ||

View File

@@ -17,6 +17,7 @@
#include "BLI_linklist.h"
#include "BLI_math_geom.h"
#include "BLI_math_vector.h"
#include "BLI_math_vector.hh"
#include "BLI_utildefines.h"
#include "BKE_cloth.hh"
@@ -547,7 +548,9 @@ BLI_INLINE void cloth_calc_spring_force(ClothModifierData *clmd, ClothSpring *s)
}
}
static void hair_get_boundbox(ClothModifierData *clmd, float gmin[3], float gmax[3])
static void hair_get_boundbox(ClothModifierData *clmd,
blender::float3 &gmin,
blender::float3 &gmax)
{
Cloth *cloth = clmd->clothObject;
Implicit_Data *data = cloth->implicit;
@@ -556,9 +559,9 @@ static void hair_get_boundbox(ClothModifierData *clmd, float gmin[3], float gmax
INIT_MINMAX(gmin, gmax);
for (i = 0; i < mvert_num; i++) {
float x[3];
blender::float3 x;
SIM_mass_spring_get_motion_state(data, i, x, nullptr);
DO_MINMAX(x, gmin, gmax);
blender::math::min_max(x, gmin, gmax);
}
}
@@ -957,7 +960,7 @@ static void cloth_continuum_step(ClothModifierData *clmd, float dt)
*/
float density_target = parms->density_target;
float density_strength = parms->density_strength;
float gmin[3], gmax[3];
blender::float3 gmin, gmax;
int i;
/* clear grid info */