function circularIndex(start, delta, len) { var mod = (start + delta) % len; return ((mod >= 0) ? mod : mod + len); } function delta(oldIndex, newIndex) { if (oldIndex > newIndex) return 0 - (oldIndex - newIndex); else if (oldIndex < newIndex) return (newIndex - oldIndex); else return 0; } function Point(x, y) { this.x = x; this.y = y; }