svn merge -r36900:37028 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[blender-staging.git] / source / blender / blenkernel / intern / curve.c
index 2678b077b66423ed74230b6fce06e9a2735bd76d..dfc615f4489f6281338b4440e8c62f2fdee1a723 100644 (file)
  * ***** END GPL LICENSE BLOCK *****
  */
 
+/** \file blender/blenkernel/intern/curve.c
+ *  \ingroup bke
+ */
+
+
 #include <math.h>  // floor
 #include <string.h>
 #include <stdlib.h>  
@@ -47,6 +52,7 @@
 #include "DNA_key_types.h"  
 #include "DNA_scene_types.h"  
 #include "DNA_vfont_types.h"  
+#include "DNA_meshdata_types.h"  
 #include "DNA_object_types.h"
 
 #include "BKE_animsys.h"
@@ -58,7 +64,8 @@
 #include "BKE_key.h"  
 #include "BKE_library.h"  
 #include "BKE_main.h"  
-#include "BKE_object.h"  
+#include "BKE_object.h"
+#include "BKE_material.h"
 
 
 #include "ED_curve.h"
@@ -174,7 +181,7 @@ Curve *copy_curve(Curve *cu)
        int a;
        
        cun= copy_libblock(cu);
-       cun->nurb.first= cun->nurb.last= 0;
+       cun->nurb.first= cun->nurb.last= NULL;
        duplicateNurblist( &(cun->nurb), &(cu->nurb));
 
        cun->mat= MEM_dupallocN(cu->mat);
@@ -190,12 +197,13 @@ Curve *copy_curve(Curve *cu)
        cun->key= copy_key(cu->key);
        if(cun->key) cun->key->from= (ID *)cun;
        
-       cun->disp.first= cun->disp.last= 0;
-       cun->bev.first= cun->bev.last= 0;
-       cun->path= 0;
+       cun->disp.first= cun->disp.last= NULL;
+       cun->bev.first= cun->bev.last= NULL;
+       cun->path= NULL;
 
        cun->editnurb= NULL;
        cun->editfont= NULL;
+       cun->selboxes= NULL;
 
 #if 0  // XXX old animation system
        /* single user ipo too */
@@ -210,10 +218,22 @@ Curve *copy_curve(Curve *cu)
        return cun;
 }
 
