I also think that the number of segments of the path is probably the biggest problem.
Looking at what you are drawing, I think that you could compose your path using Bézier curves instead of lines. That would allow you to greatly reduce the size of the path.
Here is a function I use for this. Experiment to find the smallest number of points which produce a good result. Hope this helps!
/** Creates a curved path (a Catmull-Rom spline) which passes through a set of points.
The provided points determine the path's curvature, with no additional control points
being necessary. The path is composed entirely of cubic Bézier curves.
@param alpha determines the parameterization of the spline.
A value of 0.0f will cause it to be uniform, 0.5f centripetal, and 1.0f chordal.
@param roundness determines the general roundness of the spline.
Values above 1.0f will exaggerate it, a value of 0.0f will produce straight lines.
@param treatFirstAndLastPointsAsControls if false, the curvatures of the first
and last line segments are calculated automatically. If true, the path is
drawn from the second to the penultimate point, and the first and last points
control the curvatures of the first and last drawn line segments.
*/
inline Path createCurvedPath (const std::vector<Point<float>>& points,
float alpha = 0.5f,
float roundness = 1.0f,
bool treatFirstAndLastPointsAsControls = false) noexcept
{
jassert (points.size() >= 3); /// You need to provide at least three points
auto controlPoint = [alpha, roundness] (Point<float> p0, Point<float> p1, Point<float> p2)
{
auto d1 = p1.getDistanceFrom (p0);
auto d2 = p2.getDistanceFrom (p1);
if (d1 == 0)
return p1;
auto d1a = pow (d1, alpha);
auto d2a = pow (d2, alpha);
auto d1a2 = pow (d1, alpha * 2.0f);
auto d2a2 = pow (d2, alpha * 2.0f);
auto a = d1a2 * p2 - d2a2 * p0 + (d2a2 - d1a2) * p1;
auto b = 3.0f * d1a * (d1a + d2a);
return p1 + (a * roundness) / b;
};
auto mirror = [] (const Point<float> p, const Point<float> m)
{
return m - (p - m);
};
Path path;
auto s = int (points.size());
path.preallocateSpace (s * 7 + 4);
path.startNewSubPath (points[treatFirstAndLastPointsAsControls ? 1 : 0]);
if (! treatFirstAndLastPointsAsControls)
path.cubicTo (controlPoint (mirror (points[1], points[0]), points[0], points[1]),
controlPoint (points[2], points[1], points[0]),
points[1]);
for (int p = 1; p < s - 2; ++p)
path.cubicTo (controlPoint (points[p-1], points[p], points[p+1]),
controlPoint (points[p+2], points[p+1], points[p]),
points[p+1]);
if (! treatFirstAndLastPointsAsControls)
path.cubicTo (controlPoint (points[s-3], points[s-2], points[s-1]),
controlPoint (mirror (points[s-2], points[s-1]), points[s-1], points[s-2]),
points[s-1]);
return path;
}