Skip to content

Removing duplicate transform code #30

Open
@matthijskooijman

Description

This issue contains a suggestion for a code refactor which I came across when working on #23. This is something that can be done independent of #23, but I didn't want to spend more time on this now without knowing where, if anywhere, this svgpathtools refactor from #23 would lead. Still, I did want to document this suggestion somewhere, so here it is.

The suggestion is to split the transform methods on Transformable and its subclasses. Currently, this method does two things:

  1. combine the passed in (parent) transformation matrix with the local (for this element) transformation matrix, and
  2. apply the resulting matrix

I think it would be worthwhile to split these two things, so 1. can be common and live in the Transformable class and can call 2., and 2. can be defined by each subclass independently (and the current "call transform on all items" could be the default implementation for 2. in Transformable, or (better IMHO) duplicated between Group and Path). This would allow removing the duplicate code for 1. that is currently duplicated in all subclasses that override transform.

I'm not sure what the names for these would be, since their function is very similar 2. only applies a precalculated transformation to the current element (and any children recursively), while 1. does the calculation and accepts a parent transformation.

If this change is made, method 1. can also easily save the resulting effective transformation matrix, which can then be used by _get_fill_stroke to fix #25.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions