Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Added support for multiple transforms in the same SVG element (#1159)

Kapil Sachdevac3f6119761a1
diff --git a/manim/mobject/svg/svg_mobject.py b/manim/mobject/svg/svg_mobject.py
index 79dbb49af..2d431019b 100644
--- a/manim/mobject/svg/svg_mobject.py
+++ b/manim/mobject/svg/svg_mobject.py
@@ -14,6 +14,8 @@ from xml.dom.minidom import Element as MinidomElement, parse as minidom_parse
from typing import Dict, List
+from manim import logger
+
from .style_utils import cascade_element_style, parse_style
from .svg_path import SVGPathMobject, string_to_numbers
from ... import config
@@ -415,7 +417,7 @@ class SVGMobject(VMobject):
def handle_transforms(self, element, mobject):
"""Applies the SVG transform to the specified mobject. Transforms include:
- ``rotate``, ``translate``, ``scale``, and ``skew``.
+ ``matrix``, ``translate``, and ``scale``.
Parameters
----------
@@ -432,39 +434,63 @@ class SVGMobject(VMobject):
y = -self.attribute_to_float(element.getAttribute("y"))
mobject.shift(x * RIGHT + y * UP)
- transform = element.getAttribute("transform")
- suffix = ")"
-
- # Transform matrix
- if transform.startswith("matrix(") and transform.endswith(suffix):
- transform = transform[len("matrix(") : -len(suffix)]
- transform = string_to_numbers(transform)
- transform = np.array(transform).reshape([3, 2])
- x = transform[2][0]
- y = -transform[2][1]
- matrix = np.identity(self.dim)
- matrix[:2, :2] = transform[:2, :]
- matrix[1] *= -1
- matrix[:, 1] *= -1
-
- for mob in mobject.family_members_with_points():
- mob.points = np.dot(mob.points, matrix)
- mobject.shift(x * RIGHT + y * UP)
+ transform_attr_value = element.getAttribute("transform")
+
+ # parse the various transforms in the attribute value
+ transform_names = ["matrix", "translate", "scale", "rotate", "skewX", "skewY"]
+
+ # Borrowed/Inspired from:
+ # https://github.com/cjlano/svg/blob/3ea3384457c9780fa7d67837c9c5fd4ebc42cb3b/svg/svg.py#L75
+
+ # match any SVG transformation with its parameter (until final parenthese)
+ # [^)]* == anything but a closing parenthese
+ # '|'.join == OR-list of SVG transformations
+ transform_regex = "|".join([x + r"[^)]*\)" for x in transform_names])
+ transforms = re.findall(transform_regex, transform_attr_value)
+
+ number_regex = r"[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?"
+
+ for t in transforms:
+ op_name, op_args = t.split("(")
+ op_name = op_name.strip()
+ op_args = [float(x) for x in re.findall(number_regex, op_args)]
+
+ if op_name == "matrix":
+ transform_args = np.array(op_args).reshape([3, 2])
+ x = transform_args[2][0]
+ y = -transform_args[2][1]
+ matrix = np.identity(self.dim)
+ matrix[:2, :2] = transform_args[:2, :]
+ matrix[1] *= -1
+ matrix[:, 1] *= -1
+
+ for mob in mobject.family_members_with_points():
+ mob.points = np.dot(mob.points, matrix)
+ mobject.shift(x * RIGHT + y * UP)
+
+ elif op_name == "scale":
+ scale_values = op_args
+ if len(scale_values) == 2:
+ scale_x, scale_y = scale_values
+ mobject.scale(np.array([scale_x, scale_y, 1]), about_point=ORIGIN)
+ elif len(scale_values) == 1:
+ scale = scale_values[0]
+ mobject.scale(np.array([scale, scale, 1]), about_point=ORIGIN)
+
+ elif op_name == "translate":
+ if len(op_args) == 2:
+ x, y = op_args
+ else:
+ x = op_args
+ y = 0
+ mobject.shift(x * RIGHT + y * DOWN)
- elif transform.startswith("scale(") and transform.endswith(suffix):
- transform = transform[len("scale(") : -len(suffix)]
- scale_values = string_to_numbers(transform)
- if len(scale_values) == 2:
- scale_x, scale_y = scale_values
- mobject.scale(np.array([scale_x, scale_y, 1]), about_point=ORIGIN)
- elif len(scale_values) == 1:
- scale = scale_values[0]
- mobject.scale(np.array([scale, scale, 1]), about_point=ORIGIN)
-
- elif transform.startswith("translate(") and transform.endswith(suffix):
- transform = transform[len("translate(") : -len(suffix)]
- x, y = string_to_numbers(transform)
- mobject.shift(x * RIGHT + y * DOWN)
+ else:
+ # TODO: handle rotate, skewX and skewY
+ # for now adding a warning message
+ logger.warning(
+ "Handling of %s transform is not supported yet!", op_name
+ )
def flatten(self, input_list):
"""A helper method to flatten the ``input_list`` into an 1D array."""
diff --git a/tests/control_data/graphical_units_data/img_and_svg/MatrixTransformTest.npz b/tests/control_data/graphical_units_data/img_and_svg/MatrixTransformTest.npz
new file mode 100644
index 000000000..810cc8f70
Binary files /dev/null and b/tests/control_data/graphical_units_data/img_and_svg/MatrixTransformTest.npz differ
diff --git a/tests/control_data/graphical_units_data/img_and_svg/MultipleTransformTest.npz b/tests/control_data/graphical_units_data/img_and_svg/MultipleTransformTest.npz
new file mode 100644
index 000000000..93eb7352c
Binary files /dev/null and b/tests/control_data/graphical_units_data/img_and_svg/MultipleTransformTest.npz differ
diff --git a/tests/control_data/graphical_units_data/img_and_svg/RotateTransformTest.npz b/tests/control_data/graphical_units_data/img_and_svg/RotateTransformTest.npz
new file mode 100644
index 000000000..41d1035b2
Binary files /dev/null and b/tests/control_data/graphical_units_data/img_and_svg/RotateTransformTest.npz differ
diff --git a/tests/control_data/graphical_units_data/img_and_svg/ScaleTransformTest.npz b/tests/control_data/graphical_units_data/img_and_svg/ScaleTransformTest.npz
new file mode 100644
index 000000000..0a70d4f98
Binary files /dev/null and b/tests/control_data/graphical_units_data/img_and_svg/ScaleTransformTest.npz differ
diff --git a/tests/control_data/graphical_units_data/img_and_svg/SkewXTransformTest.npz b/tests/control_data/graphical_units_data/img_and_svg/SkewXTransformTest.npz
new file mode 100644
index 000000000..9847e9ae6
Binary files /dev/null and b/tests/control_data/graphical_units_data/img_and_svg/SkewXTransformTest.npz differ
diff --git a/tests/control_data/graphical_units_data/img_and_svg/SkewYTransformTest.npz b/tests/control_data/graphical_units_data/img_and_svg/SkewYTransformTest.npz
new file mode 100644
index 000000000..9847e9ae6
Binary files /dev/null and b/tests/control_data/graphical_units_data/img_and_svg/SkewYTransformTest.npz differ
diff --git a/tests/control_data/graphical_units_data/img_and_svg/TranslateTransformTest.npz b/tests/control_data/graphical_units_data/img_and_svg/TranslateTransformTest.npz
new file mode 100644
index 000000000..834b585e5
Binary files /dev/null and b/tests/control_data/graphical_units_data/img_and_svg/TranslateTransformTest.npz differ
diff --git a/tests/test_graphical_units/img_svg_resources/matrix.svg b/tests/test_graphical_units/img_svg_resources/matrix.svg
new file mode 100644
index 000000000..41a053fba
--- /dev/null
+++ b/tests/test_graphical_units/img_svg_resources/matrix.svg
@@ -0,0 +1,29 @@
+<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
+ <rect x="10" y="10" width="30" height="20" fill="green" />
+
+ <!--
+ In the following example we are applying the matrix:
+ [a c e] [3 -1 30]
+ [b d f] => [1 3 40]
+ [0 0 1] [0 0 1]
+
+ which transform the rectangle as such:
+
+ top left corner: oldX=10 oldY=10
+ newX = a * oldX + c * oldY + e = 3 * 10 - 1 * 10 + 30 = 50
+ newY = b * oldX + d * oldY + f = 1 * 10 + 3 * 10 + 40 = 80
+
+ top right corner: oldX=40 oldY=10
+ newX = a * oldX + c * oldY + e = 3 * 40 - 1 * 10 + 30 = 140
+ newY = b * oldX + d * oldY + f = 1 * 40 + 3 * 10 + 40 = 110
+
+ bottom left corner: oldX=10 oldY=30
+ newX = a * oldX + c * oldY + e = 3 * 10 - 1 * 30 + 30 = 30
+ newY = b * oldX + d * oldY + f = 1 * 10 + 3 * 30 + 40 = 140
+
+ bottom right corner: oldX=40 oldY=30
+ newX = a * oldX + c * oldY + e = 3 * 40 - 1 * 30 + 30 = 120
+ newY = b * oldX + d * oldY + f = 1 * 40 + 3 * 30 + 40 = 170
+ -->
+ <rect x="10" y="10" width="30" height="20" fill="red" transform="matrix(3 1 -1 3 30 40)" />
+</svg>
\ No newline at end of file
diff --git a/tests/test_graphical_units/img_svg_resources/multiple_transforms.svg b/tests/test_graphical_units/img_svg_resources/multiple_transforms.svg
new file mode 100644
index 000000000..a7331ecba
--- /dev/null
+++ b/tests/test_graphical_units/img_svg_resources/multiple_transforms.svg
@@ -0,0 +1,636 @@
+<?xml version="1.0" encoding="utf-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
+ "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<!-- Created with matplotlib (https://matplotlib.org/) -->
+<svg height="345.6pt" version="1.1" viewBox="0 0 460.8 345.6" width="460.8pt" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+ <metadata>
+ <rdf:RDF xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
+ <cc:Work>
+ <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
+ <dc:date>2020-08-12T12:01:35.353752</dc:date>
+ <dc:format>image/svg+xml</dc:format>
+ <dc:creator>
+ <cc:Agent>
+ <dc:title>Matplotlib v3.3.0, https://matplotlib.org/</dc:title>
+ </cc:Agent>
+ </dc:creator>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <defs>
+ <style type="text/css">*{stroke-linecap:butt;stroke-linejoin:round;}</style>
+ </defs>
+ <g id="figure_1">
+ <g id="patch_1">
+ <path d="M 0 345.6
+L 460.8 345.6
+L 460.8 0
+L 0 0
+z
+" style="fill:none;"/>
+ </g>
+ <g id="axes_1">
+ <g id="patch_2">
+ <path d="M 57.6 307.584
+L 414.72 307.584
+L 414.72 41.472
+L 57.6 41.472
+z
+" style="fill:none;"/>
+ </g>
+ <g id="patch_3">
+ <path clip-path="url(#p123f0cd496)" d="M 127.941818 307.584
+L 127.941818 214.337628
+L 130.150353 218.066976
+L 132.358887 221.647169
+L 134.567421 225.084175
+L 136.775955 228.383719
+L 138.98449 231.551299
+L 141.193024 234.592194
+L 143.401558 237.511469
+L 145.610093 240.313989
+L 147.818627 243.004423
+L 150.027161 245.587255
+L 152.235696 248.066787
+L 154.44423 250.447152
+L 156.652764 252.732315
+L 158.861299 254.926084
+L 161.069833 257.032114
+L 163.278367 259.053914
+L 165.486902 260.994854
+L 167.695436 262.858166
+L 169.90397 264.646956
+L 172.112505 266.364204
+L 174.321039 268.012772
+L 176.529573 269.595406
+L 178.738108 271.114743
+L 180.946642 272.573315
+L 183.155176 273.973551
+L 185.363711 275.317786
+L 187.572245 276.608259
+L 189.780779 277.847121
+L 191.989314 279.036434
+L 194.197848 280.178181
+L 196.406382 281.274265
+L 198.614917 282.326511
+L 200.823451 283.336673
+L 203.031985 284.306434
+L 205.240519 285.23741
+L 207.449054 286.131152
+L 209.657588 286.989149
+L 211.866122 287.812831
+L 214.074657 288.603571
+L 216.283191 289.362684
+L 218.491725 290.091438
+L 220.70026 290.791045
+L 222.908794 291.462672
+L 225.117328 292.107437
+L 227.325863 292.726416
+L 229.534397 293.320638
+L 231.742931 293.891095
+L 233.951466 294.438737
+L 236.16 294.964476
+L 236.16 307.584
+z
+" style="fill:#e6e6e6;stroke:#333333;stroke-linejoin:miter;"/>
+ </g>
+ <g id="matplotlib.axis_1">
+ <g id="xtick_1">
+ <g id="line2d_1">
+ <defs>
+ <path d="M 0 0
+L 0 3.5
+" id="m10db1555b6" style="stroke:#000000;stroke-width:0.8;"/>
+ </defs>
+ <g>
+ <use style="stroke:#000000;stroke-width:0.8;" x="73.832727" xlink:href="#m10db1555b6" y="307.584"/>
+ </g>
+ </g>
+ <g id="text_1">
+ <!-- 0 -->
+ <g transform="translate(70.651477 322.182437)scale(0.1 -0.1)">
+ <defs>
+ <path d="M 31.78125 66.40625
+Q 24.171875 66.40625 20.328125 58.90625
+Q 16.5 51.421875 16.5 36.375
+Q 16.5 21.390625 20.328125 13.890625
+Q 24.171875 6.390625 31.78125 6.390625
+Q 39.453125 6.390625 43.28125 13.890625
+Q 47.125 21.390625 47.125 36.375
+Q 47.125 51.421875 43.28125 58.90625
+Q 39.453125 66.40625 31.78125 66.40625
+z
+M 31.78125 74.21875
+Q 44.046875 74.21875 50.515625 64.515625
+Q 56.984375 54.828125 56.984375 36.375
+Q 56.984375 17.96875 50.515625 8.265625
+Q 44.046875 -1.421875 31.78125 -1.421875
+Q 19.53125 -1.421875 13.0625 8.265625
+Q 6.59375 17.96875 6.59375 36.375
+Q 6.59375 54.828125 13.0625 64.515625
+Q 19.53125 74.21875 31.78125 74.21875
+z
+" id="DejaVuSans-48"/>
+ </defs>
+ <use xlink:href="#DejaVuSans-48"/>
+ </g>
+ </g>
+ </g>
+ <g id="xtick_2">
+ <g id="line2d_2">
+ <g>
+ <use style="stroke:#000000;stroke-width:0.8;" x="127.941818" xlink:href="#m10db1555b6" y="307.584"/>
+ </g>
+ </g>
+ <g id="text_2">
+ <!-- 1 -->
+ <g transform="translate(124.760568 322.182437)scale(0.1 -0.1)">
+ <defs>
+ <path d="M 12.40625 8.296875
+L 28.515625 8.296875
+L 28.515625 63.921875
+L 10.984375 60.40625
+L 10.984375 69.390625
+L 28.421875 72.90625
+L 38.28125 72.90625
+L 38.28125 8.296875
+L 54.390625 8.296875
+L 54.390625 0
+L 12.40625 0
+z
+" id="DejaVuSans-49"/>
+ </defs>
+ <use xlink:href="#DejaVuSans-49"/>
+ </g>
+ </g>
+ </g>
+ <g id="xtick_3">
+ <g id="line2d_3">
+ <g>
+ <use style="stroke:#000000;stroke-width:0.8;" x="182.050909" xlink:href="#m10db1555b6" y="307.584"/>
+ </g>
+ </g>
+ <g id="text_3">
+ <!-- 2 -->
+ <g transform="translate(178.869659 322.182437)scale(0.1 -0.1)">
+ <defs>
+ <path d="M 19.1875 8.296875
+L 53.609375 8.296875
+L 53.609375 0
+L 7.328125 0
+L 7.328125 8.296875
+Q 12.9375 14.109375 22.625 23.890625
+Q 32.328125 33.6875 34.8125 36.53125
+Q 39.546875 41.84375 41.421875 45.53125
+Q 43.3125 49.21875 43.3125 52.78125
+Q 43.3125 58.59375 39.234375 62.25
+Q 35.15625 65.921875 28.609375 65.921875
+Q 23.96875 65.921875 18.8125 64.3125
+Q 13.671875 62.703125 7.8125 59.421875
+L 7.8125 69.390625
+Q 13.765625 71.78125 18.9375 73
+Q 24.125 74.21875 28.421875 74.21875
+Q 39.75 74.21875 46.484375 68.546875
+Q 53.21875 62.890625 53.21875 53.421875
+Q 53.21875 48.921875 51.53125 44.890625
+Q 49.859375 40.875 45.40625 35.40625
+Q 44.1875 33.984375 37.640625 27.21875
+Q 31.109375 20.453125 19.1875 8.296875
+z
+" id="DejaVuSans-50"/>
+ </defs>
+ <use xlink:href="#DejaVuSans-50"/>
+ </g>
+ </g>
+ </g>
+ <g id="xtick_4">
+ <g id="line2d_4">
+ <g>
+ <use style="stroke:#000000;stroke-width:0.8;" x="236.16" xlink:href="#m10db1555b6" y="307.584"/>
+ </g>
+ </g>
+ <g id="text_4">
+ <!-- 3 -->
+ <g transform="translate(232.97875 322.182437)scale(0.1 -0.1)">
+ <defs>
+ <path d="M 40.578125 39.3125
+Q 47.65625 37.796875 51.625 33
+Q 55.609375 28.21875 55.609375 21.1875
+Q 55.609375 10.40625 48.1875 4.484375
+Q 40.765625 -1.421875 27.09375 -1.421875
+Q 22.515625 -1.421875 17.65625 -0.515625
+Q 12.796875 0.390625 7.625 2.203125
+L 7.625 11.71875
+Q 11.71875 9.328125 16.59375 8.109375
+Q 21.484375 6.890625 26.8125 6.890625
+Q 36.078125 6.890625 40.9375 10.546875
+Q 45.796875 14.203125 45.796875 21.1875
+Q 45.796875 27.640625 41.28125 31.265625
+Q 36.765625 34.90625 28.71875 34.90625
+L 20.21875 34.90625
+L 20.21875 43.015625
+L 29.109375 43.015625
+Q 36.375 43.015625 40.234375 45.921875
+Q 44.09375 48.828125 44.09375 54.296875
+Q 44.09375 59.90625 40.109375 62.90625
+Q 36.140625 65.921875 28.71875 65.921875
+Q 24.65625 65.921875 20.015625 65.03125
+Q 15.375 64.15625 9.8125 62.3125
+L 9.8125 71.09375
+Q 15.4375 72.65625 20.34375 73.4375
+Q 25.25 74.21875 29.59375 74.21875
+Q 40.828125 74.21875 47.359375 69.109375
+Q 53.90625 64.015625 53.90625 55.328125
+Q 53.90625 49.265625 50.4375 45.09375
+Q 46.96875 40.921875 40.578125 39.3125
+z
+" id="DejaVuSans-51"/>
+ </defs>
+ <use xlink:href="#DejaVuSans-51"/>
+ </g>
+ </g>
+ </g>
+ <g id="xtick_5">
+ <g id="line2d_5">
+ <g>
+ <use style="stroke:#000000;stroke-width:0.8;" x="290.269091" xlink:href="#m10db1555b6" y="307.584"/>
+ </g>
+ </g>
+ <g id="text_5">
+ <!-- 4 -->
+ <g transform="translate(287.087841 322.182437)scale(0.1 -0.1)">
+ <defs>
+ <path d="M 37.796875 64.3125
+L 12.890625 25.390625
+L 37.796875 25.390625
+z
+M 35.203125 72.90625
+L 47.609375 72.90625
+L 47.609375 25.390625
+L 58.015625 25.390625
+L 58.015625 17.1875
+L 47.609375 17.1875
+L 47.609375 0
+L 37.796875 0
+L 37.796875 17.1875
+L 4.890625 17.1875
+L 4.890625 26.703125
+z
+" id="DejaVuSans-52"/>
+ </defs>
+ <use xlink:href="#DejaVuSans-52"/>
+ </g>
+ </g>
+ </g>
+ <g id="xtick_6">
+ <g id="line2d_6">
+ <g>
+ <use style="stroke:#000000;stroke-width:0.8;" x="344.378182" xlink:href="#m10db1555b6" y="307.584"/>
+ </g>
+ </g>
+ <g id="text_6">
+ <!-- 5 -->
+ <g transform="translate(341.196932 322.182437)scale(0.1 -0.1)">
+ <defs>
+ <path d="M 10.796875 72.90625
+L 49.515625 72.90625
+L 49.515625 64.59375
+L 19.828125 64.59375
+L 19.828125 46.734375
+Q 21.96875 47.46875 24.109375 47.828125
+Q 26.265625 48.1875 28.421875 48.1875
+Q 40.625 48.1875 47.75 41.5
+Q 54.890625 34.8125 54.890625 23.390625
+Q 54.890625 11.625 47.5625 5.09375
+Q 40.234375 -1.421875 26.90625 -1.421875
+Q 22.3125 -1.421875 17.546875 -0.640625
+Q 12.796875 0.140625 7.71875 1.703125
+L 7.71875 11.625
+Q 12.109375 9.234375 16.796875 8.0625
+Q 21.484375 6.890625 26.703125 6.890625
+Q 35.15625 6.890625 40.078125 11.328125
+Q 45.015625 15.765625 45.015625 23.390625
+Q 45.015625 31 40.078125 35.4375
+Q 35.15625 39.890625 26.703125 39.890625
+Q 22.75 39.890625 18.8125 39.015625
+Q 14.890625 38.140625 10.796875 36.28125
+z
+" id="DejaVuSans-53"/>
+ </defs>
+ <use xlink:href="#DejaVuSans-53"/>
+ </g>
+ </g>
+ </g>
+ <g id="xtick_7">
+ <g id="line2d_7">
+ <g>
+ <use style="stroke:#000000;stroke-width:0.8;" x="398.487273" xlink:href="#m10db1555b6" y="307.584"/>
+ </g>
+ </g>
+ <g id="text_7">
+ <!-- 6 -->
+ <g transform="translate(395.306023 322.182437)scale(0.1 -0.1)">
+ <defs>
+ <path d="M 33.015625 40.375
+Q 26.375 40.375 22.484375 35.828125
+Q 18.609375 31.296875 18.609375 23.390625
+Q 18.609375 15.53125 22.484375 10.953125
+Q 26.375 6.390625 33.015625 6.390625
+Q 39.65625 6.390625 43.53125 10.953125
+Q 47.40625 15.53125 47.40625 23.390625
+Q 47.40625 31.296875 43.53125 35.828125
+Q 39.65625 40.375 33.015625 40.375
+z
+M 52.59375 71.296875
+L 52.59375 62.3125
+Q 48.875 64.0625 45.09375 64.984375
+Q 41.3125 65.921875 37.59375 65.921875
+Q 27.828125 65.921875 22.671875 59.328125
+Q 17.53125 52.734375 16.796875 39.40625
+Q 19.671875 43.65625 24.015625 45.921875
+Q 28.375 48.1875 33.59375 48.1875
+Q 44.578125 48.1875 50.953125 41.515625
+Q 57.328125 34.859375 57.328125 23.390625
+Q 57.328125 12.15625 50.6875 5.359375
+Q 44.046875 -1.421875 33.015625 -1.421875
+Q 20.359375 -1.421875 13.671875 8.265625
+Q 6.984375 17.96875 6.984375 36.375
+Q 6.984375 53.65625 15.1875 63.9375
+Q 23.390625 74.21875 37.203125 74.21875
+Q 40.921875 74.21875 44.703125 73.484375
+Q 48.484375 72.75 52.59375 71.296875
+z
+" id="DejaVuSans-54"/>
+ </defs>
+ <use xlink:href="#DejaVuSans-54"/>
+ </g>
+ </g>
+ </g>
+ </g>
+ <g id="matplotlib.axis_2">
+ <g id="ytick_1">
+ <g id="line2d_8">
+ <defs>
+ <path d="M 0 0
+L -3.5 0
+" id="me27c8cc867" style="stroke:#000000;stroke-width:0.8;"/>
+ </defs>
+ <g>
+ <use style="stroke:#000000;stroke-width:0.8;" x="73.832727" xlink:href="#me27c8cc867" y="307.584"/>
+ </g>
+ </g>
+ <g id="text_8">
+ <!-- 0.0 -->
+ <g transform="translate(50.929602 311.383219)scale(0.1 -0.1)">
+ <defs>
+ <path d="M 10.6875 12.40625
+L 21 12.40625
+L 21 0
+L 10.6875 0
+z
+" id="DejaVuSans-46"/>
+ </defs>
+ <use xlink:href="#DejaVuSans-48"/>
+ <use x="63.623047" xlink:href="#DejaVuSans-46"/>
+ <use x="95.410156" xlink:href="#DejaVuSans-48"/>
+ </g>
+ </g>
+ </g>
+ <g id="ytick_2">
+ <g id="line2d_9">
+ <g>
+ <use style="stroke:#000000;stroke-width:0.8;" x="73.832727" xlink:href="#me27c8cc867" y="256.890016"/>
+ </g>
+ </g>
+ <g id="text_9">
+ <!-- 0.2 -->
+ <g transform="translate(50.929602 260.689235)scale(0.1 -0.1)">
+ <use xlink:href="#DejaVuSans-48"/>
+ <use x="63.623047" xlink:href="#DejaVuSans-46"/>
+ <use x="95.410156" xlink:href="#DejaVuSans-50"/>
+ </g>
+ </g>
+ </g>
+ <g id="ytick_3">
+ <g id="line2d_10">
+ <g>
+ <use style="stroke:#000000;stroke-width:0.8;" x="73.832727" xlink:href="#me27c8cc867" y="206.196033"/>
+ </g>
+ </g>
+ <g id="text_10">
+ <!-- 0.4 -->
+ <g transform="translate(50.929602 209.995251)scale(0.1 -0.1)">
+ <use xlink:href="#DejaVuSans-48"/>
+ <use x="63.623047" xlink:href="#DejaVuSans-46"/>
+ <use x="95.410156" xlink:href="#DejaVuSans-52"/>
+ </g>
+ </g>
+ </g>
+ <g id="ytick_4">
+ <g id="line2d_11">
+ <g>
+ <use style="stroke:#000000;stroke-width:0.8;" x="73.832727" xlink:href="#me27c8cc867" y="155.502049"/>
+ </g>
+ </g>
+ <g id="text_11">
+ <!-- 0.6 -->
+ <g transform="translate(50.929602 159.301268)scale(0.1 -0.1)">
+ <use xlink:href="#DejaVuSans-48"/>
+ <use x="63.623047" xlink:href="#DejaVuSans-46"/>
+ <use x="95.410156" xlink:href="#DejaVuSans-54"/>
+ </g>
+ </g>
+ </g>
+ <g id="ytick_5">
+ <g id="line2d_12">
+ <g>
+ <use style="stroke:#000000;stroke-width:0.8;" x="73.832727" xlink:href="#me27c8cc867" y="104.808065"/>
+ </g>
+ </g>
+ <g id="text_12">
+ <!-- 0.8 -->
+ <g transform="translate(50.929602 108.607284)scale(0.1 -0.1)">
+ <defs>
+ <path d="M 31.78125 34.625
+Q 24.75 34.625 20.71875 30.859375
+Q 16.703125 27.09375 16.703125 20.515625
+Q 16.703125 13.921875 20.71875 10.15625
+Q 24.75 6.390625 31.78125 6.390625
+Q 38.8125 6.390625 42.859375 10.171875
+Q 46.921875 13.96875 46.921875 20.515625
+Q 46.921875 27.09375 42.890625 30.859375
+Q 38.875 34.625 31.78125 34.625
+z
+M 21.921875 38.8125
+Q 15.578125 40.375 12.03125 44.71875
+Q 8.5 49.078125 8.5 55.328125
+Q 8.5 64.0625 14.71875 69.140625
+Q 20.953125 74.21875 31.78125 74.21875
+Q 42.671875 74.21875 48.875 69.140625
+Q 55.078125 64.0625 55.078125 55.328125
+Q 55.078125 49.078125 51.53125 44.71875
+Q 48 40.375 41.703125 38.8125
+Q 48.828125 37.15625 52.796875 32.3125
+Q 56.78125 27.484375 56.78125 20.515625
+Q 56.78125 9.90625 50.3125 4.234375
+Q 43.84375 -1.421875 31.78125 -1.421875
+Q 19.734375 -1.421875 13.25 4.234375
+Q 6.78125 9.90625 6.78125 20.515625
+Q 6.78125 27.484375 10.78125 32.3125
+Q 14.796875 37.15625 21.921875 38.8125
+z
+M 18.3125 54.390625
+Q 18.3125 48.734375 21.84375 45.5625
+Q 25.390625 42.390625 31.78125 42.390625
+Q 38.140625 42.390625 41.71875 45.5625
+Q 45.3125 48.734375 45.3125 54.390625
+Q 45.3125 60.0625 41.71875 63.234375
+Q 38.140625 66.40625 31.78125 66.40625
+Q 25.390625 66.40625 21.84375 63.234375
+Q 18.3125 60.0625 18.3125 54.390625
+z
+" id="DejaVuSans-56"/>
+ </defs>
+ <use xlink:href="#DejaVuSans-48"/>
+ <use x="63.623047" xlink:href="#DejaVuSans-46"/>
+ <use x="95.410156" xlink:href="#DejaVuSans-56"/>
+ </g>
+ </g>
+ </g>
+ <g id="ytick_6">
+ <g id="line2d_13">
+ <g>
+ <use style="stroke:#000000;stroke-width:0.8;" x="73.832727" xlink:href="#me27c8cc867" y="54.114081"/>
+ </g>
+ </g>
+ <g id="text_13">
+ <!-- 1.0 -->
+ <g transform="translate(50.929602 57.9133)scale(0.1 -0.1)">
+ <use xlink:href="#DejaVuSans-49"/>
+ <use x="63.623047" xlink:href="#DejaVuSans-46"/>
+ <use x="95.410156" xlink:href="#DejaVuSans-48"/>
+ </g>
+ </g>
+ </g>
+ </g>
+ <g id="line2d_14">
+ <path clip-path="url(#p123f0cd496)" d="M 73.832727 54.114081
+L 77.112066 69.019649
+L 80.391405 83.048678
+L 83.670744 96.252716
+L 86.950083 108.680276
+L 90.229421 120.37702
+L 93.50876 131.385925
+L 96.788099 141.74744
+L 100.067438 151.499634
+L 103.346777 160.678341
+L 106.626116 169.317284
+L 109.905455 177.448205
+L 113.184793 185.100978
+L 116.464132 192.303722
+L 119.743471 199.082901
+L 123.02281 205.463423
+L 126.302149 211.468732
+L 129.581488 217.120892
+L 132.860826 222.440671
+L 136.140165 227.447615
+L 139.419504 232.16012
+L 142.698843 236.595501
+L 145.978182 240.770055
+L 149.257521 244.69912
+L 152.53686 248.397132
+L 155.816198 251.877678
+L 159.095537 255.153548
+L 162.374876 258.236776
+L 165.654215 261.138692
+L 168.933554 263.869957
+L 172.212893 266.440608
+L 175.492231 268.860089
+L 178.77157 271.137289
+L 182.050909 273.280577
+L 185.330248 275.297826
+L 188.609587 277.196449
+L 191.888926 278.983421
+L 195.168264 280.665308
+L 198.447603 282.24829
+L 201.726942 283.738184
+L 205.006281 285.140462
+L 208.28562 286.460278
+L 211.564959 287.702481
+L 214.844298 288.871635
+L 218.123636 289.972035
+L 221.402975 291.007726
+L 224.682314 291.982511
+L 227.961653 292.899973
+L 231.240992 293.763483
+L 234.520331 294.576213
+L 237.799669 295.34115
+L 241.079008 296.061103
+L 244.358347 296.73872
+L 247.637686 297.376488
+L 250.917025 297.976751
+L 254.196364 298.541716
+L 257.475702 299.073457
+L 260.755041 299.573928
+L 264.03438 300.044969
+L 267.313719 300.48831
+L 270.593058 300.905579
+L 273.872397 301.298311
+L 277.151736 301.667948
+L 280.431074 302.015847
+L 283.710413 302.343288
+L 286.989752 302.651474
+L 290.269091 302.941537
+L 293.54843 303.214541
+L 296.827769 303.471492
+L 300.107107 303.713333
+L 303.386446 303.940951
+L 306.665785 304.155185
+L 309.945124 304.35682
+L 313.224463 304.546597
+L 316.503802 304.725215
+L 319.78314 304.893329
+L 323.062479 305.051557
+L 326.341818 305.20048
+L 329.621157 305.340645
+L 332.900496 305.472568
+L 336.179835 305.596733
+L 339.459174 305.713596
+L 342.738512 305.823587
+L 346.017851 305.92711
+L 349.29719 306.024546
+L 352.576529 306.116251
+L 355.855868 306.202563
+L 359.135207 306.2838
+L 362.414545 306.36026
+L 365.693884 306.432223
+L 368.973223 306.499955
+L 372.252562 306.563703
+L 375.531901 306.623703
+L 378.81124 306.680174
+L 382.090579 306.733325
+L 385.369917 306.783349
+L 388.649256 306.830432
+L 391.928595 306.874747
+L 395.207934 306.916455
+L 398.487273 306.955711
+" style="fill:none;stroke:#0000ff;stroke-linecap:square;stroke-width:1.5;"/>
+ </g>
+ <g id="patch_4">
+ <path d="M 73.832727 307.584
+L 73.832727 41.472
+" style="fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;"/>
+ </g>
+ <g id="patch_5">
+ <path d="M 57.6 307.584
+L 414.72 307.584
+" style="fill:none;stroke:#000000;stroke-linecap:square;stroke-linejoin:miter;stroke-width:0.8;"/>
+ </g>
+ </g>
+ </g>
+ <defs>
+ <clipPath id="p123f0cd496">
+ <rect height="266.112" width="357.12" x="57.6" y="41.472"/>
+ </clipPath>
+ </defs>
+</svg>
diff --git a/tests/test_graphical_units/img_svg_resources/rotate.svg b/tests/test_graphical_units/img_svg_resources/rotate.svg
new file mode 100644
index 000000000..27f4e86e2
--- /dev/null
+++ b/tests/test_graphical_units/img_svg_resources/rotate.svg
@@ -0,0 +1,9 @@
+<svg viewBox="-12 -2 34 14" xmlns="http://www.w3.org/2000/svg">
+ <rect x="0" y="0" width="10" height="10" />
+
+ <!-- rotation is done around the point 0,0 -->
+ <rect x="0" y="0" width="10" height="10" fill="red" transform="rotate(100)" />
+
+ <!-- rotation is done around the point 10,10 -->
+ <rect x="0" y="0" width="10" height="10" fill="green" transform="rotate(100,10,10)" />
+</svg>
\ No newline at end of file
diff --git a/tests/test_graphical_units/img_svg_resources/scale.svg b/tests/test_graphical_units/img_svg_resources/scale.svg
new file mode 100644
index 000000000..ab12badf2
--- /dev/null
+++ b/tests/test_graphical_units/img_svg_resources/scale.svg
@@ -0,0 +1,13 @@
+<svg viewBox="-50 -50 100 100" xmlns="http://www.w3.org/2000/svg">
+ <!-- uniform scale -->
+ <circle cx="0" cy="0" r="10" fill="red" transform="scale(4)" />
+
+ <!-- vertical scale -->
+ <circle cx="0" cy="0" r="10" fill="yellow" transform="scale(1,4)" />
+
+ <!-- horizontal scale -->
+ <circle cx="0" cy="0" r="10" fill="pink" transform="scale(4,1)" />
+
+ <!-- No scale -->
+ <circle cx="0" cy="0" r="10" fill="black" />
+</svg>
\ No newline at end of file
diff --git a/tests/test_graphical_units/img_svg_resources/skewX.svg b/tests/test_graphical_units/img_svg_resources/skewX.svg
new file mode 100644
index 000000000..497f8cf67
--- /dev/null
+++ b/tests/test_graphical_units/img_svg_resources/skewX.svg
@@ -0,0 +1,5 @@
+<svg viewBox="-5 -5 10 10" xmlns="http://www.w3.org/2000/svg">
+ <rect x="-3" y="-3" width="6" height="6" />
+
+ <rect x="-3" y="-3" width="6" height="6" fill="red" transform="skewX(30)" />
+</svg>
\ No newline at end of file
diff --git a/tests/test_graphical_units/img_svg_resources/skewY.svg b/tests/test_graphical_units/img_svg_resources/skewY.svg
new file mode 100644
index 000000000..9ac6b5a69
--- /dev/null
+++ b/tests/test_graphical_units/img_svg_resources/skewY.svg
@@ -0,0 +1,5 @@
+<svg viewBox="-5 -5 10 10" xmlns="http://www.w3.org/2000/svg">
+ <rect x="-3" y="-3" width="6" height="6" />
+
+ <rect x="-3" y="-3" width="6" height="6" fill="red" transform="skewY(30)" />
+</svg>
\ No newline at end of file
diff --git a/tests/test_graphical_units/img_svg_resources/translate.svg b/tests/test_graphical_units/img_svg_resources/translate.svg
new file mode 100644
index 000000000..4444de93a
--- /dev/null
+++ b/tests/test_graphical_units/img_svg_resources/translate.svg
@@ -0,0 +1,13 @@
+<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
+ <!-- No translation -->
+ <rect x="5" y="5" width="40" height="40" fill="green" />
+
+ <!-- Horizontal translation -->
+ <rect x="5" y="5" width="40" height="40" fill="blue" transform="translate(50)" />
+
+ <!-- Vertical translation -->
+ <rect x="5" y="5" width="40" height="40" fill="red" transform="translate(0 50)" />
+
+ <!-- Both horizontal and vertical translation -->
+ <rect x="5" y="5" width="40" height="40" fill="yellow" transform="translate(50,50)" />
+</svg>
\ No newline at end of file
diff --git a/tests/test_graphical_units/test_img_and_svg.py b/tests/test_graphical_units/test_img_and_svg.py
index bf9702f6a..42c107eb9 100644
--- a/tests/test_graphical_units/test_img_and_svg.py
+++ b/tests/test_graphical_units/test_img_and_svg.py
@@ -169,6 +169,55 @@ class VideoIconTest(Scene):
self.wait()
+class MultipleTransformTest(Scene):
+ def construct(self):
+ svg_obj = SVGMobject(get_test_resource("multiple_transforms.svg"))
+ self.add(svg_obj)
+ self.wait()
+
+
+class MatrixTransformTest(Scene):
+ def construct(self):
+ svg_obj = SVGMobject(get_test_resource("matrix.svg"))
+ self.add(svg_obj)
+ self.wait()
+
+
+class ScaleTransformTest(Scene):
+ def construct(self):
+ svg_obj = SVGMobject(get_test_resource("scale.svg"))
+ self.add(svg_obj)
+ self.wait()
+
+
+class TranslateTransformTest(Scene):
+ def construct(self):
+ svg_obj = SVGMobject(get_test_resource("translate.svg"))
+ self.add(svg_obj)
+ self.wait()
+
+
+class SkewXTransformTest(Scene):
+ def construct(self):
+ svg_obj = SVGMobject(get_test_resource("skewX.svg"))
+ self.add(svg_obj)
+ self.wait()
+
+
+class SkewYTransformTest(Scene):
+ def construct(self):
+ svg_obj = SVGMobject(get_test_resource("skewY.svg"))
+ self.add(svg_obj)
+ self.wait()
+
+
+class RotateTransformTest(Scene):
+ def construct(self):
+ svg_obj = SVGMobject(get_test_resource("rotate.svg"))
+ self.add(svg_obj)
+ self.wait()
+
+
class ImageMobjectTest(Scene):
def construct(self):
file_path = get_test_resource("tree_img_640x351.png")