diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-10-29 17:55:52 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-10-29 17:55:52 +0300 |
commit | a1aeff98908d47f5aba2457df444ac20a890f707 (patch) | |
tree | 0a30d407b482836bbb6502b09add2f8d1a6f6b7f | |
parent | 67b0a56743b2786d27dc34d4d7c14cae9fe4ce16 (diff) |
SVG: Fix wrong quadratic path when point is duplicate
-rw-r--r-- | io_curve_svg/import_svg.py | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/io_curve_svg/import_svg.py b/io_curve_svg/import_svg.py index 8cfd1178..4298470b 100644 --- a/io_curve_svg/import_svg.py +++ b/io_curve_svg/import_svg.py @@ -51,6 +51,11 @@ def srgb_to_linearrgb(c): else: return pow((c + 0.055) * (1.0 / 1.055), 2.4) +def check_points_equal(point_a, point_b): + return (abs(point_a[0] - point_b[0]) < 1e-6 and + abs(point_a[1] - point_b[1]) < 1e-6) + + def SVGParseFloat(s, i=0): """ Parse first float value from string @@ -644,7 +649,7 @@ class SVGPathParser: # filled. first = self._spline['points'][0] - if abs(first['x'] - x) < 1e-6 and abs(first['y'] - y) < 1e-6: + if check_points_equal((first['x'], first['y']), (x, y)): if handle_left is not None: first['handle_left'] = handle_left first['handle_left_type'] = 'FREE' @@ -801,14 +806,15 @@ class SVGPathParser: x, y = self._getCoordPair(code.islower(), self._point) - if self._spline is None: - self._appendPoint(self._point[0], self._point[1], - handle_left_type='FREE', handle_left=self._point, - handle_right_type='FREE', handle_right=self._point) + if not check_points_equal((x, y), self._point): + if self._spline is None: + self._appendPoint(self._point[0], self._point[1], + handle_left_type='FREE', handle_left=self._point, + handle_right_type='FREE', handle_right=self._point) - self._appendPoint(x, y, - handle_left_type='FREE', handle_left=(x1, y1), - handle_right_type='FREE', handle_right=(x, y)) + self._appendPoint(x, y, + handle_left_type='FREE', handle_left=(x1, y1), + handle_right_type='FREE', handle_right=(x, y)) self._point = (x, y) self._handle = (x1, y1) |