removed all np.matrix uses (deprecation)

pull/63/head
Andy Port 2018-08-21 20:05:59 -07:00
parent 3d1a225503
commit 40a515ee63
5 changed files with 28 additions and 35 deletions

View File

@ -38,10 +38,10 @@ def points_in_each_seg_slow(path, tvals):
def points_in_each_seg(path, tvals):
"""Compute seg.point(t) for each seg in path and each t in tvals."""
A = np.matrix([[-1, 3, -3, 1], # transforms cubic bez to standard poly
[ 3, -6, 3, 0],
[-3, 3, 0, 0],
[ 1, 0, 0, 0]])
A = np.array([[-1, 3, -3, 1], # transforms cubic bez to standard poly
[ 3, -6, 3, 0],
[-3, 3, 0, 0],
[ 1, 0, 0, 0]])
B = [seg.bpoints() for seg in path]
return np.dot(B, np.dot(A, np.power(tvals, [[3],[2],[1],[0]])))

View File

@ -229,7 +229,7 @@ def _parse_transform_substr(transform_substr):
if not _check_num_parsed_values(values, [6]):
return transform
transform[0:2, 0:3] = np.matrix([values[0:6:2], values[1:6:2]])
transform[0:2, 0:3] = np.array([values[0:6:2], values[1:6:2]])
elif 'translate' in transform_substr:
if not _check_num_parsed_values(values, [1, 2]):
@ -258,11 +258,11 @@ def _parse_transform_substr(transform_substr):
else:
offset = (0, 0)
tf_offset = np.identity(3)
tf_offset[0:2, 2:3] = np.matrix([[offset[0]], [offset[1]]])
tf_offset[0:2, 2:3] = np.array([[offset[0]], [offset[1]]])
tf_rotate = np.identity(3)
tf_rotate[0:2, 0:2] = np.matrix([[np.cos(angle), -np.sin(angle)], [np.sin(angle), np.cos(angle)]])
tf_rotate[0:2, 0:2] = np.array([[np.cos(angle), -np.sin(angle)], [np.sin(angle), np.cos(angle)]])
tf_offset_neg = np.identity(3)
tf_offset_neg[0:2, 2:3] = np.matrix([[-offset[0]], [-offset[1]]])
tf_offset_neg[0:2, 2:3] = np.array([[-offset[0]], [-offset[1]]])
transform = tf_offset.dot(tf_rotate).dot(tf_offset_neg)

View File

@ -258,10 +258,10 @@ def scale(curve, sx, sy=None, origin=0j):
def transform(curve, tf):
"""Transforms the curve by the homogeneous transformation matrix tf"""
def to_point(p):
return np.matrix([[p.real], [p.imag], [1.0]])
return np.array([[p.real], [p.imag], [1.0]])
def to_vector(z):
return np.matrix([[z.real], [z.imag], [0.0]])
return np.array([[z.real], [z.imag], [0.0]])
def to_complex(v):
return v.item(0) + 1j * v.item(1)

View File

@ -9,13 +9,6 @@ def get_desired_path(name, paths):
return next(p for p in paths if p.element.get('{some://testuri}name') == name)
def column_vector(values):
input = []
for value in values:
input.append([value])
return np.matrix(input)
class TestGroups(unittest.TestCase):
def check_values(self, v, z):
@ -32,8 +25,8 @@ class TestGroups(unittest.TestCase):
# * paths is the output of doc.flatten_all_paths()
v_s_vals.append(1.0)
v_e_relative_vals.append(0.0)
v_s = column_vector(v_s_vals)
v_e = v_s + column_vector(v_e_relative_vals)
v_s = np.array(v_s_vals)
v_e = v_s + v_e_relative_vals
actual = get_desired_path(name, paths)
@ -50,13 +43,13 @@ class TestGroups(unittest.TestCase):
result = doc.flatten_all_paths()
self.assertEqual(12, len(result))
tf_matrix_group = np.matrix([[1.5, 0.0, -40.0], [0.0, 0.5, 20.0], [0.0, 0.0, 1.0]])
tf_matrix_group = np.array([[1.5, 0.0, -40.0], [0.0, 0.5, 20.0], [0.0, 0.0, 1.0]])
self.check_line(tf_matrix_group,
[183, 183], [0.0, -50],
'path00', result)
tf_scale_group = np.matrix([[1.25, 0.0, 0.0], [0.0, 1.25, 0.0], [0.0, 0.0, 1.0]])
tf_scale_group = np.array([[1.25, 0.0, 0.0], [0.0, 1.25, 0.0], [0.0, 0.0, 1.0]])
self.check_line(tf_matrix_group.dot(tf_scale_group),
[122, 320], [-50.0, 0.0],
@ -70,26 +63,26 @@ class TestGroups(unittest.TestCase):
[150, 200], [-50, 25],
'path03', result)
tf_nested_translate_group = np.matrix([[1, 0, 20], [0, 1, 0], [0, 0, 1]])
tf_nested_translate_group = np.array([[1, 0, 20], [0, 1, 0], [0, 0, 1]])
self.check_line(tf_matrix_group.dot(tf_scale_group).dot(tf_nested_translate_group),
[150, 200], [-50, 25],
'path04', result)
tf_nested_translate_xy_group = np.matrix([[1, 0, 20], [0, 1, 30], [0, 0, 1]])
tf_nested_translate_xy_group = np.array([[1, 0, 20], [0, 1, 30], [0, 0, 1]])
self.check_line(tf_matrix_group.dot(tf_scale_group).dot(tf_nested_translate_xy_group),
[150, 200], [-50, 25],
'path05', result)
tf_scale_xy_group = np.matrix([[0.5, 0, 0], [0, 1.5, 0.0], [0, 0, 1]])
tf_scale_xy_group = np.array([[0.5, 0, 0], [0, 1.5, 0.0], [0, 0, 1]])
self.check_line(tf_matrix_group.dot(tf_scale_xy_group),
[122, 320], [-50, 0],
'path06', result)
a_07 = 20.0*np.pi/180.0
tf_rotate_group = np.matrix([[np.cos(a_07), -np.sin(a_07), 0],
tf_rotate_group = np.array([[np.cos(a_07), -np.sin(a_07), 0],
[np.sin(a_07), np.cos(a_07), 0],
[0, 0, 1]])
@ -98,10 +91,10 @@ class TestGroups(unittest.TestCase):
'path07', result)
a_08 = 45.0*np.pi/180.0
tf_rotate_xy_group_R = np.matrix([[np.cos(a_08), -np.sin(a_08), 0],
tf_rotate_xy_group_R = np.array([[np.cos(a_08), -np.sin(a_08), 0],
[np.sin(a_08), np.cos(a_08), 0],
[0, 0, 1]])
tf_rotate_xy_group_T = np.matrix([[1, 0, 183], [0, 1, 183], [0, 0, 1]])
tf_rotate_xy_group_T = np.array([[1, 0, 183], [0, 1, 183], [0, 0, 1]])
tf_rotate_xy_group = tf_rotate_xy_group_T.dot(tf_rotate_xy_group_R).dot(np.linalg.inv(tf_rotate_xy_group_T))
self.check_line(tf_matrix_group.dot(tf_rotate_xy_group),
@ -109,14 +102,14 @@ class TestGroups(unittest.TestCase):
'path08', result)
a_09 = 5.0*np.pi/180.0
tf_skew_x_group = np.matrix([[1, np.tan(a_09), 0], [0, 1, 0], [0, 0, 1]])
tf_skew_x_group = np.array([[1, np.tan(a_09), 0], [0, 1, 0], [0, 0, 1]])
self.check_line(tf_matrix_group.dot(tf_skew_x_group),
[183, 183], [40, 40],
'path09', result)
a_10 = 5.0*np.pi/180.0
tf_skew_y_group = np.matrix([[1, 0, 0], [np.tan(a_10), 1, 0], [0, 0, 1]])
tf_skew_y_group = np.array([[1, 0, 0], [np.tan(a_10), 1, 0], [0, 0, 1]])
self.check_line(tf_matrix_group.dot(tf_skew_y_group),
[183, 183], [40, 40],
@ -124,10 +117,10 @@ class TestGroups(unittest.TestCase):
# This last test is for handling transforms that are defined as attributes of a <path> element.
a_11 = -40*np.pi/180.0
tf_path11_R = np.matrix([[np.cos(a_11), -np.sin(a_11), 0],
tf_path11_R = np.array([[np.cos(a_11), -np.sin(a_11), 0],
[np.sin(a_11), np.cos(a_11), 0],
[0, 0, 1]])
tf_path11_T = np.matrix([[1, 0, 100], [0, 1, 100], [0, 0, 1]])
tf_path11_T = np.array([[1, 0, 100], [0, 1, 100], [0, 0, 1]])
tf_path11 = tf_path11_T.dot(tf_path11_R).dot(np.linalg.inv(tf_path11_T))
self.check_line(tf_matrix_group.dot(tf_skew_y_group).dot(tf_path11),

View File

@ -10,11 +10,11 @@ import numpy as np
def construct_rotation_tf(a, x, y):
a = a * np.pi / 180.0
tf_offset = np.identity(3)
tf_offset[0:2, 2:3] = np.matrix([[x], [y]])
tf_offset[0:2, 2:3] = np.array([[x], [y]])
tf_rotate = np.identity(3)
tf_rotate[0:2, 0:2] = np.matrix([[np.cos(a), -np.sin(a)], [np.sin(a), np.cos(a)]])
tf_rotate[0:2, 0:2] = np.array([[np.cos(a), -np.sin(a)], [np.sin(a), np.cos(a)]])
tf_offset_neg = np.identity(3)
tf_offset_neg[0:2, 2:3] = np.matrix([[-x], [-y]])
tf_offset_neg[0:2, 2:3] = np.array([[-x], [-y]])
return tf_offset.dot(tf_rotate).dot(tf_offset_neg)
@ -157,7 +157,7 @@ class TestParser(unittest.TestCase):
tf_matrix = svgpathtools.parser.parse_transform('matrix(1.0 2.0 3.0 4.0 5.0 6.0)')
expected_tf_matrix = np.identity(3)
expected_tf_matrix[0:2, 0:3] = np.matrix([[1.0, 3.0, 5.0], [2.0, 4.0, 6.0]])
expected_tf_matrix[0:2, 0:3] = np.array([[1.0, 3.0, 5.0], [2.0, 4.0, 6.0]])
self.assertTrue(np.array_equal(expected_tf_matrix, tf_matrix))
# Try a test with no y specified