rename operators TFM_OT_* --> TRANSFORM_OT_*
[blender.git] / source / blender / editors / mesh / editmesh_mods.c
index 968bb30b0cd0d2a099587f7fcef45b986f889506..30dc61140979cdd2571b680bc39de60ea62d3c03 100644 (file)
@@ -53,7 +53,7 @@ editmesh_mods.c, UI level access, no geometry changes
 #include "DNA_view3d_types.h"
 
 #include "BLI_blenlib.h"
-#include "BLI_arithb.h"
+#include "BLI_math.h"
 #include "BLI_editVert.h"
 #include "BLI_rand.h"
 
@@ -82,6 +82,7 @@ editmesh_mods.c, UI level access, no geometry changes
 
 #include "RNA_access.h"
 #include "RNA_define.h"
+#include "RNA_enum_types.h"
 
 #include "ED_mesh.h"
 #include "ED_screen.h"
@@ -100,23 +101,45 @@ static int pupmenu() {return 0;}
 
 /* ****************************** MIRROR **************** */
 
-void EM_select_mirrored(Object *obedit, EditMesh *em)
+void EM_cache_x_mirror_vert(struct Object *ob, struct EditMesh *em)
 {
-       if(em->selectmode & SCE_SELECT_VERTEX) {
-               EditVert *eve, *v1;
-               
-               for(eve= em->verts.first; eve; eve= eve->next) {
-                       if(eve->f & SELECT) {
-                               v1= editmesh_get_x_mirror_vert(obedit, em, eve->co);
-                               if(v1) {
-                                       eve->f &= ~SELECT;
-                                       v1->f |= SELECT;
-                               }
+       EditVert *eve, *eve_mirror;
+
+       for(eve= em->verts.first; eve; eve= eve->next) {
+               eve->tmp.v= NULL;
+       }
+
+       for(eve= em->verts.first; eve; eve= eve->next) {
+               if(eve->tmp.v==NULL) {
+                       eve_mirror = editmesh_get_x_mirror_vert(ob, em, eve->co);
+                       if(eve_mirror) {
+                               eve->tmp.v= eve_mirror;
+                               eve_mirror->tmp.v = eve;
                        }
                }
        }
 }
 
+void EM_select_mirrored(Object *obedit, EditMesh *em, int extend)
+{
+
+       EditVert *eve;
+
+       EM_cache_x_mirror_vert(obedit, em);
+
+       for(eve= em->verts.first; eve; eve= eve->next) {
+               if(eve->f & SELECT && eve->tmp.v) {
+                       eve->tmp.v->f |= SELECT;
+
+                       if(extend==FALSE)
+                               eve->f &= ~SELECT;
+
+                       /* remove the interference */
+                       eve->tmp.v->tmp.v= eve->tmp.v= NULL;
+               }
+       }
+}
+
 void EM_automerge(Scene *scene, Object *obedit, int update)
 {
        Mesh *me= obedit ? obedit->data : NULL; /* can be NULL */
@@ -460,14 +483,17 @@ static void findnearestedge__doClosest(void *userData, EditEdge *eed, int x0, in
        struct { ViewContext vc; float mval[2]; int dist; EditEdge *closest; } *data = userData;
        float v1[2], v2[2];
        int distance;
-               
+
+       ED_view3d_local_clipping(data->vc.rv3d, data->vc.obedit->obmat); /* for local clipping lookups */
+
        v1[0] = x0;
        v1[1] = y0;
        v2[0] = x1;
        v2[1] = y1;
-               
-       distance= PdistVL2Dfl(data->mval, v1, v2);
-               
+
+       distance= dist_to_line_segment_v2(data->mval, v1, v2);
+
+
        if(eed->f & SELECT) distance+=5;
        if(distance < data->dist) {
                if(data->vc.rv3d->rflag & RV3D_CLIPPING) {
@@ -477,9 +503,8 @@ static void findnearestedge__doClosest(void *userData, EditEdge *eed, int x0, in
                        vec[0]= eed->v1->co[0] + labda*(eed->v2->co[0] - eed->v1->co[0]);
                        vec[1]= eed->v1->co[1] + labda*(eed->v2->co[1] - eed->v1->co[1]);
                        vec[2]= eed->v1->co[2] + labda*(eed->v2->co[2] - eed->v1->co[2]);
-                       Mat4MulVecfl(data->vc.obedit->obmat, vec);
 
-                       if(view3d_test_clipping(data->vc.rv3d, vec)==0) {
+                       if(view3d_test_clipping(data->vc.rv3d, vec, 1)==0) {
                                data->dist = distance;
                                data->closest = eed;
                        }
@@ -803,7 +828,7 @@ static int similar_face_select__internal(Scene *scene, EditMesh *em, int mode)
                                float angle;
                                for(efa= em->faces.first; efa; efa= efa->next) {
                                        if (!(efa->f & SELECT) && !efa->h) {
-                                               angle= RAD2DEG(VecAngle2(base_efa->n, efa->n));
+                                               angle= RAD2DEG(angle_v2v2(base_efa->n, efa->n));
                                                if (angle/180.0<=thresh) {
                                                        EM_select_face(efa, 1);
                                                        selcount++;
@@ -815,12 +840,12 @@ static int similar_face_select__internal(Scene *scene, EditMesh *em, int mode)
                                }
                        } else if (mode==SIMFACE_COPLANAR) { /* same planer */
                                float angle, base_dot, dot;
-                               base_dot= Inpf(base_efa->cent, base_efa->n);
+                               base_dot= dot_v3v3(base_efa->cent, base_efa->n);
                                for(efa= em->faces.first; efa; efa= efa->next) {
                                        if (!(efa->f & SELECT) && !efa->h) {
-                                               angle= RAD2DEG(VecAngle2(base_efa->n, efa->n));
+                                               angle= RAD2DEG(angle_v2v2(base_efa->n, efa->n));
                                                if (angle/180.0<=thresh) {
-                                                       dot=Inpf(efa->cent, base_efa->n);
+                                                       dot=dot_v3v3(efa->cent, base_efa->n);
                                                        if (fabs(base_dot-dot) <= thresh) {
                                                                EM_select_face(efa, 1);
                                                                selcount++;
@@ -894,7 +919,7 @@ static int similar_edge_select__internal(ToolSettings *ts, EditMesh *em, int mod
        if (mode==SIMEDGE_LENGTH) { /*store length*/
                for(eed= em->edges.first; eed; eed= eed->next) {
                        if (!eed->h) /* dont calc data for hidden edges*/
-                               eed->tmp.fp= VecLenf(eed->v1->co, eed->v2->co);
+                               eed->tmp.fp= len_v3v3(eed->v1->co, eed->v2->co);
                }
        } else if (mode==SIMEDGE_FACE) { /*store face users*/
                EditFace *efa;
@@ -937,7 +962,7 @@ static int similar_edge_select__internal(ToolSettings *ts, EditMesh *em, int mod
                                        else if (eed->f2==0) /* first access, assign the face */
                                                eed->tmp.f= efa;
                                        else if (eed->f2==1) /* second, we assign the angle*/
-                                               eed->tmp.fp= RAD2DEG(VecAngle2(eed->tmp.f->n, efa->n))/180;
+                                               eed->tmp.fp= RAD2DEG(angle_v2v2(eed->tmp.f->n, efa->n))/180;
                                        eed->f2++; /* f2==0 no face assigned. f2==1 one face found. f2==2 angle calculated.*/
                                }
                                j++;
@@ -963,11 +988,11 @@ static int similar_edge_select__internal(ToolSettings *ts, EditMesh *em, int mod
                                }
                        } else if (mode==SIMEDGE_DIR) { /* same direction */
                                float base_dir[3], dir[3], angle;
-                               VecSubf(base_dir, base_eed->v1->co, base_eed->v2->co);
+                               sub_v3_v3v3(base_dir, base_eed->v1->co, base_eed->v2->co);
                                for(eed= em->edges.first; eed; eed= eed->next) {
                                        if (!(eed->f & SELECT) && !eed->h) {
-                                               VecSubf(dir, eed->v1->co, eed->v2->co);
-                                               angle= RAD2DEG(VecAngle2(base_dir, dir));
+                                               sub_v3_v3v3(dir, eed->v1->co, eed->v2->co);
+                                               angle= RAD2DEG(angle_v2v2(base_dir, dir));
                                                
                                                if (angle>90) /* use the smallest angle between the edges */
                                                        angle= fabs(angle-180.0f);
@@ -1139,7 +1164,7 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op)
                                float angle;
                                for(eve= em->verts.first; eve; eve= eve->next) {
                                        if (!(eve->f & SELECT) && !eve->h) {
-                                               angle= RAD2DEG(VecAngle2(base_eve->no, eve->no));
+                                               angle= RAD2DEG(angle_v2v2(base_eve->no, eve->no));
                                                if (angle/180.0<=thresh) {
                                                        eve->f |= SELECT;
                                                        selcount++;
@@ -1366,34 +1391,34 @@ void EM_mesh_copy_edge(EditMesh *em, short type)
                break;
 
        case 3: /* copy length */
-               eed_len_act = VecLenf(eed_act->v1->co, eed_act->v2->co);
+               eed_len_act = len_v3v3(eed_act->v1->co, eed_act->v2->co);
                for(eed=em->edges.first; eed; eed=eed->next) {
                        if (eed->f & SELECT && eed != eed_act) {
 
-                               eed_len = VecLenf(eed->v1->co, eed->v2->co);
+                               eed_len = len_v3v3(eed->v1->co, eed->v2->co);
 
                                if (eed_len == eed_len_act) continue;
                                /* if this edge is zero length we cont do anything with it*/
                                if (eed_len == 0.0f) continue;
                                if (eed_len_act == 0.0f) {
-                                       VecAddf(vec_mid, eed->v1->co, eed->v2->co);
-                                       VecMulf(vec_mid, 0.5);
+                                       add_v3_v3v3(vec_mid, eed->v1->co, eed->v2->co);
+                                       mul_v3_fl(vec_mid, 0.5);
                                        VECCOPY(eed->v1->co, vec_mid);
                                        VECCOPY(eed->v2->co, vec_mid);
                                } else {
                                        /* copy the edge length */
-                                       VecAddf(vec_mid, eed->v1->co, eed->v2->co);
-                                       VecMulf(vec_mid, 0.5);
+                                       add_v3_v3v3(vec_mid, eed->v1->co, eed->v2->co);
+                                       mul_v3_fl(vec_mid, 0.5);
 
                                        /* SCALE 1 */
-                                       VecSubf(vec, eed->v1->co, vec_mid);
-                                       VecMulf(vec, eed_len_act/eed_len);
-                                       VecAddf(eed->v1->co, vec, vec_mid);
+                                       sub_v3_v3v3(vec, eed->v1->co, vec_mid);
+                                       mul_v3_fl(vec, eed_len_act/eed_len);
+                                       add_v3_v3v3(eed->v1->co, vec, vec_mid);
 
                                        /* SCALE 2 */
-                                       VecSubf(vec, eed->v2->co, vec_mid);
-                                       VecMulf(vec, eed_len_act/eed_len);
-                                       VecAddf(eed->v2->co, vec, vec_mid);
+                                       sub_v3_v3v3(vec, eed->v2->co, vec_mid);
+                                       mul_v3_fl(vec, eed_len_act/eed_len);
+                                       add_v3_v3v3(eed->v2->co, vec, vec_mid);
                                }
                                change = 1;
                        }
@@ -2198,7 +2223,7 @@ void MESH_OT_select_shortest_path(wmOperatorType *ot)
 
 /* here actual select happens */
 /* gets called via generic mouse select operator */
-void mouse_mesh(bContext *C, short mval[2], short extend)
+int mouse_mesh(bContext *C, short mval[2], short extend)
 {
        ViewContext vc;
        EditVert *eve;
@@ -2257,10 +2282,13 @@ void mouse_mesh(bContext *C, short mval[2], short extend)
                        vc.em->mat_nr= efa->mat_nr;
 //                     BIF_preview_changed(ID_MA);
                }
-       }
 
-       WM_event_add_notifier(C, NC_GEOM|ND_SELECT, vc.obedit->data);
+               WM_event_add_notifier(C, NC_GEOM|ND_SELECT, vc.obedit->data);
+
+               return 1;
+       }
        
+       return 0;
 }
 
 /* *********** select linked ************* */
@@ -2378,6 +2406,15 @@ static int select_linked_limited_invoke(ViewContext *vc, short all, short sel)
 #undef is_face_tag
 #undef face_tag
 
+static void linked_limit_default(bContext *C, wmOperator *op) {
+       if(!RNA_property_is_set(op->ptr, "limit")) {
+               Object *obedit= CTX_data_edit_object(C);
+               EditMesh *em= BKE_mesh_get_editmesh(obedit->data);
+               if(em->selectmode == SCE_SELECT_FACE)
+                       RNA_boolean_set(op->ptr, "limit", TRUE);
+       }
+}
+
 static int select_linked_pick_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        Object *obedit= CTX_data_edit_object(C);
@@ -2387,8 +2424,12 @@ static int select_linked_pick_invoke(bContext *C, wmOperator *op, wmEvent *event
        EditFace *efa;
        short done=1, toggle=0;
        int sel= !RNA_boolean_get(op->ptr, "deselect");
-       int limit= RNA_boolean_get(op->ptr, "limit");
+       int limit;
        
+       linked_limit_default(C, op);
+
+       limit = RNA_boolean_get(op->ptr, "limit");
+
        /* unified_finednearest needs ogl */
        view3d_operator_needs_opengl(C);
        
@@ -2549,6 +2590,12 @@ static int select_linked_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;       
 }
 
+static int select_linked_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+       linked_limit_default(C, op);
+       return select_linked_exec(C, op);
+}
+
 void MESH_OT_select_linked(wmOperatorType *ot)
 {
        /* identifiers */
@@ -2558,6 +2605,7 @@ void MESH_OT_select_linked(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= select_linked_exec;
+       ot->invoke= select_linked_invoke;
        ot->poll= ED_operator_editmesh;
        
        /* flags */
@@ -2825,6 +2873,39 @@ void MESH_OT_select_by_number_vertices(wmOperatorType *ot)
        RNA_def_enum(ot->srna, "type", type_items, 3, "Type", "Type of elements to select.");
 }
 
+
+int select_mirror_exec(bContext *C, wmOperator *op)
+{
+       Object *obedit= CTX_data_edit_object(C);
+       EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
+
+       int extend= RNA_boolean_get(op->ptr, "extend");
+
+       EM_select_mirrored(obedit, em, extend);
+
+       WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
+
+       return OPERATOR_FINISHED;
+}
+
+void MESH_OT_select_mirror(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Select Mirror";
+       ot->description= "Select mesh items at mirrored locations.";
+       ot->idname= "MESH_OT_select_mirror";
+
+       /* api callbacks */
+       ot->exec= select_mirror_exec;
+       ot->poll= ED_operator_editmesh;
+
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       /* props */
+       RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the existing selection");
+}
+
 static int select_sharp_edges_exec(bContext *C, wmOperator *op)
 {
        /* Find edges that have exactly two neighboring faces,
@@ -3291,12 +3372,31 @@ void EM_select_all(EditMesh *em)
        EM_set_flag_all(em, SELECT);
 }
 
-static int toggle_select_all_exec(bContext *C, wmOperator *op)
+void EM_deselect_all(EditMesh *em)
+{
+       EM_clear_flag_all(em, SELECT);
+}
+
+static int select_all_exec(bContext *C, wmOperator *op)
 {
        Object *obedit= CTX_data_edit_object(C);
        EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
+       int action = RNA_enum_get(op->ptr, "action");
        
-       EM_toggle_select_all(em);
+       switch (action) {
+       case SEL_TOGGLE:
+               EM_toggle_select_all(em);
+               break;
+       case SEL_SELECT:
+               EM_select_all(em);
+               break;
+       case SEL_DESELECT:
+               EM_deselect_all(em);
+               break;
+       case SEL_INVERT:
+               EM_select_swap(em);
+               break;
+       }
        
        WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);      
        BKE_mesh_end_editmesh(obedit->data, em);
@@ -3304,19 +3404,21 @@ static int toggle_select_all_exec(bContext *C, wmOperator *op)
        return OPERATOR_FINISHED;
 }
 
-void MESH_OT_select_all_toggle(wmOperatorType *ot)
+void MESH_OT_select_all(wmOperatorType *ot)
 {
        /* identifiers */
        ot->name= "Select/Deselect All";
-       ot->description= "(de)select all vertices, edges or faces.";
-       ot->idname= "MESH_OT_select_all_toggle";
+       ot->description= "Change selection of all vertices, edges or faces.";
+       ot->idname= "MESH_OT_select_all";
        
        /* api callbacks */
-       ot->exec= toggle_select_all_exec;
+       ot->exec= select_all_exec;
        ot->poll= ED_operator_editmesh;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       WM_operator_properties_select_all(ot);
 }
 
 /* ******************** **************** */
@@ -3480,14 +3582,11 @@ void MESH_OT_select_less(wmOperatorType *ot)
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
 }
 
-static void selectrandom_mesh(EditMesh *em, float perc) /* randomly selects a user-set % of vertices/edges/faces */
+static void selectrandom_mesh(EditMesh *em, float randfac) /* randomly selects a user-set % of vertices/edges/faces */
 {
        EditVert *eve;
        EditEdge *eed;
        EditFace *efa;
-       float randfac= perc;
-       /* Get the percentage of vertices to randomly select as 'randfac' */
-// XXX if(button(&randfac,0, 100,"Percentage:")==0) return;
 
        BLI_srand( BLI_rand() ); /* random seed */
        
@@ -3527,7 +3626,10 @@ static int mesh_select_random_exec(bContext *C, wmOperator *op)
        Object *obedit= CTX_data_edit_object(C);
        EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
        
-       selectrandom_mesh(em, RNA_float_get(op->ptr,"percent"));
+       if(!RNA_boolean_get(op->ptr, "extend"))
+               EM_deselect_all(em);
+       
+       selectrandom_mesh(em, RNA_float_get(op->ptr, "percent")/100.0f);
                
        WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
        
@@ -3544,14 +3646,14 @@ void MESH_OT_select_random(wmOperatorType *ot)
 
        /* api callbacks */
        ot->exec= mesh_select_random_exec;
-       ot->invoke= WM_operator_props_popup;
        ot->poll= ED_operator_editmesh;
 
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* props */
-       RNA_def_float_percentage(ot->srna, "percent", 50.0f, 0.0f, 100.0f, "Percent", "Percentage of vertices to select randomly.", 0.0001f, 1.0f);
+       RNA_def_float_percentage(ot->srna, "percent", 50.f, 0.0f, 100.0f, "Percent", "Percentage of elements to select randomly.", 0.f, 100.0f);
+       RNA_def_boolean(ot->srna, "extend", FALSE, "Extend Selection", "Extend selection instead of deselecting everything first.");
 }
 
 void EM_select_by_material(EditMesh *em, int index) 
@@ -3583,21 +3685,11 @@ void EM_deselect_by_material(EditMesh *em, int index)
 static void mesh_selection_type(ToolSettings *ts, EditMesh *em, int val)
 {
        if(val>0) {
-               if(val==1) { 
-                       em->selectmode= SCE_SELECT_VERTEX;
-                       EM_selectmode_set(em);
-               }
-               else if(val==2) {
-                       //if(ctrl) EM_convertsel(em, em->selectmode, SCE_SELECT_EDGE);
-                       em->selectmode= SCE_SELECT_EDGE;
-                       EM_selectmode_set(em);
-               }
-               
-               else{
-                       //if((ctrl)) EM_convertsel(em, em->selectmode, SCE_SELECT_FACE);
-                       em->selectmode= SCE_SELECT_FACE;
-                       EM_selectmode_set(em);
-               }
+               //if(ctrl) EM_convertsel(em, em->selectmode, SCE_SELECT_EDGE);
+               //if((ctrl)) EM_convertsel(em, em->selectmode, SCE_SELECT_FACE);
+
+               em->selectmode= val;
+               EM_selectmode_set(em);
                
                /* note, em stores selectmode to be able to pass it on everywhere without scene,
                   this is only until all select modes and toolsettings are settled more */
@@ -3606,13 +3698,6 @@ static void mesh_selection_type(ToolSettings *ts, EditMesh *em, int val)
        }
 }
 
-static EnumPropertyItem prop_mesh_edit_types[] = {
-       {1, "VERT", ICON_VERTEXSEL, "Vertices", ""},
-       {2, "EDGE", ICON_EDGESEL, "Edges", ""},
-       {3, "FACE", ICON_FACESEL, "Faces", ""},
-       {0, NULL, 0, NULL, NULL}
-};
-
 static int mesh_selection_type_exec(bContext *C, wmOperator *op)
 {              
        ToolSettings *ts= CTX_data_tool_settings(C);
@@ -3622,6 +3707,7 @@ static int mesh_selection_type_exec(bContext *C, wmOperator *op)
        mesh_selection_type(ts, em, RNA_enum_get(op->ptr,"type"));
 
        WM_event_add_notifier(C, NC_GEOM|ND_SELECT, obedit->data);
+       WM_event_add_notifier(C, NC_SCENE|ND_MODE, NULL); /* header redraw */
        
        BKE_mesh_end_editmesh(obedit->data, em);
        return OPERATOR_FINISHED;
@@ -3641,10 +3727,10 @@ void MESH_OT_selection_type(wmOperatorType *ot)
        ot->poll= ED_operator_editmesh;
        
        /* flags */
-       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+       ot->flag= OPTYPE_UNDO;
        
        /* props */
-       RNA_def_enum(ot->srna, "type", prop_mesh_edit_types, 0, "Type", "Set the mesh selection type");
+       RNA_def_enum(ot->srna, "type", mesh_select_mode_items, 0, "Type", "Set the mesh selection type");
        
 }
 /* ************************* SEAMS AND EDGES **************** */
@@ -3818,7 +3904,7 @@ void righthandfaces(EditMesh *em, int select)     /* makes faces righthand turning *
 
                while(efa) {
                        if(efa->f1) {
-                               CalcCent3f(cent, efa->v1->co, efa->v2->co, efa->v3->co);
+                               cent_tri_v3(cent, efa->v1->co, efa->v2->co, efa->v3->co);
                                cent[0]= cent[0]*cent[0] + cent[1]*cent[1] + cent[2]*cent[2];
                                
                                if(cent[0]>maxx) {
@@ -3827,7 +3913,7 @@ void righthandfaces(EditMesh *em, int select)     /* makes faces righthand turning *
                                        tria_nr= 0;
                                }
                                if(efa->v4) {
-                                       CalcCent3f(cent, efa->v1->co, efa->v3->co, efa->v4->co);
+                                       cent_tri_v3(cent, efa->v1->co, efa->v3->co, efa->v4->co);
                                        cent[0]= cent[0]*cent[0] + cent[1]*cent[1] + cent[2]*cent[2];
                                        
                                        if(cent[0]>maxx) {
@@ -3846,11 +3932,11 @@ void righthandfaces(EditMesh *em, int select)   /* makes faces righthand turning *
                /* set first face correct: calc normal */
                
                if(tria_nr==1) {
-                       CalcNormFloat(startvl->v1->co, startvl->v3->co, startvl->v4->co, nor);
-                       CalcCent3f(cent, startvl->v1->co, startvl->v3->co, startvl->v4->co);
+                       normal_tri_v3( nor,startvl->v1->co, startvl->v3->co, startvl->v4->co);
+                       cent_tri_v3(cent, startvl->v1->co, startvl->v3->co, startvl->v4->co);
                } else {
-                       CalcNormFloat(startvl->v1->co, startvl->v2->co, startvl->v3->co, nor);
-                       CalcCent3f(cent, startvl->v1->co, startvl->v2->co, startvl->v3->co);
+                       normal_tri_v3( nor,startvl->v1->co, startvl->v2->co, startvl->v3->co);
+                       cent_tri_v3(cent, startvl->v1->co, startvl->v2->co, startvl->v3->co);
                }
                /* first normal is oriented this way or the other */
                if(select) {
@@ -4060,9 +4146,9 @@ void faceselect_align_view_to_selected(View3D *v3d, RegionView3D *rv3d, Mesh *me
                        v3= me->mvert[mf->v3].co;
                        if (mf->v4) {
                                float *v4= me->mvert[mf->v4].co;
-                               CalcNormFloat4(v1, v2, v3, v4, fno);
+                               normal_quad_v3( fno,v1, v2, v3, v4);
                        } else {
-                               CalcNormFloat(v1, v2, v3, fno);
+                               normal_tri_v3( fno,v1, v2, v3);
                        }
 
                        norm[0]+= fno[0];
@@ -4085,18 +4171,18 @@ static void face_getnormal_obspace(Object *obedit, EditFace *efa, float *fno)
        float vec[4][3];
        
        VECCOPY(vec[0], efa->v1->co);
-       Mat4Mul3Vecfl(obedit->obmat, vec[0]);
+       mul_mat3_m4_v3(obedit->obmat, vec[0]);
        VECCOPY(vec[1], efa->v2->co);
-       Mat4Mul3Vecfl(obedit->obmat, vec[1]);
+       mul_mat3_m4_v3(obedit->obmat, vec[1]);
        VECCOPY(vec[2], efa->v3->co);
-       Mat4Mul3Vecfl(obedit->obmat, vec[2]);
+       mul_mat3_m4_v3(obedit->obmat, vec[2]);
        if(efa->v4) {
                VECCOPY(vec[3], efa->v4->co);
-               Mat4Mul3Vecfl(obedit->obmat, vec[3]);
+               mul_mat3_m4_v3(obedit->obmat, vec[3]);
                
-               CalcNormFloat4(vec[0], vec[1], vec[2], vec[3], fno);
+               normal_quad_v3( fno,vec[0], vec[1], vec[2], vec[3]);
        }
-       else CalcNormFloat(vec[0], vec[1], vec[2], fno);
+       else normal_tri_v3( fno,vec[0], vec[1], vec[2]);
 }
 
 
@@ -4132,7 +4218,7 @@ void editmesh_align_view_to_selected(Object *obedit, EditMesh *em, wmOperator *o
                        if (eve->f & SELECT) {
                                if (leve) {
                                        float tno[3];
-                                       CalcNormFloat(cent, leve->co, eve->co, tno);
+                                       normal_tri_v3( tno,cent, leve->co, eve->co);
                                        
                                                /* XXX, fixme, should be flipped intp a 
                                                 * consistent direction. -zr
@@ -4145,7 +4231,7 @@ void editmesh_align_view_to_selected(Object *obedit, EditMesh *em, wmOperator *o
                        }
                }
 
-               Mat4Mul3Vecfl(obedit->obmat, norm);
+               mul_mat3_m4_v3(obedit->obmat, norm);
                view3d_align_axis_to_vector(v3d, rv3d, axis, norm);
        } 
        else if (nselverts==2) { /* Align view to edge (or 2 verts) */ 
@@ -4162,7 +4248,7 @@ void editmesh_align_view_to_selected(Object *obedit, EditMesh *em, wmOperator *o
                                leve= eve;
                        }
                }
-               Mat4Mul3Vecfl(obedit->obmat, norm);
+               mul_mat3_m4_v3(obedit->obmat, norm);
                view3d_align_axis_to_vector(v3d, rv3d, axis, norm);
        } 
        else if (nselverts==1) { /* Align view to vert normal */ 
@@ -4176,7 +4262,7 @@ void editmesh_align_view_to_selected(Object *obedit, EditMesh *em, wmOperator *o
                                break; /* we know this is the only selected vert, so no need to keep looking */
                        }
                }
-               Mat4Mul3Vecfl(obedit->obmat, norm);
+               mul_mat3_m4_v3(obedit->obmat, norm);
                view3d_align_axis_to_vector(v3d, rv3d, axis, norm);
        }
 } 
@@ -4185,7 +4271,6 @@ void editmesh_align_view_to_selected(Object *obedit, EditMesh *em, wmOperator *o
 
 static int smooth_vertex(bContext *C, wmOperator *op)
 {
-       ToolSettings *ts= CTX_data_tool_settings(C);
        Object *obedit= CTX_data_edit_object(C);
        EditMesh *em= BKE_mesh_get_editmesh(((Mesh *)obedit->data));
        EditVert *eve, *eve_mir = NULL;
@@ -4258,11 +4343,11 @@ static int smooth_vertex(bContext *C, wmOperator *op)
                        
                        if((eed->v1->f & SELECT) && eed->v1->f1<255) {
                                eed->v1->f1++;
-                               VecAddf(eed->v1->tmp.p, eed->v1->tmp.p, fvec);
+                               add_v3_v3v3(eed->v1->tmp.p, eed->v1->tmp.p, fvec);
                        }
                        if((eed->v2->f & SELECT) && eed->v2->f1<255) {
                                eed->v2->f1++;
-                               VecAddf(eed->v2->tmp.p, eed->v2->tmp.p, fvec);
+                               add_v3_v3v3(eed->v2->tmp.p, eed->v2->tmp.p, fvec);
                        }
                }
                eed= eed->next;
@@ -4381,7 +4466,7 @@ void vertexnoise(Object *obedit, EditMesh *em)
                                vec[1]= 0.2*(b2-BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1]+ofs, eve->co[2]));
                                vec[2]= 0.2*(b2-BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1], eve->co[2]+ofs));
                                
-                               VecAddf(eve->co, eve->co, vec);
+                               add_v3_v3v3(eve->co, eve->co, vec);
                        }
                        else {
                                float tin, dum;
@@ -4412,8 +4497,8 @@ void flipface(EditMesh *em, EditFace *efa)
                EM_data_interp_from_faces(em, efa, NULL, efa, 0, 2, 1, 3);
        }
 
-       if(efa->v4) CalcNormFloat4(efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co, efa->n);
-       else CalcNormFloat(efa->v1->co, efa->v2->co, efa->v3->co, efa->n);
+       if(efa->v4) normal_quad_v3( efa->n,efa->v1->co, efa->v2->co, efa->v3->co, efa->v4->co);
+       else normal_tri_v3( efa->n,efa->v1->co, efa->v2->co, efa->v3->co);
 }