triangular inequality check added