Skip to content

Commit

Permalink
fix(point): Correction to Point __add__ and __sub__ operators
Browse files Browse the repository at this point in the history
I'm really sorry that I did not catch this bug sooner since it may have repercussions throughout the other libraries. Better to find them out now before the release, though.
  • Loading branch information
chriswmackey authored and Chris Mackey committed Feb 26, 2020
1 parent 7d8f4d2 commit 77b15bb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions ladybug_geometry/geometry2d/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from .._mesh import MeshBase

from .pointvector import Point2D
from .pointvector import Point2D, Vector2D
from .line import LineSegment2D
from .polygon import Polygon2D

Expand Down Expand Up @@ -168,7 +168,7 @@ def from_polygon_grid(cls, polygon, x_dim, y_dim, generate_centroids=True):
# figure out which vertices lie inside the polygon
# for tolerance reasons, we scale the polygon by a very small amount
# this avoids the fringe cases noted in the Polygon2d.is_point_inside description
tol_pt = Point2D(0.0000001, 0.0000001)
tol_pt = Vector2D(0.0000001, 0.0000001)
scaled_poly = Polygon2D(
tuple(pt.scale(1.000001, _poly_min) - tol_pt for pt in polygon.vertices))
_pattern = [scaled_poly.is_point_inside(_v) for _v in _verts]
Expand Down
16 changes: 8 additions & 8 deletions ladybug_geometry/geometry2d/pointvector.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def rotate(self, angle, origin):
angle: An angle for rotation in radians.
origin: A Point2D for the origin around which the point will be rotated.
"""
return Point2D._rotate(self - origin, angle) + origin
return Vector2D._rotate(self - origin, angle) + origin

def reflect(self, normal, origin):
"""Get a point reflected across a plane with the input normal vector and origin.
Expand All @@ -347,7 +347,7 @@ def reflect(self, normal, origin):
which the point will be reflected. THIS VECTOR MUST BE NORMALIZED.
origin: A Point2D representing the origin from which to reflect.
"""
return Point2D._reflect(self - origin, normal) + origin
return Vector2D._reflect(self - origin, normal) + origin

def scale(self, factor, origin=None):
"""Scale a point by a factor from an origin point.
Expand Down Expand Up @@ -392,20 +392,20 @@ def to_dict(self):
def __add__(self, other):
# Point + Vector -> Point
# Point + Point -> Vector
if isinstance(other, Vector2D):
return Point2D(self.x + other.x, self.y + other.y)
elif isinstance(other, Point2D):
if isinstance(other, Point2D):
return Vector2D(self.x + other.x, self.y + other.y)
elif isinstance(other, Vector2D):
return Point2D(self.x + other.x, self.y + other.y)
else:
raise TypeError('Cannot add Point2D and {}'.format(type(other)))

def __sub__(self, other):
# Point - Vector -> Point
# Point - Point -> Vector
if isinstance(other, Vector2D):
return Point2D(self.x - other.x, self.y - other.y)
elif isinstance(other, Point2D):
if isinstance(other, Point2D):
return Vector2D(self.x - other.x, self.y - other.y)
elif isinstance(other, Vector2D):
return Point2D(self.x - other.x, self.y - other.y)
else:
raise TypeError('Cannot subtract Point2D and {}'.format(type(other)))

Expand Down
2 changes: 1 addition & 1 deletion ladybug_geometry/geometry3d/face.py
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,7 @@ def _vertices_between_points(self, start_pt, end_pt, tolerance):

def _diagonal_along_self(self, direction_vector, tolerance):
"""Get the diagonal oriented along this face and always starts on the left."""
tol_pt = Point3D(1.0e-7, 1.0e-7, 1.0e-7) # closer to Python tolerance than input
tol_pt = Vector3D(1.0e-7, 1.0e-7, 1.0e-7) # closer to Python tolerance than input
diagonal = LineSegment3D.from_end_points(self.min + tol_pt, self.max - tol_pt)
# invert the diagonal XY if it is not oriented with the face plane
if self._plane.distance_to_point(diagonal.p) > tolerance:
Expand Down
18 changes: 9 additions & 9 deletions ladybug_geometry/geometry3d/pointvector.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def rotate(self, axis, angle, origin):
angle: An angle for rotation in radians.
origin: A Point3D for the origin around which the point will be rotated.
"""
return Point3D._rotate(self - origin, axis, angle) + origin
return Vector3D._rotate(self - origin, axis, angle) + origin

def rotate_xy(self, angle, origin):
"""Get a point rotated counterclockwise in the XY plane by a certain angle.
Expand All @@ -384,7 +384,7 @@ def rotate_xy(self, angle, origin):
"""
trans_self = self - origin
vec_2 = Vector2D._rotate(trans_self, angle)
return Point3D(vec_2.x, vec_2.y, trans_self.z) + origin
return Vector3D(vec_2.x, vec_2.y, trans_self.z) + origin

def reflect(self, normal, origin):
"""Get a point reflected across a plane with the input normal vector and origin.
Expand All @@ -394,7 +394,7 @@ def reflect(self, normal, origin):
which the point will be reflected. THIS VECTOR MUST BE NORMALIZED.
origin: A Point3D representing the origin from which to reflect.
"""
return Point3D._reflect(self - origin, normal) + origin
return Vector3D._reflect(self - origin, normal) + origin

def scale(self, factor, origin=None):
"""Scale a point by a factor from an origin point.
Expand Down Expand Up @@ -453,20 +453,20 @@ def to_dict(self):
def __add__(self, other):
# Point + Vector -> Point
# Point + Point -> Vector
if isinstance(other, Vector3D):
return Point3D(self.x + other.x, self.y + other.y, self.z + other.z)
elif isinstance(other, Point3D):
if isinstance(other, Point3D):
return Vector3D(self.x + other.x, self.y + other.y, self.z + other.z)
elif isinstance(other, Vector3D):
return Point3D(self.x + other.x, self.y + other.y, self.z + other.z)
else:
raise TypeError('Cannot add Point3D and {}'.format(type(other)))

def __sub__(self, other):
# Point - Vector -> Point
# Point - Point -> Vector
if isinstance(other, Vector3D):
if isinstance(other, Point3D):
return Vector3D(self.x - other.x, self.y - other.y, self.z - other.z)
elif isinstance(other, Vector3D):
return Point3D(self.x - other.x, self.y - other.y, self.z - other.z)
elif isinstance(other, Point3D):
Vector3D(self.x - other.x, self.y - other.y, self.z - other.z)
else:
raise TypeError('Cannot subtract Point3D and {}'.format(type(other)))

Expand Down

0 comments on commit 77b15bb

Please sign in to comment.