There were multiple problems in previous implementation. All fixed in 33e871fe (the first commit); the next commits are not changing the implementation in itself.
- There are three main flips along X,Y,Z (the vectors of hSize). The total flip must be defined by recursive multiplication: flip=flipX * flipY * flipZ (each factor has determinant=1, leaving hSize.determinant unchanged). Instead, previous implementation would sum the terms, as in flip=flipX+flipY+flipZ, which opens up the possibility of a singular flip matrix like ((1,1,1),(1,1,1),(1,1,1)) (det=0, final volume=0).
- We can't flip each coordinate independently. Suppose X is the axis being flipped, if we flip
Xy
first, thenXz
, it is possible that the second flip invalidates the first one. Leaving the cell elongated. - When flip along X is decided, we need to determine the next flip (along Y) by considering a modified hSize (flipped along X). Instead, previous code would go back to virgin hSize for all three flips, possibly giving an irrelevant combination of flips (and, why not, a singular matrix and null volume).