It would be good to clamp opacity to `(0, 1)`.  As it is, the weight function could return any number and you'd have a (potentially) infinitely growing cache.