Fixed valid-cube? to check all visited positions, rather than just edges of segments