Fix coordinate calculation in DMat::from_fn().

The builder function `f` was receiving incorrect coordinates, often
involving a uint underflow.

Added a test case to verify the new behavior.