caryclark@google.com | 27accef | 2012-01-25 18:57:23 +0000 | [diff] [blame] | 1 | #include "LineUtilities.h" |
| 2 | |
| 3 | bool implicitLine(const _Line& line, double& slope, double& axisIntercept) { |
| 4 | double lineDx = line[1].x - line[0].x; |
| 5 | double lineDy = line[1].y - line[0].y; |
| 6 | bool moreHorizontal = fabs(lineDx) > fabs(lineDy); |
| 7 | if (moreHorizontal) { |
| 8 | slope = lineDy / lineDx; |
| 9 | axisIntercept = line[0].y - slope * line[0].x; |
| 10 | } else { |
| 11 | slope = lineDx / lineDy; |
| 12 | axisIntercept = line[0].x - slope * line[0].y; |
| 13 | } |
| 14 | return moreHorizontal; |
| 15 | } |
| 16 | |
| 17 | int reduceOrder(const _Line& line, _Line& reduced) { |
| 18 | reduced[0] = line[0]; |
| 19 | int different = line[0] != line[1]; |
| 20 | reduced[1] = line[different]; |
| 21 | return 1 + different; |
| 22 | } |