style changes
parent
eafe3682b9
commit
0827206953
|
@ -169,7 +169,7 @@ def rotate(curve, degs, origin=None):
|
||||||
def transform(z):
|
def transform(z):
|
||||||
return exp(1j*radians(degs))*(z - origin) + origin
|
return exp(1j*radians(degs))*(z - origin) + origin
|
||||||
|
|
||||||
if origin == None:
|
if origin is None:
|
||||||
if isinstance(curve, Arc):
|
if isinstance(curve, Arc):
|
||||||
origin = curve.center
|
origin = curve.center
|
||||||
else:
|
else:
|
||||||
|
@ -206,23 +206,25 @@ def translate(curve, z0):
|
||||||
raise TypeError("Input `curve` should be a Path, Line, "
|
raise TypeError("Input `curve` should be a Path, Line, "
|
||||||
"QuadraticBezier, CubicBezier, or Arc object.")
|
"QuadraticBezier, CubicBezier, or Arc object.")
|
||||||
|
|
||||||
def scale(curve, s, origin=None):
|
|
||||||
"""Scales the curve by the factor s around the origin such that
|
def scale(curve, factor, origin=0j):
|
||||||
scale(curve, s, origin).point(t) = ((curve.point(t) - origin) * s) + origin"""
|
"""Scales `curve` by scalar `factor` around `origin`.
|
||||||
|
|
||||||
|
Note: scale(curve, s, origin).point(t) ==
|
||||||
|
((curve.point(t) - origin) * factor) + origin
|
||||||
|
"""
|
||||||
|
|
||||||
def _scale_point(z, s, origin):
|
def _scale_point(z, s, origin):
|
||||||
return ((z - origin) * s) + origin
|
return ((z - origin) * s) + origin
|
||||||
|
|
||||||
if origin == None:
|
|
||||||
origin = 0 + 0j
|
|
||||||
if isinstance(curve, Path):
|
if isinstance(curve, Path):
|
||||||
return Path(*[scale(seg, s, origin) for seg in curve])
|
return Path(*[scale(seg, factor, origin) for seg in curve])
|
||||||
elif is_bezier_segment(curve):
|
elif is_bezier_segment(curve):
|
||||||
return bpoints2bezier([_scale_point(bpt, s, 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):
|
||||||
new_start = _scale_point(curve.start, s, origin)
|
new_start = _scale_point(curve.start, factor, origin)
|
||||||
new_end = _scale_point(curve.end, s, origin)
|
new_end = _scale_point(curve.end, factor, origin)
|
||||||
return Arc(new_start, radius=curve.radius * s, rotation=curve.rotation,
|
return Arc(new_start, radius=curve.radius * factor, rotation=curve.rotation,
|
||||||
large_arc=curve.large_arc, sweep=curve.sweep, end=new_end)
|
large_arc=curve.large_arc, sweep=curve.sweep, end=new_end)
|
||||||
else:
|
else:
|
||||||
raise TypeError("Input `curve` should be a Path, Line, "
|
raise TypeError("Input `curve` should be a Path, Line, "
|
||||||
|
@ -660,7 +662,7 @@ class Line(object):
|
||||||
return translate(self, z0)
|
return translate(self, z0)
|
||||||
|
|
||||||
def scaled(self, factor, origin=None):
|
def scaled(self, factor, origin=None):
|
||||||
"""Returns a copy of self scaled by the scalar `factor`, about the complex point `origin`."""
|
"""Returns copy of self scaled by `factor` about `origin`."""
|
||||||
return scale(self, factor, origin=origin)
|
return scale(self, factor, origin=origin)
|
||||||
|
|
||||||
|
|
||||||
|
@ -908,7 +910,7 @@ class QuadraticBezier(object):
|
||||||
return translate(self, z0)
|
return translate(self, z0)
|
||||||
|
|
||||||
def scaled(self, factor, origin=None):
|
def scaled(self, factor, origin=None):
|
||||||
"""Returns a copy of self scaled by the scalar `factor`, about the complex point `origin`."""
|
"""Returns copy of self scaled by `factor` about `origin`."""
|
||||||
return scale(self, factor, origin=origin)
|
return scale(self, factor, origin=origin)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1152,7 +1154,7 @@ class CubicBezier(object):
|
||||||
return translate(self, z0)
|
return translate(self, z0)
|
||||||
|
|
||||||
def scaled(self, factor, origin=None):
|
def scaled(self, factor, origin=None):
|
||||||
"""Returns a copy of self scaled by the scalar `factor`, about the complex point `origin`."""
|
"""Returns copy of self scaled by `factor` about `origin`."""
|
||||||
return scale(self, factor, origin=origin)
|
return scale(self, factor, origin=origin)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1721,9 +1723,10 @@ class Arc(object):
|
||||||
return translate(self, z0)
|
return translate(self, z0)
|
||||||
|
|
||||||
def scaled(self, factor, origin=None):
|
def scaled(self, factor, origin=None):
|
||||||
"""Returns a copy of self scaled by the scalar `factor`, about the complex point `origin`."""
|
"""Returns copy of self scaled by `factor` about `origin`."""
|
||||||
return scale(self, factor, origin=origin)
|
return scale(self, factor, origin=origin)
|
||||||
|
|
||||||
|
|
||||||
def is_bezier_segment(x):
|
def is_bezier_segment(x):
|
||||||
return (isinstance(x, Line) or
|
return (isinstance(x, Line) or
|
||||||
isinstance(x, QuadraticBezier) or
|
isinstance(x, QuadraticBezier) or
|
||||||
|
@ -2281,5 +2284,5 @@ class Path(MutableSequence):
|
||||||
return translate(self, z0)
|
return translate(self, z0)
|
||||||
|
|
||||||
def scaled(self, factor, origin=None):
|
def scaled(self, factor, origin=None):
|
||||||
"""Returns a copy of self scaled by the scalar `factor`, about the complex point `origin`."""
|
"""Returns copy of self scaled by `factor` about `origin`."""
|
||||||
return scale(self, factor, origin=origin)
|
return scale(self, factor, origin=origin)
|
||||||
|
|
Loading…
Reference in New Issue