VecAngle3_2D, VecAngle2 and VecAngle3 returned degrees, in arithb.c degrees are most...
authorCampbell Barton <ideasman42@gmail.com>
Fri, 18 Sep 2009 15:47:00 +0000 (15:47 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 18 Sep 2009 15:47:00 +0000 (15:47 +0000)
- These now return radians
- added macro RAD2DEG(rad)
- renamed VecAngle3_2D to Vec2Angle3 since Vec2* is used in arithb.c for 2D vector functions.

source/blender/blenkernel/intern/curve.c
source/blender/blenlib/BLI_arithb.h
source/blender/blenlib/intern/arithb.c
source/blender/editors/armature/editarmature_sketch.c
source/blender/editors/armature/meshlaplacian.c
source/blender/editors/mesh/editmesh_mods.c
source/blender/editors/mesh/editmesh_tools.c
source/blender/editors/space_view3d/drawobject.c
source/blender/editors/uvedit/uvedit_draw.c

index ea3fce9ffaf06f966510b93a12f2b50ba24e1578..2ce877bd8472f8cd6812c401ef7edaf20e587ce6 100644 (file)
@@ -1616,7 +1616,7 @@ static void bevel_list_flip_tangents(BevList *bl)
 
        nr= bl->nr;
        while(nr--) {
-               if(VecAngle2(bevp0->tan, bevp1->tan) > 90)
+               if(RAD2DEG(VecAngle2(bevp0->tan, bevp1->tan)) > 90)
                        VecNegf(bevp1->tan);
 
                bevp0= bevp1;
index c2d707f60f09cbf90214b6e5d329ac1597a2391b..623a9afeb7389420a04731e3177dbaf4e005ec9f 100644 (file)
@@ -401,7 +401,7 @@ float VecAngle2(float *v1, float *v2);
 float VecAngle3(float *v1, float *v2, float *v3);
 float NormalizedVecAngle2(float *v1, float *v2);
 
-float VecAngle3_2D(float *v1, float *v2, float *v3);
+float Vec2Angle3(float *v1, float *v2, float *v3);
 float NormalizedVecAngle2_2D(float *v1, float *v2);
        
 void NormalShortToFloat(float *out, short *in);
@@ -454,6 +454,8 @@ void i_window(
 #define BLI_CS_REC709  1
 #define BLI_CS_CIE             2
 
+#define RAD2DEG(_rad) ((_rad)*(180.0/M_PI))
+
 void hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b);
 void hex_to_rgb(char *hexcol, float *r, float *g, float *b);
 void rgb_to_yuv(float r, float g, float b, float *ly, float *lu, float *lv);
index b7f56e6ca1cd37bc8deac650fcbd987eedb0a47c..b10051b056a39bcd1f9a92e53776eb0034d916ee 100644 (file)
@@ -3548,10 +3548,10 @@ float VecAngle3(float *v1, float *v2, float *v3)
        Normalize(vec1);
        Normalize(vec2);
 
-       return NormalizedVecAngle2(vec1, vec2) * (float)(180.0/M_PI);
+       return NormalizedVecAngle2(vec1, vec2);
 }
 
-float VecAngle3_2D(float *v1, float *v2, float *v3)
+float Vec2Angle3(float *v1, float *v2, float *v3)
 {
        float vec1[2], vec2[2];
 
@@ -3564,7 +3564,7 @@ float VecAngle3_2D(float *v1, float *v2, float *v3)
        Normalize2(vec1);
        Normalize2(vec2);
 
-       return NormalizedVecAngle2_2D(vec1, vec2) * (float)(180.0/M_PI);
+       return NormalizedVecAngle2_2D(vec1, vec2);
 }
 
 /* Return the shortest angle in degrees between the 2 vectors */
@@ -3577,7 +3577,7 @@ float VecAngle2(float *v1, float *v2)
        Normalize(vec1);
        Normalize(vec2);
 
-       return NormalizedVecAngle2(vec1, vec2)* (float)(180.0/M_PI);
+       return NormalizedVecAngle2(vec1, vec2);
 }
 
 float NormalizedVecAngle2(float *v1, float *v2)
index 1e416d9c31d4e74cc64290f1355b39f6e428362f..7f2f2a3410ce5093afdc72ec49c3061f23dbc595 100644 (file)
@@ -1814,7 +1814,7 @@ int sk_detectTrimGesture(bContext *C, SK_Gesture *gest, SK_Sketch *sketch)
                VecSubf(s1, gest->segments->points[1].p, gest->segments->points[0].p);
                VecSubf(s2, gest->segments->points[2].p, gest->segments->points[1].p);
 
