Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 1. crop_topleft_position.x
- 2. crop_topleft_position.y
- 3. crop_width
- 4. crop_height
- 5. bounding_width
- 6. bounding_height
- */
- function error( crop_topleft_positionX, crop_topleft_positionY, crop_width, crop_height, bounding_topleft_positionX, bounding_topleft_positionY, bounding_width, bounding_height ){
- var error=0;
- boundingCenter={x:getCenterX (bounding_topleft_positionX, bounding_width), y:getCenterY (bounding_topleft_positionY, bounding_height)}
- crop_topLeft={x:crop_topleft_positionX,y:crop_topleft_positionY};
- crop_topRight={x:get_topRightX(topLeft.x, crop_width),y:get_topRightY(topLeft.y)};
- crop_bottomRight={x:get_bottomRightX(topLeft.x, crop_width),y:get_bottomRightY (topLeft.y, crop_height)};
- crop_bottomLeft={x:get_bottomLeftX(topLeft.x),y:get_bottomLeftY (topLeft.y, crop_height)};
- fixedHalfDiagonal=0.5*((bounding_width^2+bounding_height^2)^0.5);
- distanceTopLeft=distanceBtwPoints(boundingCenter, crop_topLeft);
- distanceTopRight=distanceBtwPoints(boundingCenter, crop_topRight);
- distanceBottomLeft=distanceBtwPoints(boundingCenter, crop_bottomLeft);
- distanceBottomRight=distanceBtwPoints(boundingCenter, crop_bottomRight);
- diffTopLeft=Math.abs(distanceTopLeft-fixedHalfDiagonal);
- diffTopRight=Math.abs(distanceTopRight-fixedHalfDiagonal);
- diffBottomLeft=Math.abs(distanceBottomLeft-fixedHalfDiagonal);
- diffBottomRight=Math.abs(distanceBottomRight-fixedHalfDiagonal);
- errorTopLeft=(diffTopLeft/fixedHalfDiagonal)*100;
- errorTopRight=(diffTopRight/fixedHalfDiagonal)*100;
- errorBottomLeft=(diffBottomLeft/fixedHalfDiagonal)*100;
- errorBottomRight=(diffBottomRight/fixedHalfDiagonal)*100;
- error=max(errorTopLeft, errorTopRight, errorBottomLeft, errorBottomRight);
- return error;
- }
- function distanceBtwPoints(pointA, pointB){
- var dist=((pointB.x-pointA.x)^2+(pointB.y-pointA.y)^2)^0.5;
- return dist;
- }
- function getCenterX (topLeftX, width){
- var centerX;
- centerX=topleftX+width/2;
- return centerX;
- }
- function getCenterY (topLeftY, height){
- var centerY;
- centerY=topleftY+height/2;
- return centerY;
- }
- function get_topRightX (topLeftX, width){
- var topleftX;
- topleftX=topleftX+width;
- return topleftX;
- }
- function get_topRightY (topLeftY){
- return topleftY;
- }
- function get_bottomRightX (topLeftX, width){
- var bottomRightX;
- bottomRightX=topLeftX+width;
- return bottomRightX;
- }
- function get_bottomRightY (topLeftY, height){
- var bottomRightY;
- bottomRightY=bottomRightY+height;
- return bottomRightY;
- }
- function get_bottomLeftX (topLeftX){
- return topLeftX;
- }
- function get_bottomLeftY (topLeftY, height){
- var bottomLeftY;
- bottomLeftY=bottomLeftY+height;
- return bottomLeftY;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement