The periodic_distance
function is useful to compute the shortest distance between two vertices of a graph of dimension 3 or less, i.e. for which a Cell
has been provided. It assumes that the unit cell is not too much skewed.
periodic_distance(u, mat, ortho=nothing, safemin=nothing)
Distance between point u
and the origin, given as a triplet of fractional coordinates, in a repeating unit cell of matrix mat
. The distance is the shortest between all equivalents of u
and the origin. If ortho
is set to true
, the angles α, β and γ of the cell are assumed right, which accelerates the computation by up to 7 times. If a distance lower than safemin
is computed, stop trying to find a periodic image of u
closer to the origin. If unspecified, both ortho
and safemin
are automatically determined from mat
.
This implementation assumes that the cell corresponds to a reduced lattice. It may be invalid for some edge cases otherwise.
For optimal performance, use periodic_distance!
with buffer
, ortho
and safemin
obtained from prepare_periodic_distance_computations
.
sourcedouble_widen(::Type)
Internal function used to selectively widen small integer and rational types.
This is useful to avoid overflow without sacrificing too much efficiency by always having to resolve to very large types.
source