-               angle = VecAngle2(s1, s2);
+               angle = RAD2DEG(VecAngle2(s1, s2));
 
                if (angle > 60 && angle < 120)
                {
@@ -1932,7 +1932,7 @@ int sk_detectDeleteGesture(bContext *C, SK_Gesture *gest, SK_Sketch *sketch)
                VecSubf(s1, gest->segments->points[1].p, gest->segments->points[0].p);
                VecSubf(s2, gest->segments->points[2].p, gest->segments->points[1].p);
 
-               angle = VecAngle2(s1, s2);
+               angle = RAD2DEG(VecAngle2(s1, s2));
 
                if (angle > 120)
                {
@@ -2064,7 +2064,7 @@ int sk_detectReverseGesture(bContext *C, SK_Gesture *gest, SK_Sketch *sketch)
                                        VecSubf(end_v, sk_lastStrokePoint(gest->stk)->p, isect->p);
                                }
 
-                               angle = VecAngle2(start_v, end_v);
+                               angle = RAD2DEG(VecAngle2(start_v, end_v));
 
                                if (angle > 120)
                                {
index a6c94bee5b1a216373a8bdbbb42b172deded9d87..81e67c4d46ef642c2bceb5f604b6611b6d7f576f 100644 (file)
@@ -176,9 +176,9 @@ static void laplacian_triangle_area(LaplacianSystem *sys, int i1, int i2, int i3
        t2= cotan_weight(v2, v3, v1);
        t3= cotan_weight(v3, v1, v2);
 
-       if(VecAngle3(v2, v1, v3) > 90) obtuse= 1;
-       else if(VecAngle3(v1, v2, v3) > 90) obtuse= 2;
-       else if(VecAngle3(v1, v3, v2) > 90) obtuse= 3;
+       if(RAD2DEG(VecAngle3(v2, v1, v3)) > 90) obtuse= 1;
+       else if(RAD2DEG(VecAngle3(v1, v2, v3)) > 90) obtuse= 2;
+       else if(RAD2DEG(VecAngle3(v1, v3, v2)) > 90) obtuse= 3;
 
        if (obtuse > 0) {
                area= AreaT3Dfl(v1, v2, v3);
index 7301901aff59664b491c9f9670a62edc3cc55855..09ea9088a166d85b57762306d871caff7db008b3 100644 (file)
@@ -761,7 +761,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= VecAngle2(base_efa->n, efa->n);
+                                               angle= RAD2DEG(VecAngle2(base_efa->n, efa->n));
                                                if (angle/180.0<=thresh) {
                                                        EM_select_face(efa, 1);
                                                        selcount++;
@@ -776,7 +776,7 @@ static int similar_face_select__internal(Scene *scene, EditMesh *em, int mode)
                                base_dot= Inpf(base_efa->cent, base_efa->n);
                                for(efa= em->faces.first; efa; efa= efa->next) {
                                        if (!(efa->f & SELECT) && !efa->h) {
-                                               angle= VecAngle2(base_efa->n, efa->n);
+                                               angle= RAD2DEG(VecAngle2(base_efa->n, efa->n));
                                                if (angle/180.0<=thresh) {
                                                        dot=Inpf(efa->cent, base_efa->n);
                                                        if (fabs(base_dot-dot) <= thresh) {
@@ -916,7 +916,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= VecAngle2(eed->tmp.f->n, efa->n)/180;
+                                               eed->tmp.fp= RAD2DEG(VecAngle2(eed->tmp.f->n, efa->n))/180;
                                        eed->f2++; /* f2==0 no face assigned. f2==1 one face found. f2==2 angle calculated.*/
                                }
                                j++;
@@ -946,7 +946,7 @@ static int similar_edge_select__internal(ToolSettings *ts, EditMesh *em, int mod
                                for(eed= em->edges.first; eed; eed= eed->next) {
                                        if (!(eed->f & SELECT) && !eed->h) {
                                                VecSubf(dir, eed->v1->co, eed->v2->co);
-                                               angle= VecAngle2(base_dir, dir);
+                                               angle= RAD2DEG(VecAngle2(base_dir, dir));
                                                
                                                if (angle>90) /* use the smallest angle between the edges */
                                                        angle= fabs(angle-180.0f);
@@ -1137,7 +1137,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= VecAngle2(base_eve->no, eve->no);
+                                               angle= RAD2DEG(VecAngle2(base_eve->no, eve->no));
                                                if (angle/180.0<=thresh) {
                                                        eve->f |= SELECT;
                                                        selcount++;
index 1d2b97b3f2947d81022e1492947d92b848fbb1fc..46b941f70dfe92cf235c1cfaa3200511ee71857c 100644 (file)
@@ -3121,13 +3121,13 @@ static float measure_facepair(EditVert *v1, EditVert *v2, EditVert *v3, EditVert
        CalcNormFloat(v1->co, v3->co, v4->co, noA2);
 
        if(noA1[0] == noA2[0] && noA1[1] == noA2[1] && noA1[2] == noA2[2]) normalADiff = 0.0;
-       else normalADiff = VecAngle2(noA1, noA2);
+       else normalADiff = RAD2DEG(VecAngle2(noA1, noA2));
                //if(!normalADiff) normalADiff = 179;
        CalcNormFloat(v2->co, v3->co, v4->co, noB1);
        CalcNormFloat(v4->co, v1->co, v2->co, noB2);
 
        if(noB1[0] == noB2[0] && noB1[1] == noB2[1] && noB1[2] == noB2[2]) normalBDiff = 0.0;
-       else normalBDiff = VecAngle2(noB1, noB2);
+       else normalBDiff = RAD2DEG(VecAngle2(noB1, noB2));
                //if(!normalBDiff) normalBDiff = 179;
 
        measure += (normalADiff/360) + (normalBDiff/360);
@@ -3142,10 +3142,10 @@ static float measure_facepair(EditVert *v1, EditVert *v2, EditVert *v3, EditVert
        diff = 0.0;
 
        diff = (
-               fabs(VecAngle2(edgeVec1, edgeVec2) - 90) +
-               fabs(VecAngle2(edgeVec2, edgeVec3) - 90) +
-               fabs(VecAngle2(edgeVec3, edgeVec4) - 90) +
-               fabs(VecAngle2(edgeVec4, edgeVec1) - 90)) / 360;
+               fabs(RAD2DEG(VecAngle2(edgeVec1, edgeVec2)) - 90) +
+               fabs(RAD2DEG(VecAngle2(edgeVec2, edgeVec3)) - 90) +
+               fabs(RAD2DEG(VecAngle2(edgeVec3, edgeVec4)) - 90) +
+               fabs(RAD2DEG(VecAngle2(edgeVec4, edgeVec1)) - 90)) / 360;
        if(!diff) return 0.0;
 
        measure +=  diff;
index 3212d5cee89a34e19edb7ddd3ac5645a387c9657..b8852486dea401ee1633281268ac1aafb0ad882b 100644 (file)
@@ -1991,29 +1991,29 @@ static void draw_em_measure_stats(View3D *v3d, RegionView3D *rv3d, Object *ob, E
                                
                        if( (e4->f & e1->f & SELECT) || (G.moving && (efa->v1->f & SELECT)) ) {
                                /* Vec 1 */
-                               sprintf(val,"%.3f", VecAngle3(v4, v1, v2));
+                               sprintf(val,"%.3f", RAD2DEG(VecAngle3(v4, v1, v2)));
                                VecLerpf(fvec, efa->cent, efa->v1->co, 0.8f);
                                view3d_object_text_draw_add(efa->cent[0], efa->cent[1], efa->cent[2], val, 0);
                        }
                        if( (e1->f & e2->f & SELECT) || (G.moving && (efa->v2->f & SELECT)) ) {
                                /* Vec 2 */
-                               sprintf(val,"%.3f", VecAngle3(v1, v2, v3));
+                               sprintf(val,"%.3f", RAD2DEG(VecAngle3(v1, v2, v3)));
                                VecLerpf(fvec, efa->cent, efa->v2->co, 0.8f);
                                view3d_object_text_draw_add(fvec[0], fvec[1], fvec[2], val, 0);
                        }
                        if( (e2->f & e3->f & SELECT) || (G.moving && (efa->v3->f & SELECT)) ) {
                                /* Vec 3 */
                                if(efa->v4) 
-                                       sprintf(val,"%.3f", VecAngle3(v2, v3, v4));
+                                       sprintf(val,"%.3f", RAD2DEG(VecAngle3(v2, v3, v4)));
                                else
-                                       sprintf(val,"%.3f", VecAngle3(v2, v3, v1));
+                                       sprintf(val,"%.3f", RAD2DEG(VecAngle3(v2, v3, v1)));
                                VecLerpf(fvec, efa->cent, efa->v3->co, 0.8f);
                                view3d_object_text_draw_add(fvec[0], fvec[1], fvec[2], val, 0);
                        }
                                /* Vec 4 */
                        if(efa->v4) {
                                if( (e3->f & e4->f & SELECT) || (G.moving && (efa->v4->f & SELECT)) ) {
-                                       sprintf(val,"%.3f", VecAngle3(v3, v4, v1));
+                                       sprintf(val,"%.3f", RAD2DEG(VecAngle3(v3, v4, v1)));
                                        VecLerpf(fvec, efa->cent, efa->v4->co, 0.8f);
                                        view3d_object_text_draw_add(fvec[0], fvec[1], fvec[2], val, 0);
                                }
index a58ee9772e9fcbdfcf24a35a5d8f5a96a3f6414b..fbd12007c16a0ac7fa19346bdefce0ae06b8305d 100644 (file)
@@ -251,17 +251,17 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, EditMesh *em, MTFac
                                        if(efa->v4) {
                                                
 #if 0                                          /* Simple but slow, better reuse normalized vectors */
-                                               uvang1 = VecAngle3_2D(tf_uv[3], tf_uv[0], tf_uv[1]);
-                                               ang1 = VecAngle3(efa->v4->co, efa->v1->co, efa->v2->co);
+                                               uvang1 = RAD2DEG(Vec2Angle3(tf_uv[3], tf_uv[0], tf_uv[1]));
+                                               ang1 = RAD2DEG(VecAngle3(efa->v4->co, efa->v1->co, efa->v2->co));
                                                
-                                               uvang2 = VecAngle3_2D(tf_uv[0], tf_uv[1], tf_uv[2]);
-                                               ang2 = VecAngle3(efa->v1->co, efa->v2->co, efa->v3->co);
+                                               uvang2 = RAD2DEG(Vec2Angle3(tf_uv[0], tf_uv[1], tf_uv[2]));
+                                               ang2 = RAD2DEG(VecAngle3(efa->v1->co, efa->v2->co, efa->v3->co));
                                                
-                                               uvang3 = VecAngle3_2D(tf_uv[1], tf_uv[2], tf_uv[3]);
-                                               ang3 = VecAngle3(efa->v2->co, efa->v3->co, efa->v4->co);
+                                               uvang3 = RAD2DEG(Vec2Angle3(tf_uv[1], tf_uv[2], tf_uv[3]));
+                                               ang3 = RAD2DEG(VecAngle3(efa->v2->co, efa->v3->co, efa->v4->co));
                                                
-                                               uvang4 = VecAngle3_2D(tf_uv[2], tf_uv[3], tf_uv[0]);
-                                               ang4 = VecAngle3(efa->v3->co, efa->v4->co, efa->v1->co);
+                                               uvang4 = RAD2DEG(Vec2Angle3(tf_uv[2], tf_uv[3], tf_uv[0]));
+                                               ang4 = RAD2DEG(VecAngle3(efa->v3->co, efa->v4->co, efa->v1->co));
 #endif
                                                
                                                /* uv angles */
@@ -315,14 +315,14 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, EditMesh *em, MTFac
                                        }
                                        else {
 #if 0                                          /* Simple but slow, better reuse normalized vectors */
-                                               uvang1 = VecAngle3_2D(tf_uv[2], tf_uv[0], tf_uv[1]);
-                                               ang1 = VecAngle3(efa->v3->co, efa->v1->co, efa->v2->co);
+                                               uvang1 = RAD2DEG(Vec2Angle3(tf_uv[2], tf_uv[0], tf_uv[1]));
+                                               ang1 = RAD2DEG(VecAngle3(efa->v3->co, efa->v1->co, efa->v2->co));
                                                
-                                               uvang2 = VecAngle3_2D(tf_uv[0], tf_uv[1], tf_uv[2]);
-                                               ang2 = VecAngle3(efa->v1->co, efa->v2->co, efa->v3->co);
+                                               uvang2 = RAD2DEG(Vec2Angle3(tf_uv[0], tf_uv[1], tf_uv[2]));
+                                               ang2 = RAD2DEG(VecAngle3(efa->v1->co, efa->v2->co, efa->v3->co));
                                                
-                                               uvang3 = 180-(uvang1+uvang2);
-                                               ang3 = 180-(ang1+ang2);
+                                               uvang3 = M_PI-(uvang1+uvang2);
+                                               ang3 = M_PI-(ang1+ang2);
 #endif                                         
                                                
                                                /* uv angles */