Euclidean geometry in javascript