QT_BEGIN_NAMESPACE #define CURVE_FLATNESS Q_PI / 8 void QTriangulatingStroker::endCapOrJoinClosed(const qreal *start, const qreal *cur, bool implicitClose, bool endsAtStart) { if (endsAtStart) { join(start + 2); } else if (implicitClose) { join(start); lineTo(start); join(start+2); } else { endCap(cur); } int count = m_vertices.size(); // Copy the (x, y) values because QDataBuffer::add(const float& t) // may resize the buffer, which will leave t pointing at the // previous buffer's memory region if we don't copy first. float x = m_vertices.at(count-2); float y = m_vertices.at(count-1); m_vertices.add(x); m_vertices.add(y); }
std::vector<Point> generateEndCap(const Line& targetEdge,const Point& targetEndpoint, const std::vector<Line>& adjacentEdges, const std::vector<Line>& crossSectionLines) { std::vector<Vector> adjacentEdgeVectors(adjacentEdges.size()); for (int i=0;i<adjacentEdges.size();i++) { Line oe=adjacentEdges.at(i); Point oeEnd=oe.getPointA(); if (Point::almostEqual(oeEnd, targetEndpoint)) { adjacentEdgeVectors.at(i)=oe.getVector(); } else { adjacentEdgeVectors.at(i)=oe.getVector()*-1; } } std::vector<Plane> endCapPlanes; for (int i=0;i<adjacentEdges.size();i++) { Vector reVector=targetEdge.getVector(); if (!(Point::almostEqual(targetEdge.getPointA(), targetEndpoint))) { reVector*=-1; } Vector oeVector=adjacentEdgeVectors.at(i); Vector planeVector1=Vector::cross(reVector, oeVector); Vector planeVector2=Vector::angleBisector(reVector, oeVector); Point planeVertex1=targetEndpoint; Point planeVertex2=planeVertex1+planeVector1; Point planeVertex3=planeVertex1+planeVector2; endCapPlanes.push_back(Plane::planeThroughPoints(planeVertex1, planeVertex2, planeVertex3)); } std::vector<Point> endCap(crossSectionLines.size()); for (int i=0;i<endCap.size();i++) { Point endCapPoint(0,0,0); double dist=100000.0; for (int j=0;j<endCapPlanes.size();j++) { Point testPoint=planeLineIntersection(crossSectionLines.at(i),endCapPlanes.at(j)); double testDist=Point::distance(testPoint, targetEdge.getMidpoint()); if (testDist<dist) { endCapPoint=testPoint; dist=testDist; } } endCap.at(i)=endCapPoint; } return endCap; }