Repository: googlefonts/picosvg

Issue:
Failed to extract translation
.local/lib/python3.7/site-packages/picosvg/svg_transform.py", line 339, in decompose_translation
    ), f"Failed to extract translation from {self}, parts compose back to {test_compose}"
AssertionError: Failed to extract translation from Affine2D(a=-4.382842e-08, b=1.0027, c=-4.2262, d=-1.847346e-07, e=1133.4812, f=889.4797), parts compose back to Affine2D(a=-4.382842e-08, b=1.0027, c=-4.2262, d=-1.847346e-07, e=1133.4812, f=889.4796970082031)


Discussion:

Patch:
diff --git a/src/picosvg/svg_transform.py b/src/picosvg/svg_transform.py
index 557b775..5e519bf 100644
--- a/src/picosvg/svg_transform.py
+++ b/src/picosvg/svg_transform.py
@@ -32,7 +32,7 @@ from picosvg.geometric_types import (
 )
 from picosvg.svg_meta import ntos
 
-DECOMPOSITION_ALMOST_EQUAL_TOLERANCE = 1e-6
+DECOMPOSITION_ALMOST_EQUAL_TOLERANCE = 1e-4
 
 _SVG_ARG_FIXUPS = collections.defaultdict(
     lambda: lambda _: None,


Test patch:
diff --git a/tests/svg_reuse_test.py b/tests/svg_reuse_test.py
index 56bfb4f..fff9e52 100644
--- a/tests/svg_reuse_test.py
+++ b/tests/svg_reuse_test.py
@@ -44,13 +44,6 @@ import pytest
             Affine2D.identity().translate(1, -1),
             0.01,
         ),
-        # different rects
-        (
-            SVGRect(x=20, y=20, width=100, height=20),
-            SVGRect(x=40, y=30, width=60, height=20),
-            Affine2D(a=0.6, b=0.0, c=0.0, d=1.0, e=28.0, f=10.0),
-            0.01,
-        ),
         # circles that may happen to match the ones Noto clock emoji
         (
             SVGCircle(cx=15.89, cy=64.13, r=4),
@@ -124,9 +117,9 @@ def test_svg_reuse(s1, s2, expected_affine, tolerance):
     if expected_affine:
         assert (
             affine
-        ), f"No affine found between {s1.as_path().d} and {s2.as_path().d}. Expected {expected_affine}"
+        ), f"No affine found between {s1.d} and {s2.d}. Expected {expected_affine}"
         # Round because we've seen issues with different test environments when overly fine
         affine = affine.round(4)
     assert (
         affine == expected_affine
-    ), f"Unexpected affine found between {s1.as_path().d} and {s2.as_path().d}."
+    ), f"Unexpected affine found between {s1.d} and {s2.d}."
diff --git a/tests/svg_transform_test.py b/tests/svg_transform_test.py
index 2f18abe..d20dc60 100644
--- a/tests/svg_transform_test.py
+++ b/tests/svg_transform_test.py
@@ -353,6 +353,21 @@ class TestAffine2D:
                 Affine2D(1, 0, 0, 1, 50, -100),
                 Affine2D(0, -1.0, 1.0, 0, 0, 0),
             ),
+            # https://github.com/googlefonts/picosvg/issues/239
+            (
+                Affine2D(
+                    a=-4.382842e-08,
+                    b=1.0027,
+                    c=-4.2262,
+                    d=-1.847346e-07,
+                    e=1133.4812,
+                    f=889.4797,
+                ),
+                Affine2D(a=1, b=0, c=0, d=1, e=887.0845192597527, f=-268.2034070511364),
+                Affine2D(
+                    a=-4.382842e-08, b=1.0027, c=-4.2262, d=-1.847346e-07, e=0, f=0
+                ),
+            ),
         ],
     )
     def test_decompose_translation(