JonazMartinez / explorercanvas

Automatically exported from code.google.com/p/explorercanvas
Apache License 2.0
0 stars 0 forks source link

Rotating 360° #27

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Draw an image (0,0,width,height)
2. Rotate Right Math.PI/2
3. Rotate Left -Math.PI/2 (or rotate again Math*PI/2 three times)

What is the expected output? What do you see instead?

Image should be in the same postion as before any rotation,
but it looks like having 1 or 2 pixel padding left/top.

What version of the product are you using? On what operating system?

r3 win XPs.p.3

Please provide any additional information below.

Looks like the problem is that the Matrixmultiply function overflows the
floating in javascript and so the value passed to the DXtransformation 
is 0.9999999999999998 insthead of 1, 
which should be the cosinus of Math.PI*n angles.
i added the following lines to "round" the result.
Once again I'm not sure this solves the bug, but I tested it and looks like
it's working in IE6 IE7 IE8.

--
if (sum>0 && sum<1){              
var sS = sum.toString().replace("0.","");
var sSA=[];
    for (var ii=0;ii<sS.length;ii++){
        sSA.push(parseInt(sS[ii]));
    }               
    for (ii=sSA.length;ii>5;ii--){
        if(sum<1){
            sS="0.";                    
            if(ii>=5){
                for(var q=0;q<ii-1;q++){sS+="0";}
                sS+="1";
                sum+=parseFloat(sS);
            }
        }
    }               
}

Original issue reported on code.google.com by sl8...@gmail.com on 6 Apr 2009 at 6:22

GoogleCodeExporter commented 9 years ago
Sorry,

I pasted an old test 
this is the correct one:)

  function rM(sum){
    var sS = sum.toString().replace("0.","");
    var sSA=[];
        for (var ii=0;ii<sS.length;ii++){
            sSA.push(parseInt(sS.substring(ii,ii+1)));
        }               
        for (ii=sSA.length;ii>5;ii--){
            if(sum<1){
                sS="0.";        
                if(sSA[ii]>=5){
                    for(var q=0;q<ii-1;q++){
                        sS+="0";
                    }
                    sS+="1";            
                    sum+=parseFloat(sS);
                }
            }else{
                break;
            }
        }             
    return sum;
  }

  function matrixMultiply(m1, m2) {
    var result = createMatrixIdentity();

    for (var x = 0; x < 3; x++) {
      for (var y = 0; y < 3; y++) {
        var sum = 0;

        for (var z = 0; z < 3; z++) {
          sum += m1[x][z] * m2[z][y];
          if (sum>0 && sum<1){            
            sum=rM(sum);
          }   
        }
        result[x][y] = sum;
      }
    }
    return result;
  }

Original comment by sl8...@gmail.com on 6 Apr 2009 at 8:16