Divide only the necessary dimensions

Check if the distance is greater than each dimension and divide only the ones that are too big.

- [ ] Tests for new code
- [ ] Benchmark
- [ ] All tests pass
- [ ] Changelog entry
- [ ] Can be merged