diff --git a/setup.cfg b/setup.cfg index 35b25833..74dbb6a1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = svgelements -version = 1.4.3 +version = 1.4.5 description = Svg Elements Parsing long_description_content_type=text/markdown long_description = file: README.md diff --git a/svgelements/svgelements.py b/svgelements/svgelements.py index 97e34049..91f64c71 100644 --- a/svgelements/svgelements.py +++ b/svgelements/svgelements.py @@ -7,13 +7,15 @@ except ImportError: from collections import MutableSequence # noqa from copy import copy -from math import * + +from math import ceil, cos, radians, sin, sqrt, hypot, atan, atan2, tan, degrees, acos, log from xml.etree.ElementTree import iterparse try: from math import tau except ImportError: + from math import pi tau = pi * 2 """ @@ -28,7 +30,7 @@ and the Arc can do exact arc calculations if scipy is installed. """ -SVGELEMENTS_VERSION = "1.4.3" +SVGELEMENTS_VERSION = "1.4.5" MIN_DEPTH = 5 ERROR = 1e-12 @@ -993,6 +995,12 @@ def __eq__(self, other): def __ne__(self, other): return not self == other + def __abs__(self): + # Return opaque color. + if self.value is None: + return Color(self.value) + return Color(self.red, self.green, self.blue) + @staticmethod def rgb_to_int(r, g, b, opacity=1.0): if opacity > 1: @@ -2184,7 +2192,7 @@ def as_turns(self): return self / tau def is_orthogonal(self): - return (self % (tau / 4)) == 0 + return (self % (tau / 4.0)) == 0 class Matrix: @@ -4209,7 +4217,7 @@ def __init__(self, *args, **kwargs): if sagitta is not None: control = Point.towards(self.start, self.end, 0.5) angle = self.start.angle_to(self.end) - control = control.polar_to(angle - tau / 4, sagitta) + control = control.polar_to(angle - tau / 4.0, sagitta) if 'control' in kwargs: # Control is any additional point on the arc. control = Point(kwargs['control']) if control is not None: @@ -4595,7 +4603,7 @@ def _svg_parameterize(self, start, rx, ry, rotation, large_arc_flag, sweep_flag, def as_quad_curves(self, arc_required): if arc_required is None: - sweep_limit = tau / 12 + sweep_limit = tau / 12.0 arc_required = int(ceil(abs(self.sweep) / sweep_limit)) if arc_required == 0: return @@ -4630,7 +4638,7 @@ def as_quad_curves(self, arc_required): def as_cubic_curves(self, arc_required=None): if arc_required is None: - sweep_limit = tau / 12 + sweep_limit = tau / 12.0 arc_required = int(ceil(abs(self.sweep) / sweep_limit)) if arc_required == 0: return @@ -4745,7 +4753,7 @@ def point_at_angle(self, angle): tau_1_4 = tau / 4.0 tau_3_4 = 3 * tau_1_4 if tau_3_4 >= abs(angle) % tau > tau_1_4: - t += tau / 2 + t += tau / 2.0 return self.point_at_t(t) def angle_at_point(self, p): @@ -4772,7 +4780,7 @@ def t_at_point(self, p): tau_1_4 = tau / 4.0 tau_3_4 = 3 * tau_1_4 if tau_3_4 >= abs(angle) % tau > tau_1_4: - t += tau / 2 + t += tau / 2.0 return t def point_at_t(self, t): @@ -4807,18 +4815,18 @@ def bbox(self): """ phi = self.get_rotation().as_radians if cos(phi) == 0: - atan_x = pi / 2 + atan_x = tau / 4.0 atan_y = 0 elif sin(phi) == 0: atan_x = 0 - atan_y = pi / 2 + atan_y = tau / 4.0 else: rx, ry = self.rx, self.ry atan_x = atan(-(ry / rx) * tan(phi)) atan_y = atan((ry / rx) / tan(phi)) def angle_inv(ang, k): # inverse of angle from Arc.derivative() - return ((ang + pi * k) * (360 / (2 * pi)) - self.theta) / self.delta + return ((ang + (tau/2.0) * k) * (360 / tau) - self.theta) / self.delta xtrema = [self.start.x, self.end.x] ytrema = [self.start.y, self.end.y] @@ -6062,7 +6070,7 @@ def point_at_angle(self, angle): tau_1_4 = tau / 4.0 tau_3_4 = 3 * tau_1_4 if tau_3_4 >= abs(angle) % tau > tau_1_4: - t += tau / 2 + t += tau / 2.0 return self.point_at_t(t) def angle_at_point(self, p): @@ -6093,7 +6101,7 @@ def t_at_point(self, p): tau_1_4 = tau / 4.0 tau_3_4 = 3 * tau_1_4 if tau_3_4 >= abs(angle) % tau > tau_1_4: - t += tau / 2 + t += tau / 2.0 return t def point_at_t(self, t):