[Python-modules-commits] [python-svg.path] 03/08: Import python-svg.path_2.1.1.orig.tar.xz

Daniel Stender stender at moszumanska.debian.org
Sat Jun 25 07:57:37 UTC 2016


This is an automated email from the git hooks/post-receive script.

stender pushed a commit to branch master
in repository python-svg.path.

commit afcc39deb35e6a1f8be26c6553bb16831a4337bd
Author: Daniel Stender <stender at debian.org>
Date:   Sat Jun 25 09:43:53 2016 +0200

    Import python-svg.path_2.1.1.orig.tar.xz
---
 CHANGES.txt                      | 15 ++++++++++
 CONTRIBUTORS.txt                 |  3 +-
 PKG-INFO                         | 21 ++++++++++++--
 setup.py                         |  3 +-
 src/svg.path.egg-info/PKG-INFO   | 21 ++++++++++++--
 src/svg/path/parser.py           |  1 +
 src/svg/path/path.py             | 61 +++++++++++++++++++++++++---------------
 src/svg/path/tests/test_paths.py | 26 +++++++++++++++--
 8 files changed, 119 insertions(+), 32 deletions(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index 5f4699c..3021028 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,6 +1,21 @@
 Changelog
 =========
 
+
+2.1.1 (2016-02-28)
+------------------
+
+- #18: QuadraticBeziers could get a DivideByZero error under certain
+  circumstances. [MTician]
+
+- Accept an error parameter to Path.point() to be able to
+  control error vs performance setting. [saschwarz]
+
+- #25: Arc's could create a MathDomain error under certain circumstances.
+
+- #17: Set last_command always.
+
+
 2.0.1 (2015-10-17)
 ------------------
 
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
index aedc719..65c082d 100644
--- a/CONTRIBUTORS.txt
+++ b/CONTRIBUTORS.txt
@@ -5,5 +5,6 @@ provided suggestions and feedback about the d() function.
 
 Michiel Schallig suggested calculating length by recursive straight-line
 approximations, which enables you to choose between accuracy or speed.
+Steve Schwarz added an error argument to make that choice an argument.
 
-Thanks also to bug fixers Martin R, abcjjy, and Daniel Stender.
+Thanks also to bug fixers Martin R, abcjjy, Daniel Stender and MTician.
diff --git a/PKG-INFO b/PKG-INFO
index a966ede..861c1ed 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: svg.path
-Version: 2.0.1
+Version: 2.1.1
 Summary: SVG path objects and parser
 Home-page: https://github.com/regebro/svg.path
 Author: Lennart Regebro
@@ -182,12 +182,28 @@ Description: svg.path
         
         Michiel Schallig suggested calculating length by recursive straight-line
         approximations, which enables you to choose between accuracy or speed.
+        Steve Schwarz added an error argument to make that choice an argument.
         
-        Thanks also to bug fixers Martin R, abcjjy, and Daniel Stender.
+        Thanks also to bug fixers Martin R, abcjjy, Daniel Stender and MTician.
         
         Changelog
         =========
         
+        
+        2.1.1 (2016-02-28)
+        ------------------
+        
+        - #18: QuadraticBeziers could get a DivideByZero error under certain
+          circumstances. [MTician]
+        
+        - Accept an error parameter to Path.point() to be able to
+          control error vs performance setting. [saschwarz]
+        
+        - #25: Arc's could create a MathDomain error under certain circumstances.
+        
+        - #17: Set last_command always.
+        
+        
         2.0.1 (2015-10-17)
         ------------------
         
@@ -266,6 +282,7 @@ Classifier: Programming Language :: Python :: 3.1
 Classifier: Programming Language :: Python :: 3.2
 Classifier: Programming Language :: Python :: 3.3
 Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
 Classifier: Programming Language :: Python :: Implementation :: PyPy
 Classifier: Programming Language :: Python :: Implementation :: Jython
 Classifier: Topic :: Multimedia :: Graphics
diff --git a/setup.py b/setup.py
index 61e3e43..3043006 100644
--- a/setup.py
+++ b/setup.py
@@ -1,7 +1,7 @@
 from setuptools import setup, find_packages
 import os
 
-version = '2.0.1'
+version = '2.1.1'
 
 long_description = (
     open('README.rst').read()
@@ -33,6 +33,7 @@ setup(name='svg.path',
           'Programming Language :: Python :: 3.2',
           'Programming Language :: Python :: 3.3',
           'Programming Language :: Python :: 3.4',
+          'Programming Language :: Python :: 3.5',
           'Programming Language :: Python :: Implementation :: PyPy',
           'Programming Language :: Python :: Implementation :: Jython',
           'Topic :: Multimedia :: Graphics'
diff --git a/src/svg.path.egg-info/PKG-INFO b/src/svg.path.egg-info/PKG-INFO
index a966ede..861c1ed 100644
--- a/src/svg.path.egg-info/PKG-INFO
+++ b/src/svg.path.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: svg.path
-Version: 2.0.1
+Version: 2.1.1
 Summary: SVG path objects and parser
 Home-page: https://github.com/regebro/svg.path
 Author: Lennart Regebro
@@ -182,12 +182,28 @@ Description: svg.path
         
         Michiel Schallig suggested calculating length by recursive straight-line
         approximations, which enables you to choose between accuracy or speed.
+        Steve Schwarz added an error argument to make that choice an argument.
         
-        Thanks also to bug fixers Martin R, abcjjy, and Daniel Stender.
+        Thanks also to bug fixers Martin R, abcjjy, Daniel Stender and MTician.
         
         Changelog
         =========
         
+        
+        2.1.1 (2016-02-28)
+        ------------------
+        
+        - #18: QuadraticBeziers could get a DivideByZero error under certain
+          circumstances. [MTician]
+        
+        - Accept an error parameter to Path.point() to be able to
+          control error vs performance setting. [saschwarz]
+        
+        - #25: Arc's could create a MathDomain error under certain circumstances.
+        
+        - #17: Set last_command always.
+        
+        
         2.0.1 (2015-10-17)
         ------------------
         
@@ -266,6 +282,7 @@ Classifier: Programming Language :: Python :: 3.1
 Classifier: Programming Language :: Python :: 3.2
 Classifier: Programming Language :: Python :: 3.3
 Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
 Classifier: Programming Language :: Python :: Implementation :: PyPy
 Classifier: Programming Language :: Python :: Implementation :: Jython
 Classifier: Topic :: Multimedia :: Graphics
diff --git a/src/svg/path/parser.py b/src/svg/path/parser.py
index 912bd17..96ca5ee 100644
--- a/src/svg/path/parser.py
+++ b/src/svg/path/parser.py
@@ -45,6 +45,7 @@ def parse_path(pathdef, current_pos=0j):
             if command is None:
                 raise ValueError("Unallowed implicit command in %s, position %s" % (
                     pathdef, len(pathdef.split()) - len(elements)))
+            last_command = command  # Used by S and T
 
         if command == 'M':
             # Moveto command.
diff --git a/src/svg/path/path.py b/src/svg/path/path.py
index 31d2bcd..86dc285 100644
--- a/src/svg/path/path.py
+++ b/src/svg/path/path.py
@@ -136,23 +136,34 @@ class QuadraticBezier(object):
                pos ** 2 * self.end
 
     def length(self, error=None, min_depth=None):
-        # http://www.malczak.info/blog/quadratic-bezier-curve-length/
-        a = self.start - 2 * self.control + self.end
-        b = 2 * (self.control - self.start)
-
-        A = 4 * (a.real ** 2 + a.imag ** 2)
-        B = 4 * (a.real * b.real + a.imag * b.imag)
-        C = b.real ** 2 + b.imag ** 2
-
-        Sabc = 2 * sqrt(A + B + C)
-        A2 = sqrt(A)
-        A32 = 2 * A * A2
-        C2 = 2 * sqrt(C)
-        BA = B / A2
-
-        return (A32 * Sabc + A2 * B * (Sabc - C2) + (4 * C * A - B ** 2) *
-                log((2 * A2 + BA + Sabc) / (BA + C2))) / (4 * A32)
-
+        a = self.start - 2*self.control + self.end
+        b = 2*(self.control - self.start)
+        a_dot_b = a.real*b.real + a.imag*b.imag
+
+        if abs(a) < 1e-12:
+            s = abs(b)
+        elif abs(a_dot_b + abs(a)*abs(b)) < 1e-12:
+            k = abs(b)/abs(a)
+            if k >= 2:
+                s = abs(b) - abs(a)
+            else:
+                s = abs(a)*(k**2/2 - k + 1)
+        else:
+            # For an explanation of this case, see
+            # http://www.malczak.info/blog/quadratic-bezier-curve-length/
+            A = 4 * (a.real ** 2 + a.imag ** 2)
+            B = 4 * (a.real * b.real + a.imag * b.imag)
+            C = b.real ** 2 + b.imag ** 2
+
+            Sabc = 2 * sqrt(A + B + C)
+            A2 = sqrt(A)
+            A32 = 2 * A * A2
+            C2 = 2 * sqrt(C)
+            BA = B / A2
+
+            s = (A32 * Sabc + A2 * B * (Sabc - C2) + (4 * C * A - B ** 2) *
+                    log((2 * A2 + BA + Sabc) / (BA + C2))) / (4 * A32)
+        return s
 
 class Arc(object):
 
@@ -238,10 +249,14 @@ class Arc(object):
 
         n = sqrt((ux * ux + uy * uy) * (vx * vx + vy * vy))
         p = ux * vx + uy * vy
-        if p == 0:
-            delta = degrees(acos(0))
-        else:
-            delta = degrees(acos(p / n))
+        d = p/n
+        # In certain cases the above calculation can through inaccuracies
+        # become just slightly out of range, f ex -1.0000000000000002.
+        if d > 1.0:
+            d = 1.0
+        elif d < -1.0:
+            d = -1.0
+        delta = degrees(acos(d))
         if (ux * vy - uy * vx) < 0:
             delta = -delta
         self.delta = delta % 360
@@ -332,7 +347,7 @@ class Path(MutableSequence):
         self._length = sum(lengths)
         self._lengths = [each / self._length for each in lengths]
 
-    def point(self, pos):
+    def point(self, pos, error=ERROR):
 
         # Shortcuts
         if pos == 0.0:
@@ -340,7 +355,7 @@ class Path(MutableSequence):
         if pos == 1.0:
             return self._segments[-1].point(pos)
 
-        self._calc_lengths()
+        self._calc_lengths(error=error)
         # Find which segment the point we search for is located on:
         segment_start = 0
         for index, segment in enumerate(self._segments):
diff --git a/src/svg/path/tests/test_paths.py b/src/svg/path/tests/test_paths.py
index 43c20ff..57609d7 100644
--- a/src/svg/path/tests/test_paths.py
+++ b/src/svg/path/tests/test_paths.py
@@ -315,9 +315,22 @@ class QuadraticBezierTest(unittest.TestCase):
         self.assertAlmostEqual(path2.point(1), (1000 + 300j))
 
     def test_length(self):
-        # calculated with the cubic bezier length estimation
-        path1 = QuadraticBezier(200 + 300j, 400 + 50j, 600 + 300j)
-        self.assertAlmostEqual(path1.length(), 487.7710938890204)
+        # expected results calculated with
+        # svg.path.segment_length(q, 0, 1, q.start, q.end, 1e-14, 20, 0)
+        q1 = QuadraticBezier(200 + 300j, 400 + 50j, 600 + 300j)
+        q2 = QuadraticBezier(200 + 300j, 400 + 50j, 500 + 200j)
+        closedq = QuadraticBezier(6+2j, 5-1j, 6+2j)
+        linq1 = QuadraticBezier(1, 2, 3)
+        linq2 = QuadraticBezier(1+3j, 2+5j, -9 - 17j)
+        nodalq = QuadraticBezier(1, 1, 1)
+        tests = [(q1, 487.77109389525975),
+                 (q2, 379.90458193489155),
+                 (closedq, 3.1622776601683795),
+                 (linq1, 2),
+                 (linq2, 22.73335777124786),
+                 (nodalq, 0)]
+        for q, exp_res in tests:
+            self.assertAlmostEqual(q.length(), exp_res)
 
     def test_equality(self):
         # This is to test the __eq__ and __ne__ methods, so we can't use
@@ -414,6 +427,13 @@ class ArcTest(unittest.TestCase):
         self.assertTrue(segment == Arc(0j, 100 + 50j, 0, 0, 0, 100 + 50j))
         self.assertTrue(segment != Arc(0j, 100 + 50j, 0, 1, 0, 100 + 50j))
 
+    def test_issue25(self):
+        # This raised a math domain error
+        Arc((725.307482225571-915.5548199281527j),
+            (202.79421639137703+148.77294617167183j),
+            225.6910319606926, 1, 1,
+            (-624.6375539637027+896.5483089399895j))
+
 
 class TestPath(unittest.TestCase):
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-svg.path.git



More information about the Python-modules-commits mailing list