code cleanup: float <> double conversion.

This commit is contained in:
Campbell Barton 2012-11-03 18:23:30 +00:00
parent a18ead1521
commit 9b948717b0
19 changed files with 69 additions and 69 deletions

@ -318,12 +318,12 @@ void IDP_FreeProperty(struct IDProperty *prop);
/** Unlinks any struct IDProperty<->ID linkage that might be going on.*/
void IDP_UnlinkProperty(struct IDProperty *prop);
#define IDP_Int(prop) ((prop)->data.val)
#define IDP_Float(prop) (*(float *)&(prop)->data.val)
#define IDP_String(prop) ((char *)(prop)->data.pointer)
#define IDP_Array(prop) ((prop)->data.pointer)
#define IDP_IDPArray(prop) ((IDProperty *)(prop)->data.pointer)
#define IDP_Double(prop) (*(double *)&(prop)->data.val)
#define IDP_Int(prop) ((prop)->data.val)
#define IDP_Float(prop) (*(float *)&(prop)->data.val)
#define IDP_Double(prop) (*(double *)&(prop)->data.val)
#define IDP_String(prop) ((char *) (prop)->data.pointer)
#define IDP_Array(prop) ((prop)->data.pointer)
#define IDP_IDPArray(prop) ((IDProperty *) (prop)->data.pointer)
#ifdef DEBUG
/* for printout only */

@ -378,8 +378,8 @@ float BKE_mask_spline_project_co(MaskSpline *spline, MaskSplinePoint *point,
if (len_squared_v2(v1) > proj_eps_squared) {
ang1 = angle_v2v2(v1, n1);
if (ang1 > M_PI / 2.0f)
ang1 = M_PI - ang1;
if (ang1 > (float)M_PI / 2.0f)
ang1 = (float)M_PI - ang1;
if (ang < 0.0f || ang1 < ang) {
ang = ang1;
@ -405,8 +405,8 @@ float BKE_mask_spline_project_co(MaskSpline *spline, MaskSplinePoint *point,
if (len_squared_v2(v2) > proj_eps_squared) {
ang2 = angle_v2v2(v2, n2);
if (ang2 > M_PI / 2.0f)
ang2 = M_PI - ang2;
if (ang2 > (float)M_PI / 2.0f)
ang2 = (float)M_PI - ang2;
if (ang2 < ang) {
ang = ang2;
@ -555,7 +555,7 @@ float BKE_mask_point_weight_scalar(MaskSpline *spline, MaskSplinePoint *point, c
if (!bezt_next) {
return bezt->weight;
}
else if (u <= 0.0) {
else if (u <= 0.0f) {
return bezt->weight;
}
else if (u >= 1.0f) {
@ -576,7 +576,7 @@ float BKE_mask_point_weight(MaskSpline *spline, MaskSplinePoint *point, const fl
if (!bezt_next) {
return bezt->weight;
}
else if (u <= 0.0) {
else if (u <= 0.0f) {
return bezt->weight;
}
else if (u >= 1.0f) {
@ -1805,7 +1805,7 @@ static void interp_weights_uv_v2_calc(float r_uv[2], const float pt[2], const fl
float pt_on_line[2];
r_uv[0] = closest_to_line_v2(pt_on_line, pt, pt_a, pt_b);
r_uv[1] = (len_v2v2(pt_on_line, pt) / len_v2v2(pt_a, pt_b)) *
((line_point_side_v2(pt_a, pt_b, pt) < 0.0f) ? -1.0 : 1.0); /* this line only sets the sign */
((line_point_side_v2(pt_a, pt_b, pt) < 0.0f) ? -1.0f : 1.0f); /* this line only sets the sign */
}

@ -428,7 +428,7 @@ static void layer_bucket_init(MaskRasterLayer *layer, const float pixel_size)
/* width and height of each bucket */
const float bucket_size_x = (bucket_dim_x + FLT_EPSILON) / layer->buckets_x;
const float bucket_size_y = (bucket_dim_y + FLT_EPSILON) / layer->buckets_y;
const float bucket_max_rad = (max_ff(bucket_size_x, bucket_size_y) * M_SQRT2) + FLT_EPSILON;
const float bucket_max_rad = (max_ff(bucket_size_x, bucket_size_y) * (float)M_SQRT2) + FLT_EPSILON;
const float bucket_max_rad_squared = bucket_max_rad * bucket_max_rad;
unsigned int *face = &layer->face_array[0][0];

@ -1505,7 +1505,7 @@ static void find_first_points(PROCESS *mbproc, MetaBall *mb, int a)
float f = 0.0f;
ml = G_mb.mainb[a];
f = 1.0 - (mb->thresh / ml->s);
f = 1.0f - (mb->thresh / ml->s);
/* Skip, when Stiffness of MetaElement is too small ... MetaElement can't be
* visible alone ... but still can influence others MetaElements :-) */

@ -234,7 +234,7 @@ void quat_to_mat4(float m[][4], const float q[4])
double q0, q1, q2, q3, qda, qdb, qdc, qaa, qab, qac, qbb, qbc, qcc;
#ifdef DEBUG
if (!((q0 = dot_qtqt(q, q)) == 0.0f || (fabsf(q0 - 1.0) < QUAT_EPSILON))) {
if (!((q0 = dot_qtqt(q, q)) == 0.0f || (fabsf(q0 - 1.0) < (float)QUAT_EPSILON))) {
fprintf(stderr, "Warning! quat_to_mat4() called with non-normalized: size %.8f *** report a bug ***\n", (float)q0);
}
#endif
@ -1077,11 +1077,11 @@ void compatible_eul(float eul[3], const float oldrot[3])
for (i = 0; i < 3; i++) {
deul[i] = eul[i] - oldrot[i];
if (deul[i] > pi_thresh) {
eul[i] -= floorf(( deul[i] / pi_x2) + 0.5) * pi_x2;
eul[i] -= floorf(( deul[i] / pi_x2) + 0.5f) * pi_x2;
deul[i] = eul[i] - oldrot[i];
}
else if (deul[i] < -pi_thresh) {
eul[i] += floorf((-deul[i] / pi_x2) + 0.5) * pi_x2;
eul[i] += floorf((-deul[i] / pi_x2) + 0.5f) * pi_x2;
deul[i] = eul[i] - oldrot[i];
}
}

@ -39,7 +39,7 @@
#include "BLI_voronoi.h"
#include "BLI_utildefines.h"
#define VORONOI_EPS 1e-2
#define VORONOI_EPS 1e-2f
enum {
voronoiEventType_Site = 0,

@ -313,7 +313,7 @@ void poly_rotate_plane(const float normal[3], float (*verts)[3], const int nvert
float up[3] = {0.0f, 0.0f, 1.0f}, axis[3], q[4];
float mat[3][3];
double angle;
float angle;
int i;
cross_v3_v3v3(axis, normal, up);
@ -329,7 +329,7 @@ void poly_rotate_plane(const float normal[3], float (*verts)[3], const int nvert
axis[2] = 0.0f;
}
axis_angle_to_quat(q, axis, (float)angle);
axis_angle_to_quat(q, axis, angle);
quat_to_mat3(mat, q);
for (i = 0; i < nverts; i++)

@ -365,7 +365,7 @@ void bmo_create_uvsphere_exec(BMesh *bm, BMOperator *op)
len2 = len_v3v3(vec, vec2);
/* use shortest segment length divided by 3 as merge threshold */
BMO_op_callf(bm, op->flag, "remove_doubles verts=%fv dist=%f", VERT_MARK, MIN2(len, len2) / 3.0f);
BMO_op_callf(bm, op->flag, "remove_doubles verts=%fv dist=%f", VERT_MARK, min_ff(len, len2) / 3.0f);
}
/* and now do imat */

@ -45,8 +45,8 @@
#define SMOOTH_LAPLACIAN_AREA_FACTOR 4.0f
#define SMOOTH_LAPLACIAN_EDGE_FACTOR 2.0f
#define SMOOTH_LAPLACIAN_MAX_EDGE_PERCENTAGE 1.8
#define SMOOTH_LAPLACIAN_MIN_EDGE_PERCENTAGE 0.15
#define SMOOTH_LAPLACIAN_MAX_EDGE_PERCENTAGE 1.8f
#define SMOOTH_LAPLACIAN_MIN_EDGE_PERCENTAGE 0.15f
struct BLaplacianSystem {
float *eweights; /* Length weights per Edge */
@ -236,7 +236,7 @@ static void init_laplacian_matrix(LaplacianSystem *sys)
areaf = area_tri_v3(v1, v2, v3);
}
if (fabs(areaf) < sys->min_area) {
if (fabsf(areaf) < sys->min_area) {
sys->zerola[idv1] = 1;
sys->zerola[idv2] = 1;
sys->zerola[idv3] = 1;
@ -443,13 +443,13 @@ static float compute_volume(BMesh *bm)
y3 = vf[2]->co[1];
z3 = vf[2]->co[2];
vol += (1.0 / 6.0) * (0.0 - x3 * y2 * z1 + x2 * y3 * z1 + x3 * y1 * z2 - x1 * y3 * z2 - x2 * y1 * z3 + x1 * y2 * z3);
vol += (1.0f / 6.0f) * (0.0f - x3 * y2 * z1 + x2 * y3 * z1 + x3 * y1 * z2 - x1 * y3 * z2 - x2 * y1 * z3 + x1 * y2 * z3);
if (i == 4) {
x4 = vf[3]->co[0];
y4 = vf[3]->co[1];
z4 = vf[3]->co[2];
vol += (1.0 / 6.0) * (x1 * y3 * z4 - x1 * y4 * z3 - x3 * y1 * z4 + x3 * z1 * y4 + y1 * x4 * z3 - x4 * y3 * z1);
vol += (1.0f / 6.0f) * (x1 * y3 * z4 - x1 * y4 * z3 - x3 * y1 * z4 + x3 * z1 * y4 + y1 * x4 * z3 - x4 * y3 * z1);
}
}
return fabs(vol);

@ -54,7 +54,7 @@
#define ELE_SPLIT 16
/* see bug [#32665], 0.00005 means a we get face splits at a little under 1.0 degrees */
#define FLT_FACE_SPLIT_EPSILON 0.00005
#define FLT_FACE_SPLIT_EPSILON 0.00005f
/*
* NOTE: beauty has been renamed to flag!

@ -1226,7 +1226,7 @@ static void harmonic_ray_callback(void *userdata, int index, const BVHTreeRay *r
hit->dist = dist;
copy_v3_v3(hit->co, co);
isec->isect = dot_v3v3(no, ray->direction) <= 0.0;
isec->isect = (dot_v3v3(no, ray->direction) <= 0.0f);
isec->labda = dist;
isec->face = mf;
}

@ -2000,7 +2000,7 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, const rcti *
/* draws in resolution of 20x4 colors */
void ui_draw_gradient(rcti *rect, const float hsv[3], const int type, const float alpha)
{
const float color_step = (type == UI_GRAD_H) ? 0.02 : 0.05f;
const float color_step = (type == UI_GRAD_H) ? 0.02f : 0.05f;
int a;
float h = hsv[0], s = hsv[1], v = hsv[2];
float dx, dy, sx1, sx2, sy;

@ -1216,13 +1216,13 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
if (ca->flag & CAM_SHOWTITLESAFE) {
UI_ThemeColorBlendShade(TH_WIRE, TH_BACK, 0.25, 0);
hmargin = 0.1 * (x2 - x1);
vmargin = 0.05 * (y2 - y1);
uiDrawBox(GL_LINE_LOOP, x1 + hmargin, y1+vmargin, x2 - hmargin, y2 - vmargin, 2.0);
hmargin = 0.1f * (x2 - x1);
vmargin = 0.05f * (y2 - y1);
uiDrawBox(GL_LINE_LOOP, x1 + hmargin, y1+vmargin, x2 - hmargin, y2 - vmargin, 2.0f);
hmargin = 0.035 * (x2 - x1);
vmargin = 0.035 * (y2 - y1);
uiDrawBox(GL_LINE_LOOP, x1 + hmargin, y1+vmargin, x2 - hmargin, y2 - vmargin, 2.0);
hmargin = 0.035f * (x2 - x1);
vmargin = 0.035f * (y2 - y1);
uiDrawBox(GL_LINE_LOOP, x1 + hmargin, y1+vmargin, x2 - hmargin, y2 - vmargin, 2.0f);
}
if (ca && (ca->flag & CAM_SHOWSENSOR)) {
/* determine sensor fit, and get sensor x/y, for auto fit we

@ -163,8 +163,8 @@ eV3DProjStatus ED_view3d_project_short_ex(ARegion *ar, float perspmat[4][4], con
float tvec[2];
eV3DProjStatus ret = ed_view3d_project__internal(ar, perspmat, is_local, co, tvec, flag);
if (ret == V3D_PROJ_RET_OK) {
if ((tvec[0] > -32700.0 && tvec[0] < 32700.0f) &&
(tvec[1] > -32700.0 && tvec[1] < 32700.0f))
if ((tvec[0] > -32700.0f && tvec[0] < 32700.0f) &&
(tvec[1] > -32700.0f && tvec[1] < 32700.0f))
{
r_co[0] = (short)floor(tvec[0]);
r_co[1] = (short)floor(tvec[1]);
@ -182,8 +182,8 @@ eV3DProjStatus ED_view3d_project_int_ex(ARegion *ar, float perspmat[4][4], const
float tvec[2];
eV3DProjStatus ret = ed_view3d_project__internal(ar, perspmat, is_local, co, tvec, flag);
if (ret == V3D_PROJ_RET_OK) {
if ((tvec[0] > -2140000000.0 && tvec[0] < 2140000000.0f) &&
(tvec[1] > -2140000000.0 && tvec[1] < 2140000000.0f))
if ((tvec[0] > -2140000000.0f && tvec[0] < 2140000000.0f) &&
(tvec[1] > -2140000000.0f && tvec[1] < 2140000000.0f))
{
r_co[0] = (int)floor(tvec[0]);
r_co[1] = (int)floor(tvec[1]);

@ -1442,7 +1442,7 @@ void GPU_update_mesh_buffers(GPU_Buffers *buffers, MVert *mvert,
fmask = (vmask[fv[0]] +
vmask[fv[1]] +
vmask[fv[2]] +
vmask[fv[3]]) * 0.25;
vmask[fv[3]]) * 0.25f;
}
}
else {
@ -1915,7 +1915,7 @@ static void gpu_draw_buffers_legacy_mesh(GPU_Buffers *buffers)
buffers->vmask[fv[1]] +
buffers->vmask[fv[2]]);
if (f->v4)
fmask = (fmask + buffers->vmask[fv[3]]) * 0.25;
fmask = (fmask + buffers->vmask[fv[3]]) * 0.25f;
else
fmask /= 3.0f;
gpu_color_from_mask_set(fmask, diffuse_color);

@ -1589,8 +1589,8 @@ void GPU_lamp_update_distance(GPULamp *lamp, float distance, float att1, float a
void GPU_lamp_update_spot(GPULamp *lamp, float spotsize, float spotblend)
{
lamp->spotsi= cos(M_PI*spotsize/360.0);
lamp->spotbl= (1.0f - lamp->spotsi)*spotblend;
lamp->spotsi= cosf((float)M_PI * spotsize / 360.0f);
lamp->spotbl= (1.0f - lamp->spotsi) * spotblend;
}
static void gpu_lamp_from_blender(Scene *scene, Object *ob, Object *par, Lamp *la, GPULamp *lamp)

@ -52,8 +52,8 @@
#include "ONL_opennl.h"
#define MOD_LAPLACIANSMOOTH_MAX_EDGE_PERCENTAGE 1.8
#define MOD_LAPLACIANSMOOTH_MIN_EDGE_PERCENTAGE 0.02
#define MOD_LAPLACIANSMOOTH_MAX_EDGE_PERCENTAGE 1.8f
#define MOD_LAPLACIANSMOOTH_MIN_EDGE_PERCENTAGE 0.02f
struct BLaplacianSystem {
float *eweights; /* Length weights per Edge */
@ -279,13 +279,13 @@ static float compute_volume(float (*vertexCos)[3], MFace *mfaces, int numFaces)
z3 = vf[2][2];
vol += (1.0 / 6.0) * (x2 * y3 * z1 + x3 * y1 * z2 - x1 * y3 * z2 - x2 * y1 * z3 + x1 * y2 * z3 - x3 * y2 * z1);
vol += (1.0f / 6.0f) * (x2 * y3 * z1 + x3 * y1 * z2 - x1 * y3 * z2 - x2 * y1 * z3 + x1 * y2 * z3 - x3 * y2 * z1);
if ((&mfaces[i])->v4) {
vf[3] = vertexCos[mfaces[i].v4];
x4 = vf[3][0];
y4 = vf[3][1];
z4 = vf[3][2];
vol += (1.0 / 6.0) * (x1 * y3 * z4 - x1 * y4 * z3 - x3 * y1 * z4 + x3 * z1 * y4 + y1 * x4 * z3 - x4 * y3 * z1);
vol += (1.0f / 6.0f) * (x1 * y3 * z4 - x1 * y4 * z3 - x3 * y1 * z4 + x3 * z1 * y4 + y1 * x4 * z3 - x4 * y3 * z1);
}
}
return fabsf(vol);
@ -365,7 +365,7 @@ static void init_laplacian_matrix(LaplacianSystem *sys)
else {
areaf = area_tri_v3(v1, v2, v3);
}
if (fabs(areaf) < sys->min_area) {
if (fabsf(areaf) < sys->min_area) {
sys->zerola[idv1] = 1;
sys->zerola[idv2] = 1;
sys->zerola[idv3] = 1;

@ -49,33 +49,33 @@
* static conversion functions to avoid duplicate code, no type checking.
*/
static PyObject *idprop_py_from_idp_string(IDProperty *prop)
static PyObject *idprop_py_from_idp_string(const IDProperty *prop)
{
if (prop->subtype == IDP_STRING_SUB_BYTE) {
return PyBytes_FromStringAndSize(IDP_Array(prop), prop->len);
return PyBytes_FromStringAndSize(IDP_String(prop), prop->len);
}
else {
#ifdef USE_STRING_COERCE
return PyC_UnicodeFromByteAndSize(IDP_Array(prop), prop->len - 1);
#else
return PyUnicode_FromStringAndSize(IDP_Array(prop), prop->len - 1);
return PyUnicode_FromStringAndSize(IDP_String(prop), prop->len - 1);
#endif
}
}
static PyObject *idprop_py_from_idp_int(IDProperty *prop)
static PyObject *idprop_py_from_idp_int(const IDProperty *prop)
{
return PyLong_FromLong((long)prop->data.val);
return PyLong_FromLong((long)IDP_Int(prop));
}
static PyObject *idprop_py_from_idp_float(IDProperty *prop)
static PyObject *idprop_py_from_idp_float(const IDProperty *prop)
{
return PyFloat_FromDouble((double)(*(float *)(&prop->data.val)));
return PyFloat_FromDouble((double)IDP_Float(prop));
}
static PyObject *idprop_py_from_idp_double(IDProperty *prop)
static PyObject *idprop_py_from_idp_double(const IDProperty *prop)
{
return PyFloat_FromDouble((*(double *)(&prop->data.val)));
return PyFloat_FromDouble(IDP_Double(prop));
}
static PyObject *idprop_py_from_idp_group(ID *id, IDProperty *prop, IDProperty *parent)
@ -189,7 +189,7 @@ static int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject
PyErr_SetString(PyExc_TypeError, "expected an int type");
return -1;
}
prop->data.val = ivalue;
IDP_Int(prop) = ivalue;
break;
}
case IDP_FLOAT:
@ -199,7 +199,7 @@ static int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject
PyErr_SetString(PyExc_TypeError, "expected a float");
return -1;
}
*(float *)&self->prop->data.val = fvalue;
IDP_Float(self->prop) = fvalue;
break;
}
case IDP_DOUBLE:
@ -209,7 +209,7 @@ static int BPy_IDGroup_SetData(BPy_IDProperty *self, IDProperty *prop, PyObject
PyErr_SetString(PyExc_TypeError, "expected a float");
return -1;
}
*(double *)&self->prop->data.val = dvalue;
IDP_Double(self->prop) = dvalue;
break;
}
default:

@ -590,8 +590,8 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void)
break;
case GHOST_kKeyNumpadPlus:
if (val == 0) break;
zoomx += 2.0;
zoomy += 2.0;
zoomx += 2.0f;
zoomy += 2.0f;
/* no break??? - is this intentional? - campbell XXX25 */
case GHOST_kKeyNumpadMinus:
{
@ -599,8 +599,8 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void)
/* int ofsx, ofsy; */ /* UNUSED */
if (val == 0) break;
if (zoomx > 1.0) zoomx -= 1.0;
if (zoomy > 1.0) zoomy -= 1.0;
if (zoomx > 1.0f) zoomx -= 1.0f;
if (zoomy > 1.0f) zoomy -= 1.0f;
// playanim_window_get_position(&ofsx, &ofsy);
playanim_window_get_size(&sizex, &sizey);
/* ofsx += sizex / 2; */ /* UNUSED */
@ -665,10 +665,10 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr ps_void)
zoomx = (float) sizex / ps->ibufx;
zoomy = (float) sizey / ps->ibufy;
zoomx = floor(zoomx + 0.5);
zoomy = floor(zoomy + 0.5);
if (zoomx < 1.0) zoomx = 1.0;
if (zoomy < 1.0) zoomy = 1.0;
zoomx = floor(zoomx + 0.5f);
zoomy = floor(zoomy + 0.5f);
if (zoomx < 1.0f) zoomx = 1.0f;
if (zoomy < 1.0f) zoomy = 1.0f;
sizex = zoomx * ps->ibufx;
sizey = zoomy * ps->ibufy;