Repository: meerk40t/svgelements

Issue:
Numerical Instability above the 1e-12 level for cubic bounding box.
```python
    def test_bbox_failure(self):
        p = Path(transform=Matrix(682.657124793113, 0.000000000003, -0.000000000003, 682.657124793113, 257913.248909660178, -507946.354527872754))
        p += CubicBezier(start=Point(-117.139521365,1480.99923469), control1=Point(-41.342266634,1505.62725567), control2=Point(40.3422666342,1505.62725567), end=Point(116.139521365,1480.99923469))
        bounds = p.bbox()
        self.assertNotAlmostEquals(bounds[1], bounds[3], delta=100)
```

This fails even though it's basically an arc and the y-range should be quite considerable.

See: meerk40t/meerk40t#1798



Discussion:

Patch:
diff --git a/svgelements/svgelements.py b/svgelements/svgelements.py
index e89a99d..804043e 100644
--- a/svgelements/svgelements.py
+++ b/svgelements/svgelements.py
@@ -4773,7 +4773,7 @@ class CubicBezier(Curve):
         local_extremizers = [0, 1]
         a = [c[v] for c in self]
         denom = a[0] - 3 * a[1] + 3 * a[2] - a[3]
-        if abs(denom) >= 1e-12:
+        if abs(denom) >= 1e-8:
             delta = (
                 a[1] * a[1] - (a[0] + a[1]) * a[2] + a[2] * a[2] + (a[0] - a[1]) * a[3]
             )


Test patch:
diff --git a/test/test_cubic_bezier.py b/test/test_cubic_bezier.py
index 37ef038..6927487 100644
--- a/test/test_cubic_bezier.py
+++ b/test/test_cubic_bezier.py
@@ -74,3 +74,9 @@ class TestElementCubicBezierPoint(unittest.TestCase):
             bbox2 = cubic2.bbox()
             for a, b in zip(bbox1, bbox2):
                 self.assertAlmostEqual(a, b, delta=1e-5)
+
+    def test_cubic_bounds_issue_220(self):
+        p = Path(transform=Matrix(682.657124793113, 0.000000000003, -0.000000000003, 682.657124793113, 257913.248909660178, -507946.354527872754))
+        p += CubicBezier(start=Point(-117.139521365,1480.99923469), control1=Point(-41.342266634,1505.62725567), control2=Point(40.3422666342,1505.62725567), end=Point(116.139521365,1480.99923469))
+        bounds = p.bbox()
+        self.assertNotAlmostEquals(bounds[1], bounds[3], delta=100)