Revert "COSMIT skip some repeated computations in k-means"

This reverts commit e3583daa2f196b5822f784c7e53f081668ecef6d,
except for a typo fix.

Fixes #3039.