File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
week3/mergesort/assignment-collinear-points Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change 1+ input.txt
2+ Test.java
Original file line number Diff line number Diff line change @@ -63,6 +63,8 @@ private void calculateSegments() {
6363 testPoints [i ] = this .points [i ];
6464 }
6565
66+ ArrayList <String > usedSegments = new ArrayList <>();
67+
6668 for (int i = 0 ; i < this .points .length ; ++i ) {
6769 Point p0 = this .points [i ];
6870
@@ -87,8 +89,17 @@ private void calculateSegments() {
8789 Point pmin = Collections .min (sub );
8890 Point pmax = Collections .max (sub );
8991
92+ LineSegment segment = new LineSegment (pmin , pmax );
93+
94+ if (usedSegments .contains (segment .toString ())) {
95+ continue ;
96+ }
97+ usedSegments .add (segment .toString ());
98+
9099 this .segments = Arrays .copyOf (this .segments , segments .length + 1 );
91- this .segments [segments .length - 1 ] = new LineSegment (pmin , pmax );
100+ this .segments [segments .length - 1 ] = segment ;
101+
102+ // TODO: remove duplicates!!!
92103 }
93104
94105 start = j ;
You can’t perform that action at this time.
0 commit comments