MCPcopy Create free account
hub / github.com/OpenBoard-org/OpenBoard / curveToPolygon

Method curveToPolygon

src/frameworks/UBGeometryUtils.cpp:247–265  ·  view source on GitHub ↗

* @brief Build and return a polygon from a list of points (at least 2), and start and end widths. * * The resulting polygon will pass by all points in the curve; its thickness is calculated at each point * of the curve (linearly interpolated between start and end widths) and the segments are joined by * (approximately) curved joints. * * Like with lineToPolygon, the ends are semi-circular.

Source from the content-addressed store, hash-verified

245 * Like with lineToPolygon, the ends are semi-circular.
246 */
247QPolygonF UBGeometryUtils::curveToPolygon(const QList<QPointF>& points, qreal startWidth, qreal endWidth)
248{
249 int n_points = points.size();
250
251 if (n_points < 2)
252 return QPolygonF();
253
254 if (n_points == 2)
255 return lineToPolygon(points[0], points[1], startWidth, endWidth);
256
257 QList<QPair<QPointF, qreal> > pointsAndWidths;
258 for (int i(0); i < n_points; ++i) {
259 qreal width = startWidth + (qreal(i)/qreal(n_points-1)) * (endWidth - startWidth);
260
261 pointsAndWidths << QPair<QPointF, qreal>(points[i], width);
262 }
263
264 return curveToPolygon(pointsAndWidths, true, true);
265}
266
267/**
268 * @brief Build and return a polygon from a list of points and thicknesses (at least 2)

Callers

nothing calls this directly

Calls 3

sizeMethod · 0.45
moveToMethod · 0.45
angleMethod · 0.45

Tested by

no test coverage detected