MCPcopy Create free account
hub / github.com/careercup/ctci / countEquivalentLines

Method countEquivalentLines

java/Chapter 7/Question7_6/Question.java:10–22  ·  view source on GitHub ↗
(ArrayList<Line> lines, Line line)

Source from the content-addressed store, hash-verified

8
9 /* Count lines within an array of lines which are "equivalent" (slope and y-intercept are within an epsilon value) to a given line */
10 public static int countEquivalentLines(ArrayList<Line> lines, Line line) {
11 if (lines == null) {
12 return 0;
13 }
14
15 int count = 0;
16 for (Line parallelLine : lines) {
17 if (parallelLine.isEquivalent(line)) {
18 count++;
19 }
20 }
21 return count;
22 }
23
24 /* Check hashmap for lines that are equivalent. Note that we need to check one epsilon above and below the actual slope
25 * since we're defining two lines as equivalent if they're within an epsilon of each other.

Callers 1

findBestLineMethod · 0.95

Calls 3

floorToNearestEpsilonMethod · 0.95
isEquivalentMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected