bool MgPath::arcTo(const Point2d& point, const Point2d& end, bool rel) { bool ret = false; Point2d lastpt(getEndPoint()); if (m_data->beginIndex >= 0 && getSize(m_data->points) >= m_data->beginIndex + 1 && m_data->points.size() == m_data->types.size()) { Point2d start = m_data->points[m_data->points.size() - 1]; Point2d center; float radius, startAngle, sweepAngle; if (mgcurv::arc3P(start, rel ? point + lastpt : point, rel ? end + lastpt : end, center, radius, &startAngle, &sweepAngle)) { Point2d pts[16]; int n = mgcurv::arcToBezier(pts, center, radius, radius, startAngle, sweepAngle); if (n >= 4) { ret = true; for (int i = 1; i < n; i++) { m_data->points.push_back(pts[i]); m_data->types.push_back(kMgBezierTo); } } } } return ret; }
void addNumpyToPolygonF(QPolygonF& poly, const Tuple2Ptrs& d) { // iterate over rows until none left const int numcols = d.data.size(); QPointF lastpt(-1e6, -1e6); for(int row=0 ; ; ++row) { bool ifany = false; // the numcols-1 makes sure we don't get odd numbers of columns for(int col=0; col < (numcols-1); col += 2) { // add point if point in two columns if( row < d.dims[col] && row < d.dims[col+1] ) { const QPointF pt(d.data[col][row], d.data[col+1][row]); if( ! smallDelta(pt, lastpt) ) { poly << pt; lastpt = pt; } ifany = true; } } // exit loop if no more columns if(! ifany ) break; } }
void plotPathsToPainter(QPainter& painter, QPainterPath& path, const Numpy1DObj& x, const Numpy1DObj& y, const Numpy1DObj* scaling, const QRectF* clip, const QImage* colorimg) { QRectF cliprect( QPointF(-32767,-32767), QPointF(32767,32767) ); if( clip != 0 ) { qreal x1, y1, x2, y2; clip->getCoords(&x1, &y1, &x2, &y2); cliprect.setCoords(x1, y1, x2, y2); } QRectF pathbox = path.boundingRect(); cliprect.adjust(pathbox.left(), pathbox.top(), pathbox.bottom(), pathbox.right()); // keep track of duplicate points QPointF lastpt(-1e6, -1e6); // keep original transformation for restoration after each iteration QTransform origtrans(painter.worldTransform()); // number of iterations int size = min(x.dim, y.dim); // if few color points, trim down number of paths if( colorimg != 0 ) size = min(size, colorimg->width()); // too few scaling points if( scaling != 0 ) size = min(size, scaling->dim); // draw each path for(int i = 0; i < size; ++i) { const QPointF pt(x(i), y(i)); if( cliprect.contains(pt) && ! smallDelta(lastpt, pt) ) { painter.translate(pt); if( scaling != 0 ) { // scale point if requested const qreal s = (*scaling)(i); painter.scale(s, s); } if( colorimg != 0 ) { // get color from pixel and create a new brush QBrush b( QColor::fromRgba(colorimg->pixel(i, 0)) ); painter.setBrush(b); } painter.drawPath(path); painter.setWorldTransform(origtrans); lastpt = pt; } } }
bool MgPath::quadTo(const Point2d& cp, const Point2d& end, bool rel) { Point2d lastpt(getEndPoint()); m_data->points.push_back(rel ? cp + lastpt : cp); m_data->points.push_back(rel ? end + lastpt : end); m_data->types.push_back(kMgQuadTo); m_data->types.push_back(kMgQuadTo); return true; }
bool MgPath::smoothQuadTo(const Point2d& end, bool rel) { Point2d lastpt(getEndPoint()); Point2d cp(m_data->points.size() > 1 ? 2 * lastpt - m_data->points[m_data->points.size() - 2].asVector() : lastpt); m_data->points.push_back(cp); m_data->points.push_back(rel ? end + lastpt : end); m_data->types.push_back(kMgQuadTo); m_data->types.push_back(kMgQuadTo); return true; }
bool MgPath::bezierTo(const Point2d& cp1, const Point2d& cp2, const Point2d& end, bool rel) { Point2d lastpt(getEndPoint()); m_data->points.push_back(rel ? cp1 + lastpt : cp1); m_data->points.push_back(rel ? cp2 + lastpt : cp2); m_data->points.push_back(rel ? end + lastpt : end); for (int i = 0; i < 3; i++) m_data->types.push_back(kMgBezierTo); return true; }
bool MgPath::smoothBezierTo(const Point2d& cp2, const Point2d& end, bool rel) { Point2d lastpt(getEndPoint()); Point2d cp1(m_data->points.size() > 1 ? 2 * lastpt - m_data->points[m_data->points.size() - 2].asVector() : lastpt); m_data->points.push_back(cp1); m_data->points.push_back(rel ? cp2 + lastpt : cp2); m_data->points.push_back(rel ? end + lastpt : end); for (int i = 0; i < 3; i++) m_data->types.push_back(kMgBezierTo); return true; }
bool MgPath::linesTo(int count, const Point2d* points, bool rel) { bool ret = (m_data->beginIndex >= 0 && count > 0 && points); Point2d lastpt(getEndPoint()); if (ret) { for (int i = 0; i < count; i++) { m_data->points.push_back(rel ? points[i] + lastpt : points[i]); m_data->types.push_back(kMgLineTo); } } return ret; }
bool MgPath::beziersTo(int count, const Point2d* points, bool reverse, bool rel) { bool ret = (m_data->beginIndex >= 0 && count > 0 && points && (count % 3) == 0); Point2d lastpt(getEndPoint()); if (ret && reverse) { for (int i = count - 1; i >= 0; i--) { m_data->points.push_back(rel ? points[i] + lastpt : points[i]); m_data->types.push_back(kMgBezierTo); } } else if (ret) { for (int i = 0; i < count; i++) { m_data->points.push_back(rel ? points[i] + lastpt : points[i]); m_data->types.push_back(kMgBezierTo); } } return ret; }