Point calculation in javascript