src/ldObject.cpp

changeset 1002
a3ee23db8393
parent 1000
c064cc048f14
child 1003
31873c3cbdbc
equal deleted inserted replaced
1001:024cbc902e75 1002:a3ee23db8393
222 // Remove the old object 222 // Remove the old object
223 destroy(); 223 destroy();
224 } 224 }
225 } 225 }
226 226
227 void LDObject::replace (const LDObjectList& others)
228 {
229 int idx = lineNumber();
230
231 if (idx != -1 and not others.isEmpty())
232 {
233 for (int i = 1; i < others.size(); ++i)
234 document()->insertObj (idx + i, others[i]);
235
236 document()->setObject (idx, others[0]);
237 destroy();
238 }
239 }
240
227 // ============================================================================= 241 // =============================================================================
228 // 242 //
229 // Swap this object with another. 243 // Swap this object with another.
230 // 244 //
231 void LDObject::swap (LDObject* other) 245 void LDObject::swap (LDObject* other)
1054 void LDOverlay::setFileName (QString value) 1068 void LDOverlay::setFileName (QString value)
1055 { 1069 {
1056 m_fileName = value; 1070 m_fileName = value;
1057 } 1071 }
1058 1072
1073 Vertex LDBezierCurve::pointAt (qreal t) const
1074 {
1075 if (t >= 0.0 and t <= 1.0)
1076 {
1077 Vertex result;
1078 result += pow (1.0 - t, 3) * vertex (0);
1079 result += (3 * pow (1.0 - t, 2) * t) * vertex (2);
1080 result += (3 * (1.0 - t) * pow (t, 2)) * vertex (3);
1081 result += pow (t, 3) * vertex (1);
1082 return result;
1083 }
1084 else
1085 return Vertex();
1086 }
1087
1088 LDObjectList LDBezierCurve::rasterize (int segments)
1089 {
1090 LDObjectList result;
1091 QVector<Vertex> parms;
1092 parms.append (pointAt (0.0));
1093
1094 for (int i = 1; i < segments; ++i)
1095 parms.append (pointAt (double (i) / segments));
1096
1097 parms.append (pointAt (1.0));
1098
1099 for (int i = 0; i < segments; ++i)
1100 result << new LDLine (parms[i], parms[i + 1]);
1101
1102 return result;
1103 }
1104
1059 // ============================================================================= 1105 // =============================================================================
1060 // 1106 //
1061 // Selects this object. 1107 // Selects this object.
1062 // 1108 //
1063 void LDObject::select() 1109 void LDObject::select()

mercurial