From ee656c7de049d415962ecb9f2ac12a7fd8205d28 Mon Sep 17 00:00:00 2001 From: Orion Elenzil Date: Wed, 30 May 2018 10:54:56 -0700 Subject: [PATCH] refactor `scale()` and `scaled()` to `scale_uniform()` and `scaled_uniform()` --- svgpathtools/path.py | 28 ++++++++++++++-------------- test/test_path.py | 6 +++--- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/svgpathtools/path.py b/svgpathtools/path.py index 27bb4d5..8108042 100644 --- a/svgpathtools/path.py +++ b/svgpathtools/path.py @@ -207,10 +207,10 @@ def translate(curve, z0): "QuadraticBezier, CubicBezier, or Arc object.") -def scale(curve, factor, origin=0j): - """Scales `curve` by scalar `factor` around `origin`. +def scale_uniform(curve, factor, origin=0j): + """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 """ @@ -218,7 +218,7 @@ def scale(curve, factor, origin=0j): return ((z - origin) * s) + origin 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): return bpoints2bezier([_scale_point(bpt, factor, origin) for bpt in curve.bpoints()]) elif isinstance(curve, Arc): @@ -661,9 +661,9 @@ class Line(object): that self.translated(z0).point(t) = self.point(t) + z0 for any t.""" 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`.""" - return scale(self, factor, origin=origin) + return scale_uniform(self, factor, origin=origin) class QuadraticBezier(object): @@ -909,9 +909,9 @@ class QuadraticBezier(object): that self.translated(z0).point(t) = self.point(t) + z0 for any t.""" 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`.""" - return scale(self, factor, origin=origin) + return scale_uniform(self, factor, origin=origin) class CubicBezier(object): @@ -1153,9 +1153,9 @@ class CubicBezier(object): that self.translated(z0).point(t) = self.point(t) + z0 for any t.""" 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`.""" - return scale(self, factor, origin=origin) + return scale_uniform(self, factor, origin=origin) class Arc(object): @@ -1722,9 +1722,9 @@ class Arc(object): that self.translated(z0).point(t) = self.point(t) + z0 for any t.""" 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`.""" - return scale(self, factor, origin=origin) + return scale_uniform(self, factor, origin=origin) 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.""" 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`.""" - return scale(self, factor, origin=origin) + return scale_uniform(self, factor, origin=origin) diff --git a/test/test_path.py b/test/test_path.py index b8df0de..8e5cc24 100644 --- a/test/test_path.py +++ b/test/test_path.py @@ -726,7 +726,7 @@ class TestPath(unittest.TestCase): with self.assertRaises(AssertionError): p_open.cropped(1, 0) - def test_transform_scale(self): + def test_transform_scale_uniform(self): line1 = Line(600 + 350j, 650 + 325j) arc1 = Arc(650 + 325j, 25 + 25j, -30, 0, 1, 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: # 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 len_orig = path_orig.length() @@ -776,7 +776,7 @@ class TestPath(unittest.TestCase): # scale by 0.3 around (0, -100) # the 'almost equal' test fails at the 7th decimal place for # 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 len_orig = path_orig.length()