meerk40t / svgelements

SVG Parsing for Elements, Paths, and other SVG Objects.
MIT License
133 stars 29 forks source link

Make Point compatible with numpy.array() #67

Closed abey79 closed 3 years ago

abey79 commented 3 years ago

This tiny fix makes Point compatible with numpy:

>>> np.array([Point(1, 2), Point(3, 4), Point(5, 6)])
array([[1, 2],
       [3, 4],
       [5, 6]])

This is greatly useful to convert Polygon/Polyline's points to numpy array:

# this works and does what you think it should
poly = Polyline(points=((10, 20), (30, 20), (100, 200), (32, 64)))
pts = np.array(poly.points)
abey79 commented 3 years ago

This test appears to be somewhat fragile:

======================================================================
212FAIL: test_arc_len_circle_line (test_arc_length.TestElementArcLength)
213Known chord vs line
214----------------------------------------------------------------------
215Traceback (most recent call last):
216  File "/home/travis/build/meerk40t/svgelements/test/test_arc_length.py", line 296, in test_arc_len_circle_line
217    self.assertAlmostEqual(chord, length)
218AssertionError: 58.20358497566716 != 58.20358482449973 within 7 places
tatarize commented 3 years ago

Failed test is nothing to do with this PR. I might have to give it a broader error range.

test_arc_length.TestElementArcLength

FAIL: test_arc_len_circle_line (test_arc_length.TestElementArcLength) Known chord vs line

Traceback (most recent call last): File "/home/travis/build/meerk40t/svgelements/test/test_arc_length.py", line 296, in test_arc_len_circle_line self.assertAlmostEqual(chord, length) AssertionError: 58.20358497566716 != 58.20358482449973 within 7 places