diff options
author | oehhar <harald.oehlmann@elmicron.de> | 2021-03-31 18:23:45 (GMT) |
---|---|---|
committer | oehhar <harald.oehlmann@elmicron.de> | 2021-03-31 18:23:45 (GMT) |
commit | 5de1c70e9572b7c1695b987a44d8cec8e40aac41 (patch) | |
tree | 84884123498b4e98114d26b53f8cb0c847e4be03 | |
parent | feb4cedf2bc123276a2997508048e4862ba70ce4 (diff) | |
download | tk-5de1c70e9572b7c1695b987a44d8cec8e40aac41.zip tk-5de1c70e9572b7c1695b987a44d8cec8e40aac41.tar.gz tk-5de1c70e9572b7c1695b987a44d8cec8e40aac41.tar.bz2 |
Imported fix for: nanosvg #179: "Division by float 0"
-rw-r--r-- | generic/nanosvg.h | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/generic/nanosvg.h b/generic/nanosvg.h index 5142bf3..9a6eb3f 100644 --- a/generic/nanosvg.h +++ b/generic/nanosvg.h @@ -2278,7 +2278,12 @@ static void nsvg__pathArcTo(NSVGparser* p, float* cpx, float* cpy, float* args, /* The loop assumes an iteration per end point (including start and end), this +1. */ ndivs = (int)(fabsf(da) / (NSVG_PI*0.5f) + 1.0f); hda = (da / (float)ndivs) / 2.0f; - kappa = fabsf(4.0f / 3.0f * (1.0f - cosf(hda)) / sinf(hda)); + /* Fix for ticket #179: division by 0: avoid cotangens around 0 (infinite) */ + if ((hda < 1e-3f) && (hda > -1e-3f)) + hda *= 0.5f; + else + hda = (1.0f - cosf(hda)) / sinf(hda); + kappa = fabsf(4.0f / 3.0f * hda); if (da < 0.0f) kappa = -kappa; |