Created
June 25, 2012 18:48
-
-
Save dscho/2990484 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// take a list and return a newArray(...) command | |
function join(list) { | |
result = "newArray("; | |
for (i = 0; i < list.length; i++) { | |
if (i > 0) | |
result = result + ", "; | |
result = result + list[i]; | |
} | |
result = result + ")"; | |
return result; | |
} | |
function distance(x1, y1, x2, y2) { | |
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); | |
} | |
function distance2segment(x, y, x1, y1, x2, y2) { | |
return distance(x, y, x1, y1) + distance(x, y, x2, y2); | |
} | |
function closestSegment(x, y, xList, yList) { | |
best = -1; | |
bestDistance = 9999999; // really large | |
for (i = 0; i < xList.length - 1; i++) { | |
distance = distace2segment(x, y, xList[i], yList[i], xList[i + 1], yList[i + 1]); | |
if (bestDistance > distance) { | |
bestDistance = distance; | |
best = i; | |
} | |
} | |
return best; | |
} | |
getSelectionCoordinates(x, y); | |
command = "makeSelection(" + selectionType + ", " | |
+ join(x) + ", " | |
+ join(y) + ");"; | |
print(command); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment