Skip to content

Commit

Permalink
Merge branch 'master' into fastfail-intersection
Browse files Browse the repository at this point in the history
  • Loading branch information
mathandy committed Feb 4, 2023
2 parents b6e5a62 + d9515ea commit 31b6f3d
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 31 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/github-ci-legacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Github CI Unit Testing for Legacy Environments

on:
push:
pull_request:
workflow_dispatch:

jobs:
build:
runs-on: ${{ matrix.os }}
continue-on-error: true
strategy:
matrix:
os: [ubuntu-18.04, macos-10.15, windows-2019]
python-version: [2.7, 3.5, 3.6]
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# configure python
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

# install deps
- name: Install dependencies for ${{ matrix.os }} Python ${{ matrix.python-version }}
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install scipy
# find and run all unit tests
- name: Run unit tests
run: python -m unittest discover test
2 changes: 1 addition & 1 deletion .github/workflows/github-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9, "3.10"]
python-version: [3.7, 3.8, 3.9, "3.10", "3.11"]
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion examples/compute-many-points-quickly-using-numpy-arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
svgpathtools.bezier module."""
from __future__ import print_function
import numpy as np
from svgpathtools import *
from svgpathtools import bezier_point, Path, bpoints2bezier, polynomial2bezier


class HigherOrderBezier:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
continuous subpaths.
"""

from svgpathtools import *
from svgpathtools import Path, Line


def path1_is_contained_in_path2(path1, path2):
assert path2.isclosed() # This question isn't well-defined otherwise
Expand All @@ -16,11 +17,11 @@ def path1_is_contained_in_path2(path1, path2):

# find a point that's definitely outside path2
xmin, xmax, ymin, ymax = path2.bbox()
B = (xmin + 1) + 1j*(ymax + 1)
b = (xmin + 1) + 1j*(ymax + 1)

A = path1.start # pick an arbitrary point in path1
AB_line = Path(Line(A, B))
number_of_intersections = len(AB_line.intersect(path2))
a = path1.start # pick an arbitrary point in path1
ab_line = Path(Line(a, b))
number_of_intersections = len(ab_line.intersect(path2))
if number_of_intersections % 2: # if number of intersections is odd
return True
else:
Expand Down
9 changes: 6 additions & 3 deletions examples/distance-between-two-svg-paths-example.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from svgpathtools import *
from svgpathtools import disvg, Line, CubicBezier
from scipy.optimize import fminbound

# create some example paths
path1 = CubicBezier(1,2+3j,3-5j,4+1j)
path2 = path1.rotated(60).translated(3)

# find minimizer
from scipy.optimize import fminbound

def dist(t):
return path1.radialrange(path2.point(t))[0][0]


# find minimizer
T2 = fminbound(dist, 0, 1)

# Let's do a visual check
Expand Down
5 changes: 3 additions & 2 deletions svgpathtools/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Example:
Typical usage looks something like the following.
>> from svgpathtools import *
>> from svgpathtools import Document
>> doc = Document('my_file.html')
>> for path in doc.paths():
>> # Do something with the transformed Path object.
Expand Down Expand Up @@ -44,14 +44,15 @@
from io import StringIO
from tempfile import gettempdir
from time import time
import numpy as np

# Internal dependencies
from .parser import parse_path
from .parser import parse_transform
from .svg_to_paths import (path2pathd, ellipse2pathd, line2pathd,
polyline2pathd, polygon2pathd, rect2pathd)
from .misctools import open_in_browser
from .path import *
from .path import transform, Path, is_path_segment

# To maintain forward/backward compatibility
try:
Expand Down
19 changes: 10 additions & 9 deletions svgpathtools/svg_io_sax.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
from __future__ import division, absolute_import, print_function
import os
from xml.etree.ElementTree import iterparse, Element, ElementTree, SubElement
import numpy as np

# Internal dependencies
from .parser import parse_path
from .parser import parse_transform
from .svg_to_paths import (path2pathd, ellipse2pathd, line2pathd,
polyline2pathd, polygon2pathd, rect2pathd)
from .misctools import open_in_browser
from .path import *
from .path import transform

