Skip to content

Commit

Permalink
Merge pull request #154 from chris-greening/add-translate-method
Browse files Browse the repository at this point in the history
Add translate method
  • Loading branch information
chris-greening authored Apr 10, 2023
2 parents 0b06924 + abc4996 commit 1d26dec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setuptools.setup(
name="spyrograph",
version="0.25.3",
version="0.26.0",
author="Chris Greening",
author_email="chris@christophergreening.com",
description="Library for drawing spirographs in Python",
Expand Down
8 changes: 4 additions & 4 deletions spyrograph/core/_trochoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(

self.coords = list(zip(self.x, self.y, self.thetas))

def transform(self, x: Number = 0, y: Number = 0) -> "_Trochoid":
def translate(self, x: Number = 0, y: Number = 0) -> "_Trochoid":
"""
Return a new shape translated by the given x and y offsets.
Expand All @@ -113,21 +113,21 @@ def transform(self, x: Number = 0, y: Number = 0) -> "_Trochoid":
"""
# pylint: disable=no-value-for-parameter
try:
transformed_shape = self.__class__(
translated_shape = self.__class__(
R=self.R,
r=self.r,
d=self.d,
thetas=self.thetas,
origin=(self.origin[0]+x, self.origin[1]+y)
)
except TypeError:
transformed_shape = self.__class__(
translated_shape = self.__class__(
R=self.R,
r=self.r,
thetas=self.thetas,
origin=(self.origin[0]+x, self.origin[1]+y)
)
return transformed_shape
return translated_shape

def scale(self, factor: Number) -> Union["_Trochoid", "_Cycloid"]:
"""Return shape with input parameters scaled by a given input factor.
Expand Down
36 changes: 18 additions & 18 deletions tests/_trochoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,28 @@ def test_dunder_repr_doesnt_break_on_repr_call(self, instance):
repr_val = repr(instance)
assert isinstance(repr_val, str)

def test_transform_float_offset(self, instance):
up_and_left_transform_instance = instance.transform(x=100.33, y=-100.69)
assert instance.origin[0] + 100.33 == up_and_left_transform_instance.origin[0]
assert instance.origin[1] - 100.69 == up_and_left_transform_instance.origin[1]
def test_translate_float_offset(self, instance):
up_and_left_translate_instance = instance.translate(x=100.33, y=-100.69)
assert instance.origin[0] + 100.33 == up_and_left_translate_instance.origin[0]
assert instance.origin[1] - 100.69 == up_and_left_translate_instance.origin[1]

def test_transform_zero_offset(self, instance):
zero_transformed_instance = instance.transform(x=0, y=0)
assert instance.origin[0] == zero_transformed_instance.origin[0]
assert instance.origin[1] == zero_transformed_instance.origin[1]
def test_translate_zero_offset(self, instance):
zero_translateed_instance = instance.translate(x=0, y=0)
assert instance.origin[0] == zero_translateed_instance.origin[0]
assert instance.origin[1] == zero_translateed_instance.origin[1]

def test_transform_shape_x_direction(self, instance):
left_transformed_instance = instance.transform(x=-100)
assert instance.origin[0] - 100 == left_transformed_instance.origin[0]
def test_translate_shape_x_direction(self, instance):
left_translateed_instance = instance.translate(x=-100)
assert instance.origin[0] - 100 == left_translateed_instance.origin[0]

def test_transform_shape_y_direction(self, instance):
up_transformed_instance = instance.transform(y=100)
assert instance.origin[1] + 100 == up_transformed_instance.origin[1]
def test_translate_shape_y_direction(self, instance):
up_translateed_instance = instance.translate(y=100)
assert instance.origin[1] + 100 == up_translateed_instance.origin[1]

def test_transform_shape_x_and_y_same_transform_call(self, instance):
up_and_left_transform_instance = instance.transform(x=100, y=-100)
assert instance.origin[0] + 100 == up_and_left_transform_instance.origin[0]
assert instance.origin[1] - 100 == up_and_left_transform_instance.origin[1]
def test_translate_shape_x_and_y_same_translate_call(self, instance):
up_and_left_translate_instance = instance.translate(x=100, y=-100)
assert instance.origin[0] + 100 == up_and_left_translate_instance.origin[0]
assert instance.origin[1] - 100 == up_and_left_translate_instance.origin[1]

def test_dunder_repr_values(self, instance):
repr_val = repr(instance)
Expand Down

0 comments on commit 1d26dec

Please sign in to comment.