Rename namespace and improve documentation
Simplified calculation and fixed some special cases like dim==2
Added test that explicitly tests the coordinate transformation.
Move implementation of utility functions in header to be inlineable.