Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed input being changed globally when modified in samplePoints().
  • Loading branch information
Andrew Lawson authored and Andrew Lawson committed Dec 1, 2014
1 parent a063b77 commit 24e228d
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions geometric_separators.pde
Expand Up @@ -137,15 +137,16 @@ PVector getGeometricMedian(ArrayList<PVector> input) {


// Sample input points into sets of 4 // Sample input points into sets of 4
ArrayList<ArrayList<PVector>> samplePoints(ArrayList<PVector> input) { ArrayList<ArrayList<PVector>> samplePoints(ArrayList<PVector> input) {
ArrayList<PVector> inputCopy = new ArrayList<PVector>(input);
ArrayList<ArrayList<PVector>> setList = new ArrayList<ArrayList<PVector>>(); ArrayList<ArrayList<PVector>> setList = new ArrayList<ArrayList<PVector>>();
ArrayList<PVector> pointList = new ArrayList<PVector>(); ArrayList<PVector> pointList = new ArrayList<PVector>();
// While there are still points, split into sets // While there are still points, split into sets
while (input.size() > 0) { while (inputCopy.size() > 0) {
double rnd = new Random().nextDouble(); double rnd = new Random().nextDouble();
int index = (int)(rnd * 10) % input.size(); int index = (int)(rnd * 10) % inputCopy.size();
// Add to set // Add to set
pointList.add(input.get(index)); pointList.add(inputCopy.get(index));
input.remove(index); inputCopy.remove(index);
// Create new set on max size // Create new set on max size
if (pointList.size() == 4) { if (pointList.size() == 4) {
setList.add(pointList); setList.add(pointList);
Expand Down

0 comments on commit 24e228d

Please sign in to comment.