fixed bug where getIndexAtLength(perimeter) returns 0 instead of the final index. closes #3389