# To maintain forward/backward compatibility
try:
str = basestring
string = basestring
except NameError:
pass
string = str

NAME_SVG = "svg"
ATTR_VERSION = "version"
Expand Down Expand Up @@ -164,17 +165,17 @@ def generate_dom(self):
if matrix is not None and not np.all(np.equal(matrix, identity)):
matrix_string = "matrix("
matrix_string += " "
matrix_string += str(matrix[0][0])
matrix_string += string(matrix[0][0])
matrix_string += " "
matrix_string += str(matrix[1][0])
matrix_string += string(matrix[1][0])
matrix_string += " "
matrix_string += str(matrix[0][1])
matrix_string += string(matrix[0][1])
matrix_string += " "
matrix_string += str(matrix[1][1])
matrix_string += string(matrix[1][1])
matrix_string += " "
matrix_string += str(matrix[0][2])
matrix_string += string(matrix[0][2])
matrix_string += " "
matrix_string += str(matrix[1][2])
matrix_string += string(matrix[1][2])
matrix_string += ")"
path.set(ATTR_TRANSFORM, matrix_string)
if ATTR_DATA in values:
Expand Down
2 changes: 1 addition & 1 deletion test/test_bezier.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import division, absolute_import, print_function
import numpy as np
import unittest
from svgpathtools.bezier import *
from svgpathtools.bezier import bezier_point, bezier2polynomial, polynomial2bezier
from svgpathtools.path import bpoints2bezier


Expand Down
2 changes: 1 addition & 1 deletion test/test_document.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import division, absolute_import, print_function
import unittest
from svgpathtools import *
from svgpathtools import Document
from io import StringIO
from io import open # overrides build-in open for compatibility with python2
from os.path import join, dirname
Expand Down
2 changes: 1 addition & 1 deletion test/test_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#------------------------------------------------------------------------------
from __future__ import division, absolute_import, print_function
import unittest
from svgpathtools import *
from svgpathtools import parse_path


class TestGeneration(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion test/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""
from __future__ import division, absolute_import, print_function
import unittest
from svgpathtools import *
from svgpathtools import Document, SVG_NAMESPACE, parse_path
from os.path import join, dirname
import numpy as np

Expand Down
3 changes: 2 additions & 1 deletion test/test_parsing.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Note: This file was taken mostly as is from the svg.path module (v 2.0)
from __future__ import division, absolute_import, print_function
import unittest
from svgpathtools import *
from svgpathtools import Path, Line, QuadraticBezier, CubicBezier, Arc, parse_path
import svgpathtools

import numpy as np


Expand Down
8 changes: 6 additions & 2 deletions test/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
import warnings

# Internal dependencies
from svgpathtools import *
from svgpathtools.path import _NotImplemented4ArcException, bezier_radialrange
from svgpathtools import (
Line, QuadraticBezier, CubicBezier, Arc, Path, poly2bez, path_encloses_pt,
bpoints2bezier, closest_point_in_path, farthest_point_in_path,
is_bezier_segment, is_bezier_path, parse_path
)
from svgpathtools.path import bezier_radialrange

# An important note for those doing any debugging:
# ------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion test/test_polytools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np

# Internal dependencies
from svgpathtools import *
from svgpathtools import rational_limit


class Test_polytools(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion test/test_sax_groups.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import division, absolute_import, print_function
import unittest
from svgpathtools import *
from svgpathtools import SaxDocument
from os.path import join, dirname


Expand Down
2 changes: 1 addition & 1 deletion test/test_svg2paths.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import division, absolute_import, print_function
import unittest
from svgpathtools import *
from svgpathtools import Path, Line, Arc, svg2paths, svgstr2paths
from io import StringIO
from io import open # overrides build-in open for compatibility with python2
from os.path import join, dirname
Expand Down

0 comments on commit 31b6f3d

Please sign in to comment.