Commit 0ab50fc2 authored by Michael Büsch's avatar Michael Büsch

geo2d: Add __bool__

Signed-off-by: Michael Büsch's avatarMichael Buesch <m@bues.ch>
parent bd32afa1
......@@ -36,6 +36,11 @@ class Base2D(object):
__hash__ = None
def __bool__(self):
return True
__nonzero__ = __bool__ # Python 2 compat
class Point2D(Base2D):
"""2D point.
"""
......@@ -50,6 +55,9 @@ class Point2D(Base2D):
return other is not None and\
self.x == other.x and self.y == other.y
def __bool__(self):
return bool(self.x or self.y)
def __repr__(self):
return "Point2D(x=%f, y=%f)" % (self.x, self.y)
......@@ -67,6 +75,9 @@ class Vect2D(Base2D):
return other is not None and\
self.x == other.x and self.y == other.y
def __bool__(self):
return bool(self.x or self.y)
def __repr__(self):
return "Vect2D(x=%f, y=%f)" % (self.x, self.y)
......@@ -92,6 +103,9 @@ class Inter2D(Base2D):
self.vect == other.vect and\
self.__intersects == other.__intersects
def __bool__(self):
return self.intersects
@property
def intersects(self):
"""Returns True, if there is an intersection.
......@@ -133,6 +147,11 @@ class LineSeg2D(Base2D):
self.pointA == other.pointA and\
self.pointB == other.pointB
def __bool__(self):
"""Returns True, if the segment is of non-zero length.
"""
return bool(self.vect)
@property
def isHorizontal(self):
"""Returns True, if the line segment is parallel to the X axis.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment