Skip to content

Commit

Permalink
Merge pull request #91 from meerk40t/1.4.5
Browse files Browse the repository at this point in the history
Math-Imports Refined
  • Loading branch information
tatarize authored Jan 18, 2021
2 parents 10242a5 + edf4b25 commit 25433f8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -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
Expand Down
34 changes: 21 additions & 13 deletions svgelements/svgelements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 25433f8

Please sign in to comment.