diff --git a/.pylintrc b/.pylintrc index 06dc518..730d6a5 100644 --- a/.pylintrc +++ b/.pylintrc @@ -198,7 +198,8 @@ good-names=i, d, ax, R, - r + r, + n # Good variable names regexes, separated by a comma. If names match any regex, # they will always be accepted diff --git a/setup.py b/setup.py index 9ec900e..e80425d 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ setuptools.setup( name="spyrograph", - version="0.13.0", + version="0.14.0", author="Chris Greening", author_email="chris@christophergreening.com", description="Library for drawing spirographs in Python", diff --git a/spyrograph/_cycloid.py b/spyrograph/_cycloid.py new file mode 100644 index 0000000..c86d347 --- /dev/null +++ b/spyrograph/_cycloid.py @@ -0,0 +1,25 @@ +"""Abstract base class for generalizing the hypocycloid and epicycloid +shape's methods i.e. tracing, calculating, etc. +""" + +from abc import ABC +from numbers import Number +from typing import List + +class _Cycloid(ABC): + # pylint: disable=too-few-public-methods + @classmethod + def n_cusps( + cls, R: Number, n: int, thetas: List[Number] = None, + theta_start: Number = None, theta_stop: Number = None, + theta_step: Number = None + ) -> "Cycloid": + """Return a cycloid with n number of cusps""" + return cls( + R=R, + r=R/n, + thetas=thetas, + theta_start=theta_start, + theta_stop=theta_stop, + theta_step=theta_step + ) diff --git a/spyrograph/_roulette.py b/spyrograph/_trochoid.py similarity index 99% rename from spyrograph/_roulette.py rename to spyrograph/_trochoid.py index 74643a7..44d5e35 100644 --- a/spyrograph/_roulette.py +++ b/spyrograph/_trochoid.py @@ -22,7 +22,7 @@ except ImportError: pd = None -class _Roulette(ABC): +class _Trochoid(ABC): def __init__( self, R: Number, r: Number, d: Number, thetas: List[Number] = None, theta_start: Number = None, theta_stop: Number = None, diff --git a/spyrograph/epitrochoid/__init__.py b/spyrograph/epitrochoid/__init__.py index e187036..761ed42 100644 --- a/spyrograph/epitrochoid/__init__.py +++ b/spyrograph/epitrochoid/__init__.py @@ -2,6 +2,6 @@ from spyrograph.epitrochoid.epitrochoid import Epitrochoid from spyrograph.epitrochoid.epicycloid import Epicycloid -from spyrograph.epitrochoid.cardioid import Cardioid -from spyrograph.epitrochoid.nephroid import Nephroid -from spyrograph.epitrochoid.ranuncloid import Ranuncloid +from spyrograph.epitrochoid.special.cardioid import Cardioid +from spyrograph.epitrochoid.special.nephroid import Nephroid +from spyrograph.epitrochoid.special.ranuncloid import Ranuncloid diff --git a/spyrograph/epitrochoid/epicycloid.py b/spyrograph/epitrochoid/epicycloid.py index 1de3532..004e3e8 100644 --- a/spyrograph/epitrochoid/epicycloid.py +++ b/spyrograph/epitrochoid/epicycloid.py @@ -6,8 +6,9 @@ from numbers import Number from spyrograph.epitrochoid.epitrochoid import Epitrochoid +from spyrograph._cycloid import _Cycloid -class Epicycloid(Epitrochoid): +class Epicycloid(_Cycloid, Epitrochoid): """Model of a epicycloid which is a special case of a epitrochoid where the circle is rolling around the outside of the fixed circle and has 1/3 the radius of the fixed circle diff --git a/spyrograph/epitrochoid/epitrochoid.py b/spyrograph/epitrochoid/epitrochoid.py index 92f431a..cb2947c 100644 --- a/spyrograph/epitrochoid/epitrochoid.py +++ b/spyrograph/epitrochoid/epitrochoid.py @@ -5,9 +5,9 @@ import math from numbers import Number -from spyrograph._roulette import _Roulette +from spyrograph._trochoid import _Trochoid -class Epitrochoid(_Roulette): +class Epitrochoid(_Trochoid): """Model of a epitrochoid""" def _circle_offset(self) -> Number: """Return rolling circle offset from fixed circle""" diff --git a/spyrograph/epitrochoid/special/__init__.py b/spyrograph/epitrochoid/special/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/spyrograph/epitrochoid/cardioid.py b/spyrograph/epitrochoid/special/cardioid.py similarity index 100% rename from spyrograph/epitrochoid/cardioid.py rename to spyrograph/epitrochoid/special/cardioid.py diff --git a/spyrograph/epitrochoid/nephroid.py b/spyrograph/epitrochoid/special/nephroid.py similarity index 100% rename from spyrograph/epitrochoid/nephroid.py rename to spyrograph/epitrochoid/special/nephroid.py diff --git a/spyrograph/epitrochoid/ranuncloid.py b/spyrograph/epitrochoid/special/ranuncloid.py similarity index 100% rename from spyrograph/epitrochoid/ranuncloid.py rename to spyrograph/epitrochoid/special/ranuncloid.py diff --git a/spyrograph/hypotrochoid/__init__.py b/spyrograph/hypotrochoid/__init__.py index 2f2fe9d..a0a17e8 100644 --- a/spyrograph/hypotrochoid/__init__.py +++ b/spyrograph/hypotrochoid/__init__.py @@ -2,7 +2,7 @@ from spyrograph.hypotrochoid.hypotrochoid import Hypotrochoid from spyrograph.hypotrochoid.hypocycloid import Hypocycloid -from spyrograph.hypotrochoid.deltoid import Deltoid -from spyrograph.hypotrochoid.astroid import Astroid -from spyrograph.hypotrochoid.ellipse import Ellipse -from spyrograph.hypotrochoid.tusi_couple import TusiCouple +from spyrograph.hypotrochoid.special.deltoid import Deltoid +from spyrograph.hypotrochoid.special.astroid import Astroid +from spyrograph.hypotrochoid.special.ellipse import Ellipse +from spyrograph.hypotrochoid.special.tusi_couple import TusiCouple diff --git a/spyrograph/hypotrochoid/hypocycloid.py b/spyrograph/hypotrochoid/hypocycloid.py index 7601dc7..240d60a 100644 --- a/spyrograph/hypotrochoid/hypocycloid.py +++ b/spyrograph/hypotrochoid/hypocycloid.py @@ -6,8 +6,9 @@ from numbers import Number from spyrograph.hypotrochoid.hypotrochoid import Hypotrochoid +from spyrograph._cycloid import _Cycloid -class Hypocycloid(Hypotrochoid): +class Hypocycloid(_Cycloid, Hypotrochoid): """Model of a hypocycloid which is a special case of a hypotrochoid where the circle is rolling around the inside of the fixed circle and has 1/3 the radius of the fixed circle diff --git a/spyrograph/hypotrochoid/hypotrochoid.py b/spyrograph/hypotrochoid/hypotrochoid.py index 500175c..677a999 100644 --- a/spyrograph/hypotrochoid/hypotrochoid.py +++ b/spyrograph/hypotrochoid/hypotrochoid.py @@ -5,9 +5,9 @@ import math from numbers import Number -from spyrograph._roulette import _Roulette +from spyrograph._trochoid import _Trochoid -class Hypotrochoid(_Roulette): +class Hypotrochoid(_Trochoid): """Model of a hypotrochoid""" def _circle_offset(self) -> Number: """Return rolling circle offset from fixed circle""" diff --git a/spyrograph/hypotrochoid/special/__init__.py b/spyrograph/hypotrochoid/special/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/spyrograph/hypotrochoid/astroid.py b/spyrograph/hypotrochoid/special/astroid.py similarity index 100% rename from spyrograph/hypotrochoid/astroid.py rename to spyrograph/hypotrochoid/special/astroid.py diff --git a/spyrograph/hypotrochoid/deltoid.py b/spyrograph/hypotrochoid/special/deltoid.py similarity index 100% rename from spyrograph/hypotrochoid/deltoid.py rename to spyrograph/hypotrochoid/special/deltoid.py diff --git a/spyrograph/hypotrochoid/ellipse.py b/spyrograph/hypotrochoid/special/ellipse.py similarity index 100% rename from spyrograph/hypotrochoid/ellipse.py rename to spyrograph/hypotrochoid/special/ellipse.py diff --git a/spyrograph/hypotrochoid/tusi_couple.py b/spyrograph/hypotrochoid/special/tusi_couple.py similarity index 100% rename from spyrograph/hypotrochoid/tusi_couple.py rename to spyrograph/hypotrochoid/special/tusi_couple.py diff --git a/tests/_roulette.py b/tests/_roulette.py index f840c14..8ffd3b1 100644 --- a/tests/_roulette.py +++ b/tests/_roulette.py @@ -121,3 +121,13 @@ def test_multiple_thetas_exception(self, thetas: "np.array") -> None: def test_rolling_radius_equals_distance(self, instance): """Test radius of rolling circle is equal to distance""" assert instance.r == instance.d + + def test_n_cusps(self, thetas): + """Test the n cusps factory method""" + for n in range(2, 5): + obj = self.class_name.n_cusps( + R = 300, + n = n, + thetas = thetas + ) + assert obj.r == obj.R/n \ No newline at end of file