Corner detection in javascript