Advertisement
Guest User

Untitled

a guest
Sep 16th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. 1. crop_topleft_position.x
  3. 2. crop_topleft_position.y
  4. 3. crop_width
  5. 4. crop_height
  6. 5. bounding_width
  7. 6. bounding_height
  8. */
  9. function error( crop_topleft_positionX, crop_topleft_positionY, crop_width, crop_height, bounding_topleft_positionX, bounding_topleft_positionY, bounding_width, bounding_height ){
  10.     var error=0;
  11.    
  12.     boundingCenter={x:getCenterX (bounding_topleft_positionX, bounding_width), y:getCenterY (bounding_topleft_positionY, bounding_height)}
  13.  
  14.     crop_topLeft={x:crop_topleft_positionX,y:crop_topleft_positionY};
  15.    
  16.     crop_topRight={x:get_topRightX(topLeft.x, crop_width),y:get_topRightY(topLeft.y)};
  17.    
  18.     crop_bottomRight={x:get_bottomRightX(topLeft.x, crop_width),y:get_bottomRightY (topLeft.y, crop_height)};
  19.  
  20.     crop_bottomLeft={x:get_bottomLeftX(topLeft.x),y:get_bottomLeftY (topLeft.y, crop_height)};
  21.    
  22.     fixedHalfDiagonal=0.5*((bounding_width^2+bounding_height^2)^0.5);
  23.  
  24.     distanceTopLeft=distanceBtwPoints(boundingCenter, crop_topLeft);
  25.     distanceTopRight=distanceBtwPoints(boundingCenter, crop_topRight);
  26.     distanceBottomLeft=distanceBtwPoints(boundingCenter, crop_bottomLeft);
  27.     distanceBottomRight=distanceBtwPoints(boundingCenter, crop_bottomRight);
  28.  
  29.     diffTopLeft=Math.abs(distanceTopLeft-fixedHalfDiagonal);
  30.     diffTopRight=Math.abs(distanceTopRight-fixedHalfDiagonal);
  31.     diffBottomLeft=Math.abs(distanceBottomLeft-fixedHalfDiagonal);
  32.     diffBottomRight=Math.abs(distanceBottomRight-fixedHalfDiagonal);
  33.  
  34.     errorTopLeft=(diffTopLeft/fixedHalfDiagonal)*100;
  35.     errorTopRight=(diffTopRight/fixedHalfDiagonal)*100;
  36.     errorBottomLeft=(diffBottomLeft/fixedHalfDiagonal)*100;
  37.     errorBottomRight=(diffBottomRight/fixedHalfDiagonal)*100;
  38.  
  39.     error=max(errorTopLeft, errorTopRight, errorBottomLeft, errorBottomRight);
  40.     return error;
  41. }
  42.  
  43. function distanceBtwPoints(pointA, pointB){
  44.     var dist=((pointB.x-pointA.x)^2+(pointB.y-pointA.y)^2)^0.5;
  45.     return dist;
  46. }
  47.  
  48. function getCenterX (topLeftX, width){
  49.     var centerX;
  50.     centerX=topleftX+width/2;
  51.     return centerX;
  52. }
  53.  
  54. function getCenterY (topLeftY, height){
  55.     var centerY;
  56.     centerY=topleftY+height/2;
  57.     return centerY;
  58. }
  59.  
  60. function get_topRightX (topLeftX, width){
  61.     var topleftX;
  62.     topleftX=topleftX+width;
  63.     return topleftX;
  64. }
  65.  
  66. function get_topRightY (topLeftY){
  67.     return topleftY;
  68. }
  69.  
  70. function get_bottomRightX (topLeftX, width){
  71.     var bottomRightX;
  72.     bottomRightX=topLeftX+width;
  73.     return bottomRightX;
  74. }
  75.  
  76. function get_bottomRightY (topLeftY, height){
  77.     var bottomRightY;
  78.     bottomRightY=bottomRightY+height;
  79.     return bottomRightY;
  80. }
  81.  
  82. function get_bottomLeftX (topLeftX){
  83.     return topLeftX;
  84. }
  85.  
  86. function get_bottomLeftY (topLeftY, height){
  87.     var bottomLeftY;
  88.     bottomLeftY=bottomLeftY+height;
  89.     return bottomLeftY;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement