for PyPI v1.3 update

pull/12/merge 1.3
Andy 2017-02-28 23:11:46 -08:00
parent 8815ddcd52
commit 465e96f8c8
11 changed files with 48 additions and 13 deletions

View File

@ -5,6 +5,8 @@ points given by their standard representation."""
# External dependencies: # External dependencies:
from __future__ import division, absolute_import, print_function from __future__ import division, absolute_import, print_function
from builtins import range
from builtins import object
from math import factorial as fac, ceil, log, sqrt from math import factorial as fac, ceil, log, sqrt
from numpy import poly1d from numpy import poly1d
@ -83,12 +85,13 @@ def bezier2polynomial(p, numpy_ordering=True, return_poly1d=False):
coeffs = p coeffs = p
else: else:
# https://en.wikipedia.org/wiki/Bezier_curve#Polynomial_form # https://en.wikipedia.org/wiki/Bezier_curve#Polynomial_form
n = len(p) + 1 n = len(p) - 1
coeffs = [fac(n)//fac(n-j) * sum( coeffs = [fac(n)//fac(n-j) * sum(
(-1)**(i+j) * p[i] / (fac(i) * fac(j-i)) for i in xrange(j+1)) (-1)**(i+j) * p[i] / (fac(i) * fac(j-i)) for i in range(j+1))
for j in range(n+1)] for j in range(n+1)]
if not numpy_ordering:
coeffs.reverse() coeffs.reverse()
if not numpy_ordering:
coeffs = coeffs[::-1] # can't use .reverse() as might be tuple
if return_poly1d: if return_poly1d:
return poly1d(coeffs) return poly1d(coeffs)
return coeffs return coeffs

View File

@ -0,0 +1,21 @@
def directional_field(curve, tvals=np.linspace(0, 1, N), asize=1e-2,
colored=False):
size = asize * curve.length()
arrows = []
tvals = np.linspace(0, 1, N)
for t in tvals:
pt = curve.point(t)
ut = curve.unit_tangent(t)
un = curve.normal(t)
l1 = Line(pt, pt + size*(un - ut)/2).reversed()
l2 = Line(pt, pt + size*(-un - ut)/2)
if colored:
arrows.append(Path(l1, l2))
else:
arrows += [l1, l2]
if colored:
colors = [(int(255*t), 0, 0) for t in tvals]
return arrows, tvals, colors
else:
return Path(arrows)

View File

@ -3,6 +3,7 @@ aren't specific to SVGs or related mathematical objects."""
# External dependencies: # External dependencies:
from __future__ import division, absolute_import, print_function from __future__ import division, absolute_import, print_function
from builtins import range
import os import os
import sys import sys
import webbrowser import webbrowser

View File

@ -4,6 +4,10 @@ Arc."""
# External dependencies # External dependencies
from __future__ import division, absolute_import, print_function from __future__ import division, absolute_import, print_function
from builtins import map
from builtins import zip
from builtins import range
from builtins import object
from math import sqrt, cos, sin, acos, degrees, radians, log, pi from math import sqrt, cos, sin, acos, degrees, radians, log, pi
from cmath import exp, sqrt as csqrt, phase from cmath import exp, sqrt as csqrt, phase
from collections import MutableSequence from collections import MutableSequence
@ -355,7 +359,8 @@ def inv_arclength(curve, s, s_tol=ILENGTH_S_TOL, maxits=ILENGTH_MAXITS,
if curve is a Path object, then seg is a segment in curve. if curve is a Path object, then seg is a segment in curve.
error - used to compute lengths of cubics and arcs error - used to compute lengths of cubics and arcs
min_depth - used to compute lengths of cubics and arcs min_depth - used to compute lengths of cubics and arcs
Note: This function is not designed to be efficient.""" Note: This function is not designed to be efficient, but if it's slower
than you need, make sure you have scipy installed."""
curve_length = curve.length(error=error, min_depth=min_depth) curve_length = curve.length(error=error, min_depth=min_depth)
assert curve_length > 0 assert curve_length > 0
@ -1514,7 +1519,7 @@ class Arc(object):
u1poly_mag2 = real(u1poly)**2 + imag(u1poly)**2 u1poly_mag2 = real(u1poly)**2 + imag(u1poly)**2
t2s = polyroots01(u1poly_mag2 - 1) t2s = polyroots01(u1poly_mag2 - 1)
t1s = [self.phase2t(phase(u1poly(t2))) for t2 in t2s] t1s = [self.phase2t(phase(u1poly(t2))) for t2 in t2s]
return zip(t1s, t2s) return list(zip(t1s, t2s))
elif isinstance(other_seg, Arc): elif isinstance(other_seg, Arc):
assert other_seg != self assert other_seg != self
# This could be made explicit to increase efficiency # This could be made explicit to increase efficiency
@ -2126,7 +2131,7 @@ class Path(MutableSequence):
"""returns a bounding box for the input Path object in the form """returns a bounding box for the input Path object in the form
(xmin, xmax, ymin, ymax).""" (xmin, xmax, ymin, ymax)."""
bbs = [seg.bbox() for seg in self._segments] bbs = [seg.bbox() for seg in self._segments]
xmins, xmaxs, ymins, ymaxs = zip(*bbs) xmins, xmaxs, ymins, ymaxs = list(zip(*bbs))
xmin = min(xmins) xmin = min(xmins)
xmax = max(xmaxs) xmax = max(xmaxs)
ymin = min(ymins) ymin = min(ymins)

View File

@ -3,6 +3,8 @@ segments."""
# External dependencies: # External dependencies:
from __future__ import division, absolute_import, print_function from __future__ import division, absolute_import, print_function
from builtins import zip
from builtins import str
from math import ceil from math import ceil
from os import getcwd, path as os_path, makedirs from os import getcwd, path as os_path, makedirs
from xml.dom.minidom import parse as md_xml_parse from xml.dom.minidom import parse as md_xml_parse
@ -74,7 +76,7 @@ def big_bounding_box(paths_n_stuff):
raise TypeError( raise TypeError(
"paths_n_stuff can only contains Path, CubicBezier, " "paths_n_stuff can only contains Path, CubicBezier, "
"QuadraticBezier, Line, and complex objects.") "QuadraticBezier, Line, and complex objects.")
xmins, xmaxs, ymins, ymaxs = zip(*bbs) xmins, xmaxs, ymins, ymaxs = list(zip(*bbs))
xmin = min(xmins) xmin = min(xmins)
xmax = max(xmaxs) xmax = max(xmaxs)
ymin = min(ymins) ymin = min(ymins)

View File

@ -5,6 +5,7 @@ curves."""
from __future__ import division, absolute_import, print_function from __future__ import division, absolute_import, print_function
# Internal Dependencies # Internal Dependencies
from builtins import range
from .path import Path, CubicBezier, Line from .path import Path, CubicBezier, Line
from .misctools import isclose from .misctools import isclose
from .paths2svg import disvg from .paths2svg import disvg
@ -23,7 +24,7 @@ def is_differentiable(path, tol=1e-8):
def kinks(path, tol=1e-8): def kinks(path, tol=1e-8):
"""returns indices of segments that start on a non-differentiable joint.""" """returns indices of segments that start on a non-differentiable joint."""
kink_list = [] kink_list = []
for idx in xrange(len(path)): for idx in range(len(path)):
if idx == 0 and not path.isclosed(): if idx == 0 and not path.isclosed():
continue continue
try: try:

View File

@ -3,6 +3,7 @@ The main tool being the svg2paths() function."""
# External dependencies # External dependencies
from __future__ import division, absolute_import, print_function from __future__ import division, absolute_import, print_function
from builtins import zip
from xml.dom.minidom import parse from xml.dom.minidom import parse
from os import path as os_path, getcwd from os import path as os_path, getcwd
from shutil import copyfile from shutil import copyfile
@ -64,9 +65,9 @@ def svg2paths(svg_file_location,
def dom2dict(element): def dom2dict(element):
"""Converts DOM elements to dictionaries of attributes.""" """Converts DOM elements to dictionaries of attributes."""
keys = element.attributes.keys() keys = list(element.attributes.keys())
values = [val.value for val in element.attributes.values()] values = [val.value for val in list(element.attributes.values())]
return dict(zip(keys, values)) return dict(list(zip(keys, values)))
# Use minidom to extract path strings from input SVG # Use minidom to extract path strings from input SVG
paths = [dom2dict(el) for el in doc.getElementsByTagName('path')] paths = [dom2dict(el) for el in doc.getElementsByTagName('path')]

Binary file not shown.

BIN
dist/svgpathtools-1.3.tar.gz vendored Normal file

Binary file not shown.

View File

@ -1,12 +1,12 @@
Metadata-Version: 1.1 Metadata-Version: 1.1
Name: svgpathtools Name: svgpathtools
Version: 1.2.6 Version: 1.3
Summary: A collection of tools for manipulating and analyzing SVG Path objects and Bezier curves. Summary: A collection of tools for manipulating and analyzing SVG Path objects and Bezier curves.
Home-page: https://github.com/mathandy/svgpathtools Home-page: https://github.com/mathandy/svgpathtools
Author: Andy Port Author: Andy Port
Author-email: AndyAPort@gmail.com Author-email: AndyAPort@gmail.com
License: MIT License: MIT
Download-URL: http://github.com/mathandy/svgpathtools/tarball/1.2.6 Download-URL: http://github.com/mathandy/svgpathtools/tarball/1.3
Description: svgpathtools Description: svgpathtools
============ ============

View File

@ -15,6 +15,7 @@ test.svg
vectorframes.svg vectorframes.svg
svgpathtools/__init__.py svgpathtools/__init__.py
svgpathtools/bezier.py svgpathtools/bezier.py
svgpathtools/directional_field.py
svgpathtools/misctools.py svgpathtools/misctools.py
svgpathtools/parser.py svgpathtools/parser.py
svgpathtools/path.py svgpathtools/path.py