Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 65b74d1

Browse files
committed
Minor cleanup and optimization of Sketch
1 parent a4c5ac5 commit 65b74d1

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/path_converters.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,8 @@ class Sketch
10181018
m_rand(0)
10191019
{
10201020
rewind(0);
1021+
const double d_M_PI = 3.14159265358979323846;
1022+
m_p_scale = (2.0 * d_M_PI) / m_length;
10211023
}
10221024

10231025
unsigned vertex(double *x, double *y)
@@ -1037,18 +1039,18 @@ class Sketch
10371039
// We want the "cursor" along the sine wave to move at a
10381040
// random rate.
10391041
double d_rand = m_rand.get_double();
1040-
double d_M_PI = 3.14159265358979323846;
10411042
m_p += pow(m_randomness, d_rand * 2.0 - 1.0);
1042-
double r = sin(m_p / (m_length / (d_M_PI * 2.0))) * m_scale;
10431043
double den = m_last_x - *x;
10441044
double num = m_last_y - *y;
10451045
double len = num * num + den * den;
10461046
m_last_x = *x;
10471047
m_last_y = *y;
10481048
if (len != 0) {
10491049
len = sqrt(len);
1050-
*x += r * num / len;
1051-
*y += r * -den / len;
1050+
double r = sin(m_p * m_p_scale) * m_scale;
1051+
double roverlen = r / len;
1052+
*x += roverlen * num;
1053+
*y -= roverlen * den;
10521054
}
10531055
} else {
10541056
m_last_x = *x;
@@ -1083,6 +1085,7 @@ class Sketch
10831085
bool m_has_last;
10841086
double m_p;
10851087
RandomNumberGenerator m_rand;
1088+
double m_p_scale;
10861089
};
10871090

10881091
#endif // MPL_PATH_CONVERTERS_H

0 commit comments

Comments
 (0)