diff -r 024cbc902e75 -r a3ee23db8393 src/ldObject.cpp --- a/src/ldObject.cpp Sun Oct 04 04:27:38 2015 +0300 +++ b/src/ldObject.cpp Sun Oct 04 06:31:36 2015 +0300 @@ -224,6 +224,20 @@ } } +void LDObject::replace (const LDObjectList& others) +{ + int idx = lineNumber(); + + if (idx != -1 and not others.isEmpty()) + { + for (int i = 1; i < others.size(); ++i) + document()->insertObj (idx + i, others[i]); + + document()->setObject (idx, others[0]); + destroy(); + } +} + // ============================================================================= // // Swap this object with another. @@ -1056,6 +1070,38 @@ m_fileName = value; } +Vertex LDBezierCurve::pointAt (qreal t) const +{ + if (t >= 0.0 and t <= 1.0) + { + Vertex result; + result += pow (1.0 - t, 3) * vertex (0); + result += (3 * pow (1.0 - t, 2) * t) * vertex (2); + result += (3 * (1.0 - t) * pow (t, 2)) * vertex (3); + result += pow (t, 3) * vertex (1); + return result; + } + else + return Vertex(); +} + +LDObjectList LDBezierCurve::rasterize (int segments) +{ + LDObjectList result; + QVector parms; + parms.append (pointAt (0.0)); + + for (int i = 1; i < segments; ++i) + parms.append (pointAt (double (i) / segments)); + + parms.append (pointAt (1.0)); + + for (int i = 0; i < segments; ++i) + result << new LDLine (parms[i], parms[i + 1]); + + return result; +} + // ============================================================================= // // Selects this object.