File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change 55
66#include < cmath>
77#include < cstdint>
8+ #include < limits>
89
910#include " agg_clip_liang_barsky.h"
1011#include " mplutils.h"
@@ -1019,8 +1020,18 @@ class Sketch
10191020 {
10201021 rewind (0 );
10211022 const double d_M_PI = 3.14159265358979323846 ;
1022- m_p_scale = (2.0 * d_M_PI) / (m_length * m_randomness);
1023- m_log_randomness = 2.0 * log (m_randomness);
1023+ // Set derived values to zero if m_length or m_randomness are zero to
1024+ // avoid divide-by-zero errors when a sketch is created but not used.
1025+ if (m_length <= std::numeric_limits<double >::epsilon () || m_randomness <= std::numeric_limits<double >::epsilon ()) {
1026+ m_p_scale = 0.0 ;
1027+ } else {
1028+ m_p_scale = (2.0 * d_M_PI) / (m_length * m_randomness);
1029+ }
1030+ if (m_randomness <= std::numeric_limits<double >::epsilon ()) {
1031+ m_log_randomness = 0.0 ;
1032+ } else {
1033+ m_log_randomness = 2.0 * log (m_randomness);
1034+ }
10241035 }
10251036
10261037 unsigned vertex (double *x, double *y)
You can’t perform that action at this time.
0 commit comments