def __nonzero__(self):
     """Returns whether any coordinates are nonzero.
     
     Examples:
     >>> assert Vector((0, 0))
     Traceback (most recent call last):
      ...
     AssertionError
     >>> assert Vector((0, -1))
     """
     return not floateq(self.view(numpy.ndarray), 0).all()
def collinear(p1, p2, *others):
    """Returns whether all given Positions (at least 2) are collinear.
    
    Examples:
    >>> assert collinear(Position((1,0,0)), Position((0,1,0)),
    ...                  Position((-1,2,0)), Position((-2, 3, 0)))
    """
    delta = p2-p1
    for other in others:
        d = other-p1
        if not floateq(delta.dot(d)**2, delta.dot(delta) * d.dot(d)):
            return False
    return True
    def is_scalar_multiple_of(self, other):
        """Returns whether the vector is a scalar multiple of another.

        Examples:
        >>> v0 = Vector((0,0,0))
        >>> v1 = Vector((1,0,0))
        >>> v2 = Vector((2,3,4))
        >>> v3 = Vector((4,6,8))
        >>> assert not v3.is_scalar_multiple_of(v1)
        >>> assert v3.is_scalar_multiple_of(v2)
        >>> assert v2.is_scalar_multiple_of(v3)
        >>> assert not v1.is_scalar_multiple_of(v0)
        >>> assert v0.is_scalar_multiple_of(v1)
        """
        if other:
            perp = self.component_perpendicular_to(other)
            return floateq(perp.dot(perp), 0)
        else:
            return self == other
 def __eq__(self, other):
     # If all our coordinates are roughly equal to theirs,
     #  we say we're equal.
     if isinstance(other, Vector):
         return bool(floateq(self, other).all())
     return NotImplemented
 def __eq__(self, other):
     if isinstance(other, Position):
         return floateq(self.view(numpy.ndarray),
                        other.view(numpy.ndarray)).all()
     return NotImplemented