src/events/SDL_gesture.c
changeset 4920 a4032241deb5
parent 4919 716b2cbf4c9e
child 5262 b530ef003506
     1.1 --- a/src/events/SDL_gesture.c	Tue Nov 30 17:58:51 2010 -0800
     1.2 +++ b/src/events/SDL_gesture.c	Tue Nov 30 18:07:31 2010 -0800
     1.3 @@ -294,7 +294,7 @@
     1.4  }
     1.5  
     1.6  //DollarPath contains raw points, plus (possibly) the calculated length
     1.7 -int dollarNormalize(SDL_DollarPath path,SDL_FloatPoint *points) {
     1.8 +int dollarNormalize(const SDL_DollarPath *path,SDL_FloatPoint *points) {
     1.9    int i;
    1.10    float interval;
    1.11    float dist;
    1.12 @@ -303,34 +303,35 @@
    1.13    float xmin,xmax,ymin,ymax;
    1.14    float ang;
    1.15    float w,h;
    1.16 +  float length = path->length;
    1.17  
    1.18    //Calculate length if it hasn't already been done
    1.19 -  if(path.length <= 0) {
    1.20 -    for(i=1;i<path.numPoints;i++) {
    1.21 -      float dx = path.p[i  ].x - 
    1.22 -                 path.p[i-1].x;
    1.23 -      float dy = path.p[i  ].y - 
    1.24 -                 path.p[i-1].y;
    1.25 -      path.length += (float)(SDL_sqrt(dx*dx+dy*dy));
    1.26 +  if(length <= 0) {
    1.27 +    for(i=1;i<path->numPoints;i++) {
    1.28 +      float dx = path->p[i  ].x - 
    1.29 +                 path->p[i-1].x;
    1.30 +      float dy = path->p[i  ].y - 
    1.31 +                 path->p[i-1].y;
    1.32 +      length += (float)(SDL_sqrt(dx*dx+dy*dy));
    1.33      }
    1.34    }
    1.35  
    1.36    //Resample
    1.37 -  interval = path.length/(DOLLARNPOINTS - 1);
    1.38 +  interval = length/(DOLLARNPOINTS - 1);
    1.39    dist = interval;
    1.40  
    1.41    centroid.x = 0;centroid.y = 0;
    1.42    
    1.43 -  //printf("(%f,%f)\n",path.p[path.numPoints-1].x,path.p[path.numPoints-1].y);
    1.44 -  for(i = 1;i < path.numPoints;i++) {
    1.45 -    float d = (float)(SDL_sqrt((path.p[i-1].x-path.p[i].x)*(path.p[i-1].x-path.p[i].x)+
    1.46 -                             (path.p[i-1].y-path.p[i].y)*(path.p[i-1].y-path.p[i].y)));
    1.47 +  //printf("(%f,%f)\n",path->p[path->numPoints-1].x,path->p[path->numPoints-1].y);
    1.48 +  for(i = 1;i < path->numPoints;i++) {
    1.49 +    float d = (float)(SDL_sqrt((path->p[i-1].x-path->p[i].x)*(path->p[i-1].x-path->p[i].x)+
    1.50 +                             (path->p[i-1].y-path->p[i].y)*(path->p[i-1].y-path->p[i].y)));
    1.51      //printf("d = %f dist = %f/%f\n",d,dist,interval);
    1.52      while(dist + d > interval) {
    1.53 -      points[numPoints].x = path.p[i-1].x + 
    1.54 -        ((interval-dist)/d)*(path.p[i].x-path.p[i-1].x);
    1.55 -      points[numPoints].y = path.p[i-1].y + 
    1.56 -        ((interval-dist)/d)*(path.p[i].y-path.p[i-1].y);
    1.57 +      points[numPoints].x = path->p[i-1].x + 
    1.58 +        ((interval-dist)/d)*(path->p[i].x-path->p[i-1].x);
    1.59 +      points[numPoints].y = path->p[i-1].y + 
    1.60 +        ((interval-dist)/d)*(path->p[i].y-path->p[i-1].y);
    1.61        centroid.x += points[numPoints].x;
    1.62        centroid.y += points[numPoints].y;
    1.63        numPoints++;
    1.64 @@ -344,7 +345,7 @@
    1.65      return 0;
    1.66    }
    1.67    //copy the last point
    1.68 -  points[DOLLARNPOINTS-1] = path.p[path.numPoints-1];
    1.69 +  points[DOLLARNPOINTS-1] = path->p[path->numPoints-1];
    1.70    numPoints = DOLLARNPOINTS;
    1.71  
    1.72    centroid.x /= numPoints;
    1.73 @@ -386,7 +387,7 @@
    1.74    return numPoints;
    1.75  }
    1.76  
    1.77 -float dollarRecognize(SDL_DollarPath path,int *bestTempl,SDL_GestureTouch* touch) {
    1.78 +float dollarRecognize(const SDL_DollarPath *path,int *bestTempl,SDL_GestureTouch* touch) {
    1.79          
    1.80          SDL_FloatPoint points[DOLLARNPOINTS];
    1.81          int numPoints = dollarNormalize(path,points);
    1.82 @@ -528,7 +529,7 @@
    1.83  #ifdef ENABLE_DOLLAR
    1.84        if(inTouch->recording) {
    1.85          inTouch->recording = SDL_FALSE;        
    1.86 -        dollarNormalize(inTouch->dollarPath,path);
    1.87 +        dollarNormalize(&inTouch->dollarPath,path);
    1.88          //PrintPath(path);
    1.89          if(recordAll) {
    1.90            index = SDL_AddDollarGesture(NULL,path);
    1.91 @@ -549,7 +550,7 @@
    1.92        else {        
    1.93          int bestTempl;
    1.94          float error;
    1.95 -        error = dollarRecognize(inTouch->dollarPath,
    1.96 +        error = dollarRecognize(&inTouch->dollarPath,
    1.97                                  &bestTempl,inTouch);
    1.98          if(bestTempl >= 0){
    1.99            //Send Event