Skip to content

Instantly share code, notes, and snippets.

@johnkpaul
Forked from anonymous/gist:1935517
Created February 28, 2012 22:02
Show Gist options
  • Save johnkpaul/1935555 to your computer and use it in GitHub Desktop.
Save johnkpaul/1935555 to your computer and use it in GitHub Desktop.
a guest on Feb 28th, 2012 - pastebin.com/1YXe6Nvd
//for (var i = 0; i < mapPoints.length; i++){
// for (var j = i + 1; j < mapPoints.length; j++){
// var p1 = mapPoints[i];
// var p2 = mapPoints[j];
// if (getDistance(p1, p2) < 0.1){ // If distance between points is greater than .1 km
// var midpoint = getMidpoint(p1, p2);
//
// mapPoints.push(midpoint);
// mapPoints.splice(i, 1);
// mapPoints.splice(j, 1);
// }
// }
//}
function getFinalPoints(mapPoints){
var zippedPoints = zip(mapPoints,mapPoints);
var greaterThan1KmPoints = zippedPoints.filter(function(pair){
return getDistance(pair[0],pair[1]) < 0.1;
});
var lessThan1KmPoints = zippedPoints.filter(function(pair){
return !(getDistance(pair[0],pair[1]) < 0.1);
});
if(greaterThan1KmPoints.length > 0){
var midpoints = greaterThan1KmPoints.map(getMidpoint);
return lessThan1KmPoints.concat(getFinalPoints(midpoints));
}
else{
return lessThan1KmPoints;
}
}
function zip(arr1,arr2){
var zipped = [];
for (var i = 0; i < arr1.length; i++){
for (var j = i + 1; j < arr2.length; j++){
var pair = [arr1[i],arr2[j]];
zipped.push(pair);
}
}
return zipped;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment