Skip to content

Commit

Permalink
Merge pull request #53 from chris-greening/add-cycloid-cusp-routine
Browse files Browse the repository at this point in the history
Add cusp routine factory method
  • Loading branch information
chris-greening authored Mar 18, 2023
2 parents 7505da4 + 6de4dac commit 3d2df5c
Show file tree
Hide file tree
Showing 20 changed files with 54 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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.13.0",
version="0.14.0",
author="Chris Greening",
author_email="chris@christophergreening.com",
description="Library for drawing spirographs in Python",
Expand Down
25 changes: 25 additions & 0 deletions spyrograph/_cycloid.py
Original file line number Diff line number Diff line change
@@ -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
)
2 changes: 1 addition & 1 deletion spyrograph/_roulette.py → spyrograph/_trochoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions spyrograph/epitrochoid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion spyrograph/epitrochoid/epicycloid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spyrograph/epitrochoid/epitrochoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions spyrograph/hypotrochoid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion spyrograph/hypotrochoid/hypocycloid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spyrograph/hypotrochoid/hypotrochoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions tests/_roulette.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3d2df5c

Please sign in to comment.