| 175 | } |
| 176 | |
| 177 | SkPath create_triangles(const std::vector<BrushPoint>& regularPoints, const std::vector<BrushPoint>& smoothedPoints, bool hasRoundCaps) { |
| 178 | SkPathBuilder pathBuilder; |
| 179 | const int ARC_SMOOTHNESS = 10; |
| 180 | const int CIRCLE_SMOOTHNESS = 20; |
| 181 | const std::vector<BrushPoint>& pointsN = regularPoints; |
| 182 | std::vector<SkPoint> topPoints; |
| 183 | std::vector<SkPoint> bottomPoints; |
| 184 | |
| 185 | if(pointsN.size() == 1 && hasRoundCaps) { |
| 186 | std::vector<Vector2f> circlePoints = gen_circle_points(pointsN.front().pos, pointsN.front().width / 2.0f, CIRCLE_SMOOTHNESS); |
| 187 | for(size_t i = 0; i < circlePoints.size(); i++) { |
| 188 | topPoints.emplace_back(convert_vec2<SkPoint>(circlePoints[i])); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | if(pointsN.size() < 2) { |
| 193 | if(!topPoints.empty()) { |
| 194 | pathBuilder.addPolygon({topPoints.data(), topPoints.size()}, true); |
| 195 | return pathBuilder.detach(); |
| 196 | } |
| 197 | return SkPath(); |
| 198 | } |
| 199 | |
| 200 | auto& points = smoothedPoints; |
| 201 | |
| 202 | std::vector<size_t> wedgeIndices = get_wedge_indices(points); |
| 203 | for(size_t i = 0; i < wedgeIndices.size() - 1; i++) { |
| 204 | |
| 205 | size_t pointsBegin = wedgeIndices[i]; |
| 206 | size_t pointsEnd = wedgeIndices[i + 1]; |
| 207 | |
| 208 | std::array<Vector2f, 3> vertArray; |
| 209 | size_t newIndex = 0; |
| 210 | |
| 211 | Vector2f perpPrev = perpendicular_vec2((points[pointsBegin + 1].pos - points[pointsBegin].pos).eval()); |
| 212 | perpPrev.normalize(); |
| 213 | |
| 214 | vertArray[0] = points[pointsBegin].pos + perpPrev * points[pointsBegin].width * 0.5f; |
| 215 | topPoints.emplace_back(convert_vec2<SkPoint>(vertArray[0])); |
| 216 | vertArray[1] = points[pointsBegin].pos - perpPrev * points[pointsBegin].width * 0.5f; |
| 217 | bottomPoints.emplace_back(convert_vec2<SkPoint>(vertArray[1])); |
| 218 | newIndex = 2; |
| 219 | |
| 220 | if(hasRoundCaps && pointsBegin == 0) { |
| 221 | Vector2f arcDirStart = (convert_vec2<Vector2f>(vertArray[0]) - points[0].pos).normalized(); |
| 222 | Vector2f arcDirEnd = (convert_vec2<Vector2f>(vertArray[1]) - points[0].pos).normalized(); |
| 223 | Vector2f arcDirCenter = (points[0].pos - points[1].pos).normalized(); |
| 224 | std::vector<Vector2f> arcPoints = arc_vec<float>(points[0].pos, arcDirStart, arcDirEnd, arcDirCenter, points[0].width * 0.5f, ARC_SMOOTHNESS); |
| 225 | arcPoints.emplace(arcPoints.begin(), convert_vec2<Vector2f>(vertArray[0])); |
| 226 | arcPoints.emplace_back(convert_vec2<Vector2f>(vertArray[1])); |
| 227 | for(size_t i = 0; i < arcPoints.size() - 1; i++) { |
| 228 | bottomPoints.emplace_back(convert_vec2<SkPoint>(arcPoints[i])); |
| 229 | } |
| 230 | bottomPoints.emplace_back(convert_vec2<SkPoint>(arcPoints.back())); |
| 231 | } |
| 232 | |
| 233 | for(size_t j = pointsBegin + 1; j < pointsEnd; j++) { |
| 234 | if(j >= pointsEnd) |
no test coverage detected