Compute dx and dy from the same angle
Add type annotations for performance.