# If v is neither a TwoVector nor a tuple, we ain't it.
return False
+
+ def __add__(self, other_vector):
+ """
+ Add other_vector to this vector, and return a new TwoVector
+ containing the result.
+ """
+ return TwoVector(self.x + other_vector.x, self.y + other_vector.y)
+
+ def __sub__(self, other_vector):
+ """
+ Subtract other_vector from this vector. Return a new
+ TwoVector.
+ """
+ return TwoVector(self.x - other_vector.x, self.y - other_vector.y)
+
+
def __str__(self):
"""
Print the contents of our ordered pair.
return (self.x * other_vector.x) + (self.y * other_vector.y)
- def add(self, other_vector):
- """
- Add other_vector to this vector, and return a new TwoVector
- containing the result.
- """
- return TwoVector(self.x + other_vector.x, self.y + other_vector.y)
-
-
class Polygon:
"""
Wraps shapely.geometry.Polygon.
def __str__(self):
"""
- Write out the well-known text representation of this polygon.
+ Write out the well-known text representation of this polygon,
+ as well as the class name, which helps distinguish
+ Geometry.Polygon from shapely.geometry.Polygon..
"""
return "Geometry.Polygon<%s>" % self._shapely_polygon.to_wkt()
+
+ def wkt(self):
+ """
+ Return just the well-known text for this Polygon.
+ """
+ return self._shapely_polygon.to_wkt()
+
@classmethod
def from_shapely(self, shapely_polygon):
Translate the self polygon by the TwoVector v.
"""
regular_coords = self.coords()
- f = (lambda p: p.add(v))
+ f = (lambda p: p + v)
translated_coords = map(f, regular_coords)
return Polygon(translated_coords)
initial_dv = self.drag_vertices(v)
terminal_dv = [0, 0] # Just initializing it.
- terminal_dv[0] = initial_dv[0].add(v)
- terminal_dv[1] = initial_dv[1].add(v)
+ terminal_dv[0] = initial_dv[0] + v
+ terminal_dv[1] = initial_dv[1] + v
return Polygon( (initial_dv[1],
initial_dv[0],