From fae9f6124ae8163d081abe3e5853f87e3a1dbf88 Mon Sep 17 00:00:00 2001 From: Fabrice Salvaire Date: Tue, 29 Jan 2019 17:33:54 +0100 Subject: [PATCH] Path: fixed transformation issue --- Patro/GeometryEngine/Path.py | 52 +++++++++++++++++++-- examples/file-format/svg/test-svg-import.py | 4 +- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/Patro/GeometryEngine/Path.py b/Patro/GeometryEngine/Path.py index aedbc48..d0863f2 100644 --- a/Patro/GeometryEngine/Path.py +++ b/Patro/GeometryEngine/Path.py @@ -432,6 +432,12 @@ class PathSegment(OnePointMixin, LinearSegment): ############################################## + def to_absolute(self): + self._point = self.stop_point + self._absolute = True + + ############################################## + def apply_transformation(self, transformation): OnePointMixin.apply_transformation(self, transformation) if self._radius is not None: @@ -458,6 +464,11 @@ class DirectionalSegment(LinearSegment): ############################################## + def __repr__(self): + return '{0}(@{1._index}, {1.offset})'.format(self.__class__.__name__, self) + + ############################################## + def apply_transformation(self, transformation): # Since a rotation will change the direction # DirectionalSegment must be casted to PathSegment @@ -557,6 +568,13 @@ class QuadraticBezierSegment(PathPart, TwoPointMixin): ############################################## + def to_absolute(self): + self._point1 = self.point1 + self._point2 = self.point2 + self._absolute = True + + ############################################## + @property def stop_point(self): return self.point2 @@ -594,6 +612,14 @@ class CubicBezierSegment(PathPart, ThreePointMixin): ############################################## + def to_absolute(self): + self._point1 = self.point1 + self._point2 = self.point2 + self._point3 = self.point3 + self._absolute = True + + ############################################## + @property def stop_point(self): return self.point3 @@ -697,6 +723,12 @@ class ArcSegment(OnePointMixin, PathPart): ############################################## + def to_absolute(self): + self._point = self.stop_point + self._absolute = True + + ############################################## + @property def points(self): return self.start_point, self.stop_point @@ -714,6 +746,8 @@ class Path2D(Primitive2DMixin, Primitive1P): """Class to implements 2D Path.""" + _logger = _module_logger.getChild('Path2D') + ############################################## def __init__(self, start_point): @@ -789,17 +823,29 @@ class Path2D(Primitive2DMixin, Primitive1P): def apply_transformation(self, transformation): - self._p0 = transformation * self._p0 + self._logger.info(str(self) + '\n' + str(transformation.type) + '\n' + str(transformation) ) - for i, part in enumerate(self._parts): + for part in self._parts: + # print(part) if isinstance(part, PathSegment): part._reset_cache() if isinstance(part, DirectionalSegment): # Since a rotation will change the direction # DirectionalSegment must be casted to PathSegment part = part.to_path_segment() - self._parts[i] = part + self._parts[part.index] = part + if part._absolute is False: + # print('incremental', part, part.points) + part.to_absolute() + # print('->', part.points) + + # print() + self._p0 = transformation * self._p0 + # print('p0', self._p0) + for part in self._parts: + # print(part) part.apply_transformation(transformation) + # print('->', part.points) ############################################## diff --git a/examples/file-format/svg/test-svg-import.py b/examples/file-format/svg/test-svg-import.py index e947cf6..52df5eb 100644 --- a/examples/file-format/svg/test-svg-import.py +++ b/examples/file-format/svg/test-svg-import.py @@ -108,12 +108,12 @@ class SceneImporter(SvgFileInternal): ) transformation = state.transform + self._logger.info('Sate Transform\n' + str(transformation)) if isinstance(item, SvgFormat.Path): # and state.stroke_dasharray is None path = item.path_data if path is not None: # Fixme: - # path = path.transform(transformation) - # Fixme: + path = path.transform(transformation) for part in path: self._update_bounding_box(part) self._scene.add_path(path, path_style) -- GitLab