(GraphPoint[] points)
| 47 | |
| 48 | |
| 49 | public static Line findBestLine(GraphPoint[] points) { |
| 50 | Line bestLine = null; |
| 51 | int bestCount = 0; |
| 52 | HashMap<Double, ArrayList<Line>> linesBySlope = new HashMap<Double, ArrayList<Line>>(); |
| 53 | |
| 54 | for (int i = 0; i < points.length; i++) { |
| 55 | for (int j = i + 1; j < points.length; j++) { |
| 56 | Line line = new Line(points[i], points[j]); |
| 57 | insertLine(linesBySlope, line); |
| 58 | |
| 59 | /* count lines that are equivalent to current line */ |
| 60 | int count = countEquivalentLines(linesBySlope, line); |
| 61 | |
| 62 | /* if better than current line, replace it */ |
| 63 | if (count > bestCount) { |
| 64 | bestLine = line; |
| 65 | bestCount = count; |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | return bestLine; |
| 71 | } |
| 72 | |
| 73 | public static GraphPoint[] createPoints() { |
| 74 | int n_points = 100; |
no test coverage detected