Skip to content

Commit 2d4f62e

Browse files
committed
Fix types
1 parent 373746f commit 2d4f62e

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

coloraide/algebra.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,8 @@ def __call__(self, t: float) -> Vector:
820820
return self.run(i, t)
821821

822822

823-
class CatmullRomInterpolator(Interpolator):
824-
"""Catrom-Mull interpolator."""
823+
class _CubicInterpolator(Interpolator):
824+
"""Cubic interpolator."""
825825

826826
@classmethod
827827
def preprocess(cls, points: list[Vector]) -> None:
@@ -832,19 +832,9 @@ def preprocess(cls, points: list[Vector]) -> None:
832832

833833
@staticmethod
834834
def interpolate(p0: float, p1: float, p2: float, p3: float, t: float) -> float:
835-
"""Calculate the new point using the provided values."""
835+
"""Interpolate."""
836836

837-
# Save some time calculating this once
838-
t2 = t ** 2
839-
t3 = t2 * t
840-
841-
# Insert control points to algorithm
842-
return (
843-
(-t3 + 2 * t2 - t) * p0 + # B0
844-
(3 * t3 - 5 * t2 + 2) * p1 + # B1
845-
(-3 * t3 + 4 * t2 + t) * p2 + # B2
846-
(t3 - t2) * p3 # B3
847-
) / 2
837+
raise NotImplementedError('This function is not implemented')
848838

849839
def run(self, i: int, t: float) -> Vector:
850840
"""Begin interpolation."""
@@ -867,7 +857,28 @@ def run(self, i: int, t: float) -> Vector:
867857
return coord
868858

869859

870-
class MonotoneInterpolator(CatmullRomInterpolator):
860+
861+
class CatmullRomInterpolator(_CubicInterpolator):
862+
"""Catrom-Mull interpolator."""
863+
864+
@staticmethod
865+
def interpolate(p0: float, p1: float, p2: float, p3: float, t: float) -> float:
866+
"""Calculate the new point using the provided values."""
867+
868+
# Save some time calculating this once
869+
t2 = t ** 2
870+
t3 = t2 * t
871+
872+
# Insert control points to algorithm
873+
return (
874+
(-t3 + 2 * t2 - t) * p0 + # B0
875+
(3 * t3 - 5 * t2 + 2) * p1 + # B1
876+
(-3 * t3 + 4 * t2 + t) * p2 + # B2
877+
(t3 - t2) * p3 # B3
878+
) / 2
879+
880+
881+
class MonotoneInterpolator(_CubicInterpolator):
871882
"""Monotone interpolator."""
872883

873884
@staticmethod
@@ -945,7 +956,7 @@ def interpolate(p0: float, p1: float, p2: float, p3: float, t: float) -> float:
945956
return min(max(result, mn), mx)
946957

947958

948-
class BSplineInterpolator(CatmullRomInterpolator):
959+
class BSplineInterpolator(_CubicInterpolator):
949960
"""B-Spline Interpolator."""
950961

951962
@staticmethod

coloraide/interpolate/bspline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def setup(self) -> None:
2121

2222
# Process undefined values
2323
self.handle_undefined()
24-
self.spline = alg.BSplineInterpolator
24+
self.spline = alg.BSplineInterpolator # type: type[alg._CubicInterpolator]
2525
self.spline.preprocess(self.coordinates)
2626

2727
def interpolate(

0 commit comments

Comments
 (0)