+static void extern_local_curve(Curve *cu)
+{      
+       id_lib_extern((ID *)cu->vfont);
+       id_lib_extern((ID *)cu->vfontb);        
+       id_lib_extern((ID *)cu->vfonti);
+       id_lib_extern((ID *)cu->vfontbi);
+       
+       if(cu->mat) {
+               extern_local_matarar(cu->mat, cu->totcol);
+       }
+}
+
 void make_local_curve(Curve *cu)
 {
-       Object *ob = 0;
-       Curve *cun;
+       Main *bmain= G.main;
+       Object *ob;
        int local=0, lib=0;
        
        /* - when there are only lib users: don't do
@@ -221,49 +241,43 @@ void make_local_curve(Curve *cu)
         * - mixed: do a copy
         */
        
-       if(cu->id.lib==0) return;
-
-       if(cu->vfont) cu->vfont->id.lib= NULL;
-       if(cu->vfontb) cu->vfontb->id.lib= NULL;
-       if(cu->vfonti) cu->vfonti->id.lib= NULL;
-       if(cu->vfontbi) cu->vfontbi->id.lib= NULL;
+       if(cu->id.lib==NULL) return;
 
        if(cu->id.us==1) {
-               cu->id.lib= 0;
+               cu->id.lib= NULL;
                cu->id.flag= LIB_LOCAL;
-               new_id(0, (ID *)cu, 0);
+
+               new_id(&bmain->curve, (ID *)cu, NULL);
+               extern_local_curve(cu);
                return;
        }
-       
-       ob= G.main->object.first;
-       while(ob) {
-               if(ob->data==cu) {
+
+       for(ob= bmain->object.first; ob && ELEM(0, lib, local); ob= ob->id.next) {
+               if(ob->data == cu) {
                        if(ob->id.lib) lib= 1;
                        else local= 1;
                }
-               ob= ob->id.next;
        }
-       
+
        if(local && lib==0) {
-               cu->id.lib= 0;
+               cu->id.lib= NULL;
                cu->id.flag= LIB_LOCAL;
-               new_id(0, (ID *)cu, 0);
+
+               new_id(&bmain->curve, (ID *)cu, NULL);
+               extern_local_curve(cu);
        }
        else if(local && lib) {
-               cun= copy_curve(cu);
+               Curve *cun= copy_curve(cu);
                cun->id.us= 0;
-               
-               ob= G.main->object.first;
-               while(ob) {
+
+               for(ob= bmain->object.first; ob; ob= ob->id.next) {
                        if(ob->data==cu) {
-                               
-                               if(ob->id.lib==0) {
+                               if(ob->id.lib==NULL) {
                                        ob->data= cun;
                                        cun->id.us++;
                                        cu->id.us--;
                                }
                        }
-                       ob= ob->id.next;
                }
        }
 }
@@ -328,19 +342,19 @@ void tex_space_curve(Curve *cu)
                cu->size[1]= (max[1]-min[1])/2.0f;
                cu->size[2]= (max[2]-min[2])/2.0f;
 
-               cu->rot[0]= cu->rot[1]= cu->rot[2]= 0.0;
+               cu->rot[0]= cu->rot[1]= cu->rot[2]= 0.0f;
 
-               if(cu->size[0]==0.0) cu->size[0]= 1.0;
-               else if(cu->size[0]>0.0 && cu->size[0]<0.00001) cu->size[0]= 0.00001;
-               else if(cu->size[0]<0.0 && cu->size[0]> -0.00001) cu->size[0]= -0.00001;
+               if(cu->size[0]==0.0f) cu->size[0]= 1.0f;
+               else if(cu->size[0]>0.0f && cu->size[0]<0.00001f) cu->size[0]= 0.00001f;
+               else if(cu->size[0]<0.0f && cu->size[0]> -0.00001f) cu->size[0]= -0.00001f;
        
-               if(cu->size[1]==0.0) cu->size[1]= 1.0;
-               else if(cu->size[1]>0.0 && cu->size[1]<0.00001) cu->size[1]= 0.00001;
-               else if(cu->size[1]<0.0 && cu->size[1]> -0.00001) cu->size[1]= -0.00001;
+               if(cu->size[1]==0.0f) cu->size[1]= 1.0f;
+               else if(cu->size[1]>0.0f && cu->size[1]<0.00001f) cu->size[1]= 0.00001f;
+               else if(cu->size[1]<0.0f && cu->size[1]> -0.00001f) cu->size[1]= -0.00001f;
        
-               if(cu->size[2]==0.0) cu->size[2]= 1.0;
-               else if(cu->size[2]>0.0 && cu->size[2]<0.00001) cu->size[2]= 0.00001;
-               else if(cu->size[2]<0.0 && cu->size[2]> -0.00001) cu->size[2]= -0.00001;
+               if(cu->size[2]==0.0f) cu->size[2]= 1.0f;
+               else if(cu->size[2]>0.0f && cu->size[2]<0.00001f) cu->size[2]= 0.00001f;
+               else if(cu->size[2]<0.0f && cu->size[2]> -0.00001f) cu->size[2]= -0.00001f;
 
        }
 }
@@ -381,12 +395,12 @@ int count_curveverts_without_handles(ListBase *nurb)
 void freeNurb(Nurb *nu)
 {
 
-       if(nu==0) return;
+       if(nu==NULL) return;
 
        if(nu->bezt) MEM_freeN(nu->bezt);
-       nu->bezt= 0;
+       nu->bezt= NULL;
        if(nu->bp) MEM_freeN(nu->bp);
-       nu->bp= 0;
+       nu->bp= NULL;
        if(nu->knotsu) MEM_freeN(nu->knotsu);
        nu->knotsu= NULL;
        if(nu->knotsv) MEM_freeN(nu->knotsv);
@@ -402,7 +416,7 @@ void freeNurblist(ListBase *lb)
 {
        Nurb *nu, *next;
 
-       if(lb==0) return;
+       if(lb==NULL) return;
 
        nu= lb->first;
        while(nu) {
@@ -410,7 +424,7 @@ void freeNurblist(ListBase *lb)
                freeNurb(nu);
                nu= next;
        }
-       lb->first= lb->last= 0;
+       lb->first= lb->last= NULL;
 }
 
 Nurb *duplicateNurb(Nurb *nu)
@@ -419,7 +433,7 @@ Nurb *duplicateNurb(Nurb *nu)
        int len;
 
        newnu= (Nurb*)MEM_mallocN(sizeof(Nurb),"duplicateNurb");
-       if(newnu==0) return 0;
+       if(newnu==NULL) return NULL;
        memcpy(newnu, nu, sizeof(Nurb));
 
        if(nu->bezt) {
@@ -585,7 +599,7 @@ static void calcknots(float *knots, short aantal, short order, short type)
                k= 0.0;
                for(a=1;a<=t;a++) {
                        knots[a-1]= k;
-                       if(a>=order && a<=aantal) k+= 1.0;
+                       if(a>=order && a<=aantal) k+= 1.0f;
                }
        }
        else if(type==2) {
@@ -593,15 +607,15 @@ static void calcknots(float *knots, short aantal, short order, short type)
                if(order==4) {
                        k= 0.34;
                        for(a=0;a<t;a++) {
-                               knots[a]= (float)floor(k);
-                               k+= (1.0/3.0);
+                               knots[a]= floorf(k);
+                               k+= (1.0f/3.0f);
                        }
                }
                else if(order==3) {
-                       k= 0.6;
+                       k= 0.6f;
                        for(a=0;a<t;a++) {
-                               if(a>=order && a<=aantal) k+= (0.5);
-                               knots[a]= (float)floor(k);
+                               if(a>=order && a<=aantal) k+= 0.5f;
+                               knots[a]= floorf(k);
                        }
                }
                else {
@@ -615,7 +629,7 @@ static void makecyclicknots(float *knots, short pnts, short order)
 {
        int a, b, order2, c;
 
-       if(knots==0) return;
+       if(knots==NULL) return;
 
        order2=order-1;
 
@@ -625,7 +639,7 @@ static void makecyclicknots(float *knots, short pnts, short order)
                for(a=1; a<order2; a++) {
                        if(knots[b]!= knots[b-a]) break;
                }
-               if(a==order2) knots[pnts+order-2]+= 1.0;
+               if(a==order2) knots[pnts+order-2]+= 1.0f;
        }
 
        b= order;
@@ -717,12 +731,12 @@ static void basisNurb(float t, short order, short pnts, float *knots, float *bas
                if(i2+j>= orderpluspnts) i2= opp2-j;
 
                for(i= i1; i<=i2; i++) {
-                       if(basis[i]!=0.0)
+                       if(basis[i]!=0.0f)
                                d= ((t-knots[i])*basis[i]) / (knots[i+j-1]-knots[i]);
                        else
-                               d= 0.0;
+                               d= 0.0f;
 
-                       if(basis[i+1]!=0.0)
+                       if(basis[i+1] != 0.0f)
                                e= ((knots[i+j]-t)*basis[i+1]) / (knots[i+j]-knots[i+1]);
                        else
                                e= 0.0;
@@ -735,7 +749,7 @@ static void basisNurb(float t, short order, short pnts, float *knots, float *bas
        *end= 0;
 
        for(i=i1; i<=i2; i++) {
-               if(basis[i]>0.0) {
+               if(basis[i] > 0.0f) {
                        *end= i;
                        if(*start==1000) *start= i;
                }
@@ -777,7 +791,7 @@ void makeNurbfaces(Nurb *nu, float *coord_array, int rowstride, int resolu, int
        i= nu->pntsu*nu->pntsv;
        ratcomp=0;
        while(i--) {
-               if(bp->vec[3]!=1.0) {
+               if(bp->vec[3] != 1.0f) {
                        ratcomp= 1;
                        break;
                }
@@ -883,7 +897,7 @@ void makeNurbfaces(Nurb *nu, float *coord_array, int rowstride, int resolu, int
                                        }
                                        else bp++;
 
-                                       if(*fp!=0.0) {
+                                       if(*fp != 0.0f) {
                                                in[0]+= (*fp) * bp->vec[0];
                                                in[1]+= (*fp) * bp->vec[1];
                                                in[2]+= (*fp) * bp->vec[2];
@@ -918,7 +932,7 @@ void makeNurbcurve(Nurb *nu, float *coord_array, float *tilt_array, float *radiu
 
        if(nu->knotsu==NULL) return;
        if(nu->orderu>nu->pntsu) return;
-       if(coord_array==0) return;
+       if(coord_array==NULL) return;
 
        /* allocate and initialize */
        len= nu->pntsu;
@@ -959,7 +973,7 @@ void makeNurbcurve(Nurb *nu, float *coord_array, float *tilt_array, float *radiu
                        *fp= basisu[i]*bp->vec[3];
                        sumdiv+= *fp;
                }
-               if(sumdiv!=0.0) if(sumdiv<0.999 || sumdiv>1.001) {
+               if(sumdiv != 0.0f) if(sumdiv < 0.999f || sumdiv > 1.001f) {
                        /* is normalizing needed? */
                        fp= sum;
                        for(i= istart; i<=iend; i++, fp++) {
@@ -975,7 +989,7 @@ void makeNurbcurve(Nurb *nu, float *coord_array, float *tilt_array, float *radiu
                        if(i>=nu->pntsu) bp= nu->bp+(i - nu->pntsu);
                        else bp++;
 
-                       if(*fp!=0.0) {
+                       if(*fp != 0.0f) {
                                
                                coord_fp[0]+= (*fp) * bp->vec[0];
                                coord_fp[1]+= (*fp) * bp->vec[1];
@@ -1020,19 +1034,19 @@ void forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int i
        rt2= 3.0f*(q0-2.0f*q1+q2)/f;
        f*= it;
        rt3= (q3-q0+3.0f*(q1-q2))/f;
-       
-         q0= rt0;
+
+       q0= rt0;
        q1= rt1+rt2+rt3;
        q2= 2*rt2+6*rt3;
        q3= 6*rt3;
-  
-         for(a=0; a<=it; a++) {
+
+       for(a=0; a<=it; a++) {
                *p= q0;
                p = (float *)(((char *)p)+stride);
                q0+= q1;
-                q1+= q2;
-                q2+= q3;
-        }
+               q1+= q2;
+               q2+= q3;
+       }
 }
 
 static void forward_diff_bezier_cotangent(float *p0, float *p1, float *p2, float *p3, float *p, int it, int stride)
@@ -1042,7 +1056,7 @@ static void forward_diff_bezier_cotangent(float *p0, float *p1, float *p2, float
         *
         * This could also be optimized like forward_diff_bezier */
        int a;
-         for(a=0; a<=it; a++) {
+       for(a=0; a<=it; a++) {
                float t = (float)a / (float)it;
 
                int i;
@@ -1051,7 +1065,7 @@ static void forward_diff_bezier_cotangent(float *p0, float *p1, float *p2, float
                }
                normalize_v3(p);
                p = (float *)(((char *)p)+stride);
-        }
+       }
 }
 
 /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
@@ -1086,7 +1100,7 @@ float *make_orco_surf(Object *ob)
                sizev = nu->pntsv*resolv;
                if (nu->flagu & CU_NURB_CYCLIC) sizeu++;
                if (nu->flagv & CU_NURB_CYCLIC) sizev++;
-                if(nu->pntsv>1) tot+= sizeu * sizev;
+               if(nu->pntsv>1) tot+= sizeu * sizev;
                
                nu= nu->next;
        }
@@ -1259,7 +1273,7 @@ void makebevelcurve(Scene *scene, Object *ob, ListBase *disp, int forRender)
                if (cu->bevobj->type!=OB_CURVE) return;
 
                bevcu= cu->bevobj->data;
-               if(bevcu->ext1==0.0 && bevcu->ext2==0.0) {
+               if(bevcu->ext1==0.0f && bevcu->ext2==0.0f) {
                        ListBase bevdisp= {NULL, NULL};
                        facx= cu->bevobj->size[0];
                        facy= cu->bevobj->size[1];
@@ -1269,7 +1283,7 @@ void makebevelcurve(Scene *scene, Object *ob, ListBase *disp, int forRender)
                                dl= bevdisp.first;
                        } else {
                                dl= cu->bevobj->disp.first;
-                               if(dl==0) {
+                               if(dl==NULL) {
                                        makeDispListCurveTypes(scene, cu->bevobj, 0);
                                        dl= cu->bevobj->disp.first;
                                }
@@ -1300,10 +1314,10 @@ void makebevelcurve(Scene *scene, Object *ob, ListBase *disp, int forRender)
                        freedisplist(&bevdisp);
                }
        }
-       else if(cu->ext1==0.0 && cu->ext2==0.0) {
+       else if(cu->ext1==0.0f && cu->ext2==0.0f) {
                ;
        }
-       else if(cu->ext2==0.0) {
+       else if(cu->ext2==0.0f) {
                dl= MEM_callocN(sizeof(DispList), "makebevelcurve2");
                dl->verts= MEM_mallocN(2*3*sizeof(float), "makebevelcurve2");
                BLI_addtail(disp, dl);
@@ -1332,13 +1346,13 @@ void makebevelcurve(Scene *scene, Object *ob, ListBase *disp, int forRender)
 
                /* a circle */
                fp= dl->verts;
-               dangle= (2.0f*M_PI/(nr));
+               dangle= (2.0f*(float)M_PI/(nr));
                angle= -(nr-1)*dangle;
                
                for(a=0; a<nr; a++) {
                        fp[0]= 0.0;
-                       fp[1]= (float)(cos(angle)*(cu->ext2));
-                       fp[2]= (float)(sin(angle)*(cu->ext2)) - cu->ext1;
+                       fp[1]= (cosf(angle)*(cu->ext2));
+                       fp[2]= (sinf(angle)*(cu->ext2)) - cu->ext1;
                        angle+= dangle;
                        fp+= 3;
                }
@@ -1369,15 +1383,15 @@ void makebevelcurve(Scene *scene, Object *ob, ListBase *disp, int forRender)
 
                        for(a=0; a<nr; a++) {
                                fp[0]= 0.0;
-                               fp[1]= (float)(cos(angle)*(cu->ext2));
-                               fp[2]= (float)(sin(angle)*(cu->ext2)) - cu->ext1;
+                               fp[1]= (float)(cosf(angle)*(cu->ext2));
+                               fp[2]= (float)(sinf(angle)*(cu->ext2)) - cu->ext1;
                                angle+= dangle;
                                fp+= 3;
                        }
                }
                
                /* part 2, sidefaces */
-               if(cu->ext1!=0.0) {
+               if(cu->ext1!=0.0f) {
                        nr= 2;
                        
                        dl= MEM_callocN(sizeof(DispList), "makebevelcurve p2");
@@ -1427,8 +1441,8 @@ void makebevelcurve(Scene *scene, Object *ob, ListBase *disp, int forRender)
 
                        for(a=0; a<nr; a++) {
                                fp[0]= 0.0;
-                               fp[1]= (float)(cos(angle)*(cu->ext2));
-                               fp[2]= (float)(sin(angle)*(cu->ext2)) + cu->ext1;
+                               fp[1]= (float)(cosf(angle)*(cu->ext2));
+                               fp[2]= (float)(sinf(angle)*(cu->ext2)) + cu->ext1;
                                angle+= dangle;
                                fp+= 3;
                        }
@@ -1447,7 +1461,7 @@ static int cu_isectLL(float *v1, float *v2, float *v3, float *v4, short cox, sho
        float deler;
 
        deler= (v1[cox]-v2[cox])*(v3[coy]-v4[coy])-(v3[cox]-v4[cox])*(v1[coy]-v2[coy]);
-       if(deler==0.0) return -1;
+       if(deler==0.0f) return -1;
 
        *labda= (v1[coy]-v3[coy])*(v3[cox]-v4[cox])-(v1[cox]-v3[cox])*(v3[coy]-v4[coy]);
        *labda= -(*labda/deler);
@@ -1462,8 +1476,8 @@ static int cu_isectLL(float *v1, float *v2, float *v3, float *v4, short cox, sho
        vec[cox]= *labda*(v2[cox]-v1[cox])+v1[cox];
        vec[coy]= *labda*(v2[coy]-v1[coy])+v1[coy];
 
-       if(*labda>=0.0 && *labda<=1.0 && *mu>=0.0 && *mu<=1.0) {
-               if(*labda==0.0 || *labda==1.0 || *mu==0.0 || *mu==1.0) return 1;
+       if(*labda>=0.0f && *labda<=1.0f && *mu>=0.0f && *mu<=1.0f) {
+               if(*labda==0.0f || *labda==1.0f || *mu==0.0f || *mu==1.0f) return 1;
                return 2;
        }
        return 0;
@@ -1508,7 +1522,7 @@ static short bevelinside(BevList *bl1,BevList *bl2)
                                /* if lab==0.0 or lab==1.0 then the edge intersects exactly a transition
                                           only allow for one situation: we choose lab= 1.0
                                 */
-                               if(mode>=0 && lab!=0.0) {
+                               if(mode >= 0 && lab != 0.0f) {
                                        if(vec[0]<hvec1[0]) links++;
                                        else rechts++;
                                }
@@ -1546,8 +1560,8 @@ static void calc_bevel_sin_cos(float x1, float y1, float x2, float y2, float *si
 
        t01= (float)sqrt(x1*x1+y1*y1);
        t02= (float)sqrt(x2*x2+y2*y2);
-       if(t01==0.0) t01= 1.0;
-       if(t02==0.0) t02= 1.0;
+       if(t01==0.0f) t01= 1.0f;
+       if(t02==0.0f) t02= 1.0f;
 
        x1/=t01; 
        y1/=t01;
@@ -1559,7 +1573,7 @@ static void calc_bevel_sin_cos(float x1, float y1, float x2, float y2, float *si
        else t02= (saacos(t02))/2.0f;
 
        t02= (float)sin(t02);
-       if(t02==0.0) t02= 1.0;
+       if(t02==0.0f) t02= 1.0f;
 
        x3= x1-x2;
        y3= y1-y2;
@@ -1696,7 +1710,7 @@ static void bevel_list_flip_tangents(BevList *bl)
 
        nr= bl->nr;
        while(nr--) {
-               if(RAD2DEG(angle_v2v2(bevp0->tan, bevp1->tan)) > 90)
+               if(RAD2DEGF(angle_v2v2(bevp0->tan, bevp1->tan)) > 90.0f)
                        negate_v3(bevp1->tan);
 
                bevp0= bevp1;
@@ -1707,13 +1721,12 @@ static void bevel_list_flip_tangents(BevList *bl)
 /* apply user tilt */
 static void bevel_list_apply_tilt(BevList *bl)
 {
-       BevPoint *bevp2, *bevp1, *bevp0;
+       BevPoint *bevp2, *bevp1;
        int nr;
        float q[4];
 
        bevp2= (BevPoint *)(bl+1);
        bevp1= bevp2+(bl->nr-1);
-       bevp0= bevp1-1;
 
        nr= bl->nr;
        while(nr--) {
@@ -1721,7 +1734,6 @@ static void bevel_list_apply_tilt(BevList *bl)
                mul_qt_qtqt(bevp1->quat, q, bevp1->quat);
                normalize_qt(bevp1->quat);
 
-               bevp0= bevp1;
                bevp1= bevp2;
                bevp2++;
        }
@@ -1811,8 +1823,6 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl)
        int nr;
        float q[4];
 
-       float cross_tmp[3];
-
        bevel_list_calc_bisect(bl);
 
        bevp2= (BevPoint *)(bl+1);
@@ -1829,6 +1839,7 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl)
                        float angle= angle_normalized_v3v3(bevp0->dir, bevp1->dir);
 
                        if(angle > 0.0f) { /* otherwise we can keep as is */
+                               float cross_tmp[3];
                                cross_v3_v3v3(cross_tmp, bevp0->dir, bevp1->dir);
                                axis_angle_to_quat(q, cross_tmp, angle);
                                mul_qt_qtqt(bevp1->quat, q, bevp0->quat);
@@ -1849,7 +1860,7 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl)
                 * do this by calculating the tilt angle difference, then apply
                 * the rotation gradually over the entire curve
                 *
-                * note that the split is between last and second last, rather then first/last as youd expect.
+                * note that the split is between last and second last, rather than first/last as youd expect.
                 *
                 * real order is like this
                 * 0,1,2,3,4 --> 1,2,3,4,0
@@ -1887,7 +1898,7 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl)
                /* flip rotation if needs be */
                cross_v3_v3v3(cross_tmp, vec_1, vec_2);
                normalize_v3(cross_tmp);
-               if(angle_normalized_v3v3(bevp_first->dir, cross_tmp) < 90/(180.0/M_PI))
+               if(angle_normalized_v3v3(bevp_first->dir, cross_tmp) < 90.0f/(float)(180.0/M_PI))
                        angle = -angle;
 
                bevp2= (BevPoint *)(bl+1);
@@ -2281,7 +2292,7 @@ void makeBevelList(Object *ob)
 
                                inp= (bevp1->vec[0]- bevp0->vec[0]) * (bevp0->vec[1]- bevp2->vec[1]) + (bevp0->vec[1]- bevp1->vec[1]) * (bevp0->vec[0]- bevp2->vec[0]);
 
-                               if(inp>0.0) sd->dir= 1;
+                               if(inp > 0.0f) sd->dir= 1;
                                else sd->dir= 0;
 
                                sd++;
@@ -2426,7 +2437,7 @@ void calchandleNurb(BezTriple *bezt, BezTriple *prev, BezTriple *next, int mode)
 
        p2= bezt->vec[1];
 
-       if(prev==0) {
+       if(prev==NULL) {
                p3= next->vec[1];
                pt[0]= 2*p2[0]- p3[0];
                pt[1]= 2*p2[1]- p3[1];
@@ -2435,7 +2446,7 @@ void calchandleNurb(BezTriple *bezt, BezTriple *prev, BezTriple *next, int mode)
        }
        else p1= prev->vec[1];
 
-       if(next==0) {
+       if(next==NULL) {
                pt[0]= 2*p2[0]- p1[0];
                pt[1]= 2*p2[1]- p1[1];
                pt[2]= 2*p2[2]- p1[2];
@@ -2481,11 +2492,11 @@ void calchandleNurb(BezTriple *bezt, BezTriple *prev, BezTriple *next, int mode)
                                if(mode==2 && next && prev) {   // keep horizontal if extrema
                                        float ydiff1= prev->vec[1][1] - bezt->vec[1][1];
                                        float ydiff2= next->vec[1][1] - bezt->vec[1][1];
-                                       if( (ydiff1<=0.0 && ydiff2<=0.0) || (ydiff1>=0.0 && ydiff2>=0.0) ) {
+                                       if( (ydiff1 <= 0.0f && ydiff2 <= 0.0f) || (ydiff1 >= 0.0f && ydiff2 >= 0.0f) ) {
                                                bezt->vec[0][1]= bezt->vec[1][1];
                                        }
                                        else {                                          // handles should not be beyond y coord of two others
-                                               if(ydiff1<=0.0) { 
+                                               if(ydiff1 <= 0.0f) {
                                                        if(prev->vec[1][1] > bezt->vec[0][1]) {
                                                                bezt->vec[0][1]= prev->vec[1][1]; 
                                                                leftviolate= 1;
@@ -2509,11 +2520,11 @@ void calchandleNurb(BezTriple *bezt, BezTriple *prev, BezTriple *next, int mode)
                                if(mode==2 && next && prev) {   // keep horizontal if extrema
                                        float ydiff1= prev->vec[1][1] - bezt->vec[1][1];
                                        float ydiff2= next->vec[1][1] - bezt->vec[1][1];
-                                       if( (ydiff1<=0.0 && ydiff2<=0.0) || (ydiff1>=0.0 && ydiff2>=0.0) ) {
+                                       if( (ydiff1 <= 0.0f && ydiff2 <= 0.0f) || (ydiff1 >= 0.0f && ydiff2 >= 0.0f) ) {
                                                bezt->vec[2][1]= bezt->vec[1][1];
                                        }
                                        else {                                          // handles should not be beyond y coord of two others
-                                               if(ydiff1<=0.0) { 
+                                               if(ydiff1 <= 0.0f) {
                                                        if(next->vec[1][1] < bezt->vec[2][1]) {
                                                                bezt->vec[2][1]= next->vec[1][1]; 
                                                                rightviolate= 1;
@@ -2554,17 +2565,17 @@ void calchandleNurb(BezTriple *bezt, BezTriple *prev, BezTriple *next, int mode)
        }
 
        if(bezt->h1==HD_VECT) { /* vector */
-               dx/=3.0
-               dy/=3.0
-               dz/=3.0;
+               dx/=3.0f;
+               dy/=3.0f;
+               dz/=3.0f;
                *(p2-3)= *p2-dx;
                *(p2-2)= *(p2+1)-dy;
                *(p2-1)= *(p2+2)-dz;
        }
        if(bezt->h2==HD_VECT) {
-               dx1/=3.0
-               dy1/=3.0
-               dz1/=3.0;
+               dx1/=3.0f;
+               dy1/=3.0f;
+               dz1/=3.0f;
                *(p2+3)= *p2+dx1;
                *(p2+4)= *(p2+1)+dy1;
                *(p2+5)= *(p2+2)+dz1;
@@ -2572,8 +2583,8 @@ void calchandleNurb(BezTriple *bezt, BezTriple *prev, BezTriple *next, int mode)
 
        len2= len_v3v3(p2, p2+3);
        len1= len_v3v3(p2, p2-3);
-       if(len1==0.0) len1=1.0;
-       if(len2==0.0) len2=1.0;
+       if(len1==0.0f) len1= 1.0f;
+       if(len2==0.0f) len2= 1.0f;
 
        if(bezt->f1 & SELECT) { /* order of calculation */
                if(bezt->h2==HD_ALIGN) {        /* aligned */
@@ -2616,7 +2627,7 @@ void calchandlesNurb(Nurb *nu) /* first, if needed, set handle flags */
        a= nu->pntsu;
        bezt= nu->bezt;
        if(nu->flagu & CU_NURB_CYCLIC) prev= bezt+(a-1);
-       else prev= 0;
+       else prev= NULL;
        next= bezt+1;
 
        while(a--) {
@@ -2624,7 +2635,7 @@ void calchandlesNurb(Nurb *nu) /* first, if needed, set handle flags */
                prev= bezt;
                if(a==1) {
                        if(nu->flagu & CU_NURB_CYCLIC) next= nu->bezt;
-                       else next= 0;
+                       else next= NULL;
                }
                else next++;
 
@@ -2683,7 +2694,7 @@ void autocalchandlesNurb(Nurb *nu, int flag)
        BezTriple *bezt2, *bezt1, *bezt0;
        int i, align, leftsmall, rightsmall;
 
-       if(nu==0 || nu->bezt==0) return;
+       if(nu==NULL || nu->bezt==NULL) return;
        
        bezt2 = nu->bezt;
        bezt1 = bezt2 + (nu->pntsu-1);
@@ -2698,18 +2709,18 @@ void autocalchandlesNurb(Nurb *nu, int flag)
                if(flag==0 || (bezt1->f1 & flag) ) {
                        bezt1->h1= 0;
                        /* distance too short: vectorhandle */
-                       if( len_v3v3( bezt1->vec[1], bezt0->vec[1] ) < 0.0001) {
+                       if( len_v3v3( bezt1->vec[1], bezt0->vec[1] ) < 0.0001f) {
                                bezt1->h1= HD_VECT;
                                leftsmall= 1;
                        }
                        else {
                                /* aligned handle? */
-                               if(dist_to_line_v2(bezt1->vec[1], bezt1->vec[0], bezt1->vec[2]) < 0.0001) {
+                               if(dist_to_line_v2(bezt1->vec[1], bezt1->vec[0], bezt1->vec[2]) < 0.0001f) {
                                        align= 1;
                                        bezt1->h1= HD_ALIGN;
                                }
                                /* or vector handle? */
-                               if(dist_to_line_v2(bezt1->vec[0], bezt1->vec[1], bezt0->vec[1]) < 0.0001)
+                               if(dist_to_line_v2(bezt1->vec[0], bezt1->vec[1], bezt0->vec[1]) < 0.0001f)
                                        bezt1->h1= HD_VECT;
                                
                        }
@@ -2718,7 +2729,7 @@ void autocalchandlesNurb(Nurb *nu, int flag)
                if(flag==0 || (bezt1->f3 & flag) ) {
                        bezt1->h2= 0;
                        /* distance too short: vectorhandle */
-                       if( len_v3v3( bezt1->vec[1], bezt2->vec[1] ) < 0.0001) {
+                       if( len_v3v3( bezt1->vec[1], bezt2->vec[1] ) < 0.0001f) {
                                bezt1->h2= HD_VECT;
                                rightsmall= 1;
                        }
@@ -2727,7 +2738,7 @@ void autocalchandlesNurb(Nurb *nu, int flag)
                                if(align) bezt1->h2= HD_ALIGN;
 
                                /* or vector handle? */
-                               if(dist_to_line_v2(bezt1->vec[2], bezt1->vec[1], bezt2->vec[1]) < 0.0001)
+                               if(dist_to_line_v2(bezt1->vec[2], bezt1->vec[1], bezt2->vec[1]) < 0.0001f)
                                        bezt1->h2= HD_VECT;
                                
                        }