refactor `scale()` and `scaled()` to `scale_uniform()` and `scaled_uniform()`
parent
0827206953
commit
ee656c7de0
|
@ -207,10 +207,10 @@ def translate(curve, z0):
|
||||||
"QuadraticBezier, CubicBezier, or Arc object.")
|
"QuadraticBezier, CubicBezier, or Arc object.")
|
||||||
|
|
||||||
|
|
||||||
def scale(curve, factor, origin=0j):
|
def scale_uniform(curve, factor, origin=0j):
|
||||||
"""Scales `curve` by scalar `factor` around `origin`.
|
"""Uniformly scales `curve` by scalar `factor` around `origin`.
|
||||||
|
|
||||||
Note: scale(curve, s, origin).point(t) ==
|
Note: scale_uniform(curve, s, origin).point(t) ==
|
||||||
((curve.point(t) - origin) * factor) + origin
|
((curve.point(t) - origin) * factor) + origin
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -218,7 +218,7 @@ def scale(curve, factor, origin=0j):
|
||||||
return ((z - origin) * s) + origin
|
return ((z - origin) * s) + origin
|
||||||
|
|
||||||
if isinstance(curve, Path):
|
if isinstance(curve, Path):
|
||||||
return Path(*[scale(seg, factor, origin) for seg in curve])
|
return Path(*[scale_uniform(seg, factor, origin) for seg in curve])
|
||||||
elif is_bezier_segment(curve):
|
elif is_bezier_segment(curve):
|
||||||
return bpoints2bezier([_scale_point(bpt, factor, origin) for bpt in curve.bpoints()])
|
return bpoints2bezier([_scale_point(bpt, factor, origin) for bpt in curve.bpoints()])
|
||||||
elif isinstance(curve, Arc):
|
elif isinstance(curve, Arc):
|
||||||
|
@ -661,9 +661,9 @@ class Line(object):
|
||||||
that self.translated(z0).point(t) = self.point(t) + z0 for any t."""
|
that self.translated(z0).point(t) = self.point(t) + z0 for any t."""
|
||||||
return translate(self, z0)
|
return translate(self, z0)
|
||||||
|
|
||||||
def scaled(self, factor, origin=None):
|
def scaled_uniform(self, factor, origin=None):
|
||||||
"""Returns copy of self scaled by `factor` about `origin`."""
|
"""Returns copy of self scaled by `factor` about `origin`."""
|
||||||
return scale(self, factor, origin=origin)
|
return scale_uniform(self, factor, origin=origin)
|
||||||
|
|
||||||
|
|
||||||
class QuadraticBezier(object):
|
class QuadraticBezier(object):
|
||||||
|
@ -909,9 +909,9 @@ class QuadraticBezier(object):
|
||||||
that self.translated(z0).point(t) = self.point(t) + z0 for any t."""
|
that self.translated(z0).point(t) = self.point(t) + z0 for any t."""
|
||||||
return translate(self, z0)
|
return translate(self, z0)
|
||||||
|
|
||||||
def scaled(self, factor, origin=None):
|
def scaled_uniform(self, factor, origin=None):
|
||||||
"""Returns copy of self scaled by `factor` about `origin`."""
|
"""Returns copy of self scaled by `factor` about `origin`."""
|
||||||
return scale(self, factor, origin=origin)
|
return scale_uniform(self, factor, origin=origin)
|
||||||
|
|
||||||
|
|
||||||
class CubicBezier(object):
|
class CubicBezier(object):
|
||||||
|
@ -1153,9 +1153,9 @@ class CubicBezier(object):
|
||||||
that self.translated(z0).point(t) = self.point(t) + z0 for any t."""
|
that self.translated(z0).point(t) = self.point(t) + z0 for any t."""
|
||||||
return translate(self, z0)
|
return translate(self, z0)
|
||||||
|
|
||||||
def scaled(self, factor, origin=None):
|
def scaled_uniform(self, factor, origin=None):
|
||||||
"""Returns copy of self scaled by `factor` about `origin`."""
|
"""Returns copy of self scaled by `factor` about `origin`."""
|
||||||
return scale(self, factor, origin=origin)
|
return scale_uniform(self, factor, origin=origin)
|
||||||
|
|
||||||
|
|
||||||
class Arc(object):
|
class Arc(object):
|
||||||
|
@ -1722,9 +1722,9 @@ class Arc(object):
|
||||||
that self.translated(z0).point(t) = self.point(t) + z0 for any t."""
|
that self.translated(z0).point(t) = self.point(t) + z0 for any t."""
|
||||||
return translate(self, z0)
|
return translate(self, z0)
|
||||||
|
|
||||||
def scaled(self, factor, origin=None):
|
def scaled_uniform(self, factor, origin=None):
|
||||||
"""Returns copy of self scaled by `factor` about `origin`."""
|
"""Returns copy of self scaled by `factor` about `origin`."""
|
||||||
return scale(self, factor, origin=origin)
|
return scale_uniform(self, factor, origin=origin)
|
||||||
|
|
||||||
|
|
||||||
def is_bezier_segment(x):
|
def is_bezier_segment(x):
|
||||||
|
@ -2283,6 +2283,6 @@ class Path(MutableSequence):
|
||||||
that self.translated(z0).point(t) = self.point(t) + z0 for any t."""
|
that self.translated(z0).point(t) = self.point(t) + z0 for any t."""
|
||||||
return translate(self, z0)
|
return translate(self, z0)
|
||||||
|
|
||||||
def scaled(self, factor, origin=None):
|
def scaled_uniform(self, factor, origin=None):
|
||||||
"""Returns copy of self scaled by `factor` about `origin`."""
|
"""Returns copy of self scaled by `factor` about `origin`."""
|
||||||
return scale(self, factor, origin=origin)
|
return scale_uniform(self, factor, origin=origin)
|
||||||
|
|
|
@ -726,7 +726,7 @@ class TestPath(unittest.TestCase):
|
||||||
with self.assertRaises(AssertionError):
|
with self.assertRaises(AssertionError):
|
||||||
p_open.cropped(1, 0)
|
p_open.cropped(1, 0)
|
||||||
|
|
||||||
def test_transform_scale(self):
|
def test_transform_scale_uniform(self):
|
||||||
line1 = Line(600 + 350j, 650 + 325j)
|
line1 = Line(600 + 350j, 650 + 325j)
|
||||||
arc1 = Arc(650 + 325j, 25 + 25j, -30, 0, 1, 700 + 300j)
|
arc1 = Arc(650 + 325j, 25 + 25j, -30, 0, 1, 700 + 300j)
|
||||||
cub1 = CubicBezier(650 + 325j, 25 + 25j, -30, 700 + 300j)
|
cub1 = CubicBezier(650 + 325j, 25 + 25j, -30, 700 + 300j)
|
||||||
|
@ -757,7 +757,7 @@ class TestPath(unittest.TestCase):
|
||||||
for path_orig in test_paths:
|
for path_orig in test_paths:
|
||||||
|
|
||||||
# scale by 2 around (100, 100)
|
# scale by 2 around (100, 100)
|
||||||
path_trns = path_orig.scaled(2.0, complex(100, 100))
|
path_trns = path_orig.scaled_uniform(2.0, complex(100, 100))
|
||||||
|
|
||||||
# expected length
|
# expected length
|
||||||
len_orig = path_orig.length()
|
len_orig = path_orig.length()
|
||||||
|
@ -776,7 +776,7 @@ class TestPath(unittest.TestCase):
|
||||||
# scale by 0.3 around (0, -100)
|
# scale by 0.3 around (0, -100)
|
||||||
# the 'almost equal' test fails at the 7th decimal place for
|
# the 'almost equal' test fails at the 7th decimal place for
|
||||||
# some length and position tests here.
|
# some length and position tests here.
|
||||||
path_trns = path_orig.scaled(0.3, complex(0, -100))
|
path_trns = path_orig.scaled_uniform(0.3, complex(0, -100))
|
||||||
|
|
||||||
# expected length
|
# expected length
|
||||||
len_orig = path_orig.length()
|
len_orig = path_orig.length()
|
||||||
|
|
Loading…
Reference in New Issue