- float result = sizeOfBlackWhiteBlackRun(fromX, fromY, toX, toY);\r
-\r
-\r
- // Now count other way -- don't run off image though of course\r
- int otherToX = fromX - (toX - fromX);\r
- if (otherToX < 0) {\r
- // "to" should the be the first value not included, so, the first value off\r
- // the edge is -1\r
- otherToX = -1;\r
- } else if (otherToX >= (int)image_->getWidth()) {\r
- otherToX = image_->getWidth();\r
- }\r
- int otherToY = fromY - (toY - fromY);\r
- if (otherToY < 0) {\r
- otherToY = -1;\r
- } else if (otherToY >= (int)image_->getHeight()) {\r
- otherToY = image_->getHeight();\r
- }\r
- result += sizeOfBlackWhiteBlackRun(fromX, fromY, otherToX, otherToY);\r
- return result - 1.0f; // -1 because we counted the middle pixel twice\r
+ float result = sizeOfBlackWhiteBlackRun(fromX, fromY, toX, toY);\r
+\r
+ // Now count other way -- don't run off image though of course\r
+ float scale = 1.0f;\r
+ int otherToX = fromX - (toX - fromX);\r
+ if (otherToX < 0) {\r
+ scale = (float) fromX / (float) (fromX - otherToX);\r
+ otherToX = 0;\r
+ } else if (otherToX >= (int)image_->getWidth()) {\r
+ scale = (float) (image_->getWidth() - 1 - fromX) / (float) (otherToX - fromX);\r
+ otherToX = image_->getWidth() - 1;\r
+ }\r
+ int otherToY = (int) (fromY - (toY - fromY) * scale);\r
+\r
+ scale = 1.0f;\r
+ if (otherToY < 0) {\r
+ scale = (float) fromY / (float) (fromY - otherToY);\r
+ otherToY = 0;\r
+ } else if (otherToY >= (int)image_->getHeight()) {\r
+ scale = (float) (image_->getHeight() - 1 - fromY) / (float) (otherToY - fromY);\r
+ otherToY = image_->getHeight() - 1;\r
+ }\r
+ otherToX = (int) (fromX + (otherToX - fromX) * scale);\r
+\r
+ result += sizeOfBlackWhiteBlackRun(fromX, fromY, otherToX, otherToY);\r
+ return result - 1.0f; // -1 because we counted the middle pixel twice\r