code cleanup: use const float and define array size
[blender.git] / source / blender / editors / mesh / editmesh_add.c
index 0d40e8585c3504ce91a570f5459b6757949a938b..f9eb8770012f0c6fd7495783a5a711aa19a004cc 100644 (file)
 #include "ED_screen.h"
 #include "ED_object.h"
 
+#include "mesh_intern.h"
+
 /* uses context to figure out transform for primitive */
 /* returns standard diameter */
-static float new_primitive_matrix(bContext *C, float *loc, float *rot, float primmat[][4])
+static float new_primitive_matrix(bContext *C, const float loc[3], const float rot[3], float primmat[][4])
 {
        Object *obedit = CTX_data_edit_object(C);
        View3D *v3d = CTX_wm_view3d(C);
@@ -83,7 +85,7 @@ static float new_primitive_matrix(bContext *C, float *loc, float *rot, float pri
 
 static void make_prim_init(bContext *C, const char *idname,
                            float *dia, float mat[][4],
-                           int *state, float *loc, float *rot, unsigned int layer)
+                           int *state, const float loc[3], const float rot[3], const unsigned int layer)
 {
        Object *obedit = CTX_data_edit_object(C);
 
@@ -99,7 +101,7 @@ static void make_prim_init(bContext *C, const char *idname,
                *state = 1;
        }
 
-       *dia *= new_primitive_matrix(C, loc, rot, mat);
+       *dia = new_primitive_matrix(C, loc, rot, mat);
 }
 
 static void make_prim_finish(bContext *C, int *state, int enter_editmode)
@@ -125,7 +127,7 @@ static int add_primitive_plane_exec(bContext *C, wmOperator *op)
        Object *obedit;
        Mesh *me;
        BMEditMesh *em;
-       float loc[3], rot[3], mat[4][4], dia = 1.0f;
+       float loc[3], rot[3], mat[4][4], dia;
        int enter_editmode;
        int state;
        unsigned int layer;
@@ -137,15 +139,15 @@ static int add_primitive_plane_exec(bContext *C, wmOperator *op)
        me = obedit->data;
        em = me->edit_btmesh;
 
-       if (!EDBM_CallAndSelectOpf(em, op, "vertout", 
-                                  "create_grid xsegments=%i ysegments=%i size=%f mat=%m4", 1, 1, dia, mat))
+       if (!EDBM_op_call_and_selectf(em, op, "vertout",
+                                     "create_grid xsegments=%i ysegments=%i size=%f mat=%m4", 1, 1, dia, mat))
        {
                return OPERATOR_CANCELLED;
        }
 
        make_prim_finish(C, &state, enter_editmode);
 
-       return OPERATOR_FINISHED;       
+       return OPERATOR_FINISHED;
 }
 
 void MESH_OT_primitive_plane_add(wmOperatorType *ot)
@@ -183,7 +185,7 @@ static int add_primitive_cube_exec(bContext *C, wmOperator *op)
        me = obedit->data;
        em = me->edit_btmesh;
 
-       if (!EDBM_CallAndSelectOpf(em, op, "vertout", "create_cube mat=%m4 size=%f", mat, 2.0f)) {
+       if (!EDBM_op_call_and_selectf(em, op, "vertout", "create_cube mat=%m4 size=%f", mat, dia * 2.0f)) {
                return OPERATOR_CANCELLED;
        }
        
@@ -237,10 +239,10 @@ static int add_primitive_circle_exec(bContext *C, wmOperator *op)
        me = obedit->data;
        em = me->edit_btmesh;
 
-       if (!EDBM_CallAndSelectOpf(em, op, "vertout",
-                                  "create_circle segments=%i diameter=%f cap_ends=%b cap_tris=%b mat=%m4",
-                                  RNA_int_get(op->ptr, "vertices"), RNA_float_get(op->ptr, "radius"),
-                                  cap_end, cap_tri, mat))
+       if (!EDBM_op_call_and_selectf(em, op, "vertout",
+                                     "create_circle segments=%i diameter=%f cap_ends=%b cap_tris=%b mat=%m4",
+                                     RNA_int_get(op->ptr, "vertices"), RNA_float_get(op->ptr, "radius"),
+                                     cap_end, cap_tri, mat))
        {
                return OPERATOR_CANCELLED;
        }
@@ -296,7 +298,7 @@ static int add_primitive_cylinder_exec(bContext *C, wmOperator *op)
        me = obedit->data;
        em = me->edit_btmesh;
 
-       if (!EDBM_CallAndSelectOpf(
+       if (!EDBM_op_call_and_selectf(
                em, op, "vertout",
                "create_cone segments=%i diameter1=%f diameter2=%f cap_ends=%b cap_tris=%b depth=%f mat=%m4",
                RNA_int_get(op->ptr, "vertices"),
@@ -331,7 +333,7 @@ void MESH_OT_primitive_cylinder_add(wmOperatorType *ot)
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
        /* props */
-       RNA_def_int(ot->srna, "vertices", 32, 2, INT_MAX, "Vertices", "", 2, 500);
+       RNA_def_int(ot->srna, "vertices", 32, 3, INT_MAX, "Vertices", "", 3, 500);
        prop = RNA_def_float(ot->srna, "radius", 1.0f, 0.0, FLT_MAX, "Radius", "", 0.001, 100.00);
        RNA_def_property_subtype(prop, PROP_DISTANCE);
        prop = RNA_def_float(ot->srna, "depth", 2.0f, 0.0, FLT_MAX, "Depth", "", 0.001, 100.00);
@@ -361,7 +363,7 @@ static int add_primitive_cone_exec(bContext *C, wmOperator *op)
        me = obedit->data;
        em = me->edit_btmesh;
 
-       if (!EDBM_CallAndSelectOpf(
+       if (!EDBM_op_call_and_selectf(
                em, op, "vertout",
                "create_cone segments=%i diameter1=%f diameter2=%f cap_ends=%b cap_tris=%b depth=%f mat=%m4",
                RNA_int_get(op->ptr, "vertices"), RNA_float_get(op->ptr, "radius1"),
@@ -393,7 +395,7 @@ void MESH_OT_primitive_cone_add(wmOperatorType *ot)
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
        
        /* props */
-       RNA_def_int(ot->srna, "vertices", 32, 2, INT_MAX, "Vertices", "", 2, 500);
+       RNA_def_int(ot->srna, "vertices", 32, 3, INT_MAX, "Vertices", "", 3, 500);
        prop = RNA_def_float(ot->srna, "radius1", 1.0f, 0.0, FLT_MAX, "Radius 1", "", 0.001, 100.00);
        RNA_def_property_subtype(prop, PROP_DISTANCE);
        prop = RNA_def_float(ot->srna, "radius2", 0.0f, 0.0, FLT_MAX, "Radius 2", "", 0.001, 100.00);
@@ -410,7 +412,7 @@ static int add_primitive_grid_exec(bContext *C, wmOperator *op)
        Object *obedit;
        Mesh *me;
        BMEditMesh *em;
-       float loc[3], rot[3], mat[4][4], dia = 1.0f;
+       float loc[3], rot[3], mat[4][4], dia;
        int enter_editmode;
        int state;
        unsigned int layer;
@@ -422,11 +424,11 @@ static int add_primitive_grid_exec(bContext *C, wmOperator *op)
        me = obedit->data;
        em = me->edit_btmesh;
 
-       if (!EDBM_CallAndSelectOpf(em, op, "vertout",
-                                  "create_grid xsegments=%i ysegments=%i size=%f mat=%m4",
-                                  RNA_int_get(op->ptr, "x_subdivisions"),
-                                  RNA_int_get(op->ptr, "y_subdivisions"),
-                                  RNA_float_get(op->ptr, "size") * dia, mat))
+       if (!EDBM_op_call_and_selectf(em, op, "vertout",
+                                     "create_grid xsegments=%i ysegments=%i size=%f mat=%m4",
+                                     RNA_int_get(op->ptr, "x_subdivisions"),
+                                     RNA_int_get(op->ptr, "y_subdivisions"),
+                                     RNA_float_get(op->ptr, "size") * dia, mat))
        {
                return OPERATOR_CANCELLED;
        }
@@ -473,7 +475,7 @@ static int add_primitive_monkey_exec(bContext *C, wmOperator *op)
        
        ED_object_add_generic_get_opts(C, op, loc, rot, &enter_editmode, &layer, &view_aligned);
        if (!view_aligned)
-               rot[0] += M_PI / 2.0f;
+               rot[0] += (float)M_PI / 2.0f;
        
        make_prim_init(C, "Monkey", &dia, mat, &state, loc, rot, layer);
 
@@ -481,7 +483,7 @@ static int add_primitive_monkey_exec(bContext *C, wmOperator *op)
        me = obedit->data;
        em = me->edit_btmesh;
 
-       if (!EDBM_CallAndSelectOpf(em, op, "vertout", "create_monkey mat=%m4", mat)) {
+       if (!EDBM_op_call_and_selectf(em, op, "vertout", "create_monkey mat=%m4", mat)) {
                return OPERATOR_CANCELLED;
        }
        
@@ -524,10 +526,10 @@ static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op)
        me = obedit->data;
        em = me->edit_btmesh;
 
-       if (!EDBM_CallAndSelectOpf(em, op, "vertout",
-                                  "create_uvsphere segments=%i revolutions=%i diameter=%f mat=%m4",
-                                  RNA_int_get(op->ptr, "segments"), RNA_int_get(op->ptr, "ring_count"),
-                                  RNA_float_get(op->ptr, "size"), mat))
+       if (!EDBM_op_call_and_selectf(em, op, "vertout",
+                                     "create_uvsphere segments=%i revolutions=%i diameter=%f mat=%m4",
+                                     RNA_int_get(op->ptr, "segments"), RNA_int_get(op->ptr, "ring_count"),
+                                     RNA_float_get(op->ptr, "size"), mat))
        {
                return OPERATOR_CANCELLED;
        }
@@ -580,7 +582,7 @@ static int add_primitive_icosphere_exec(bContext *C, wmOperator *op)
        me = obedit->data;
        em = me->edit_btmesh;
 
-       if (!EDBM_CallAndSelectOpf(
+       if (!EDBM_op_call_and_selectf(
                em, op, "vertout",
                "create_icosphere subdivisions=%i diameter=%f mat=%m4",
                RNA_int_get(op->ptr, "subdivisions"),