| 267 | } |
| 268 | |
| 269 | bool writeShapeDescription(FILE *output, const Shape &shape) { |
| 270 | if (!shape.validate()) |
| 271 | return false; |
| 272 | bool writeColors = isColored(shape); |
| 273 | switch (shape.getYAxisOrientation()) { |
| 274 | case Y_UPWARD: |
| 275 | fprintf(output, "@y-up\n"); |
| 276 | break; |
| 277 | case Y_DOWNWARD: |
| 278 | fprintf(output, "@y-down\n"); |
| 279 | break; |
| 280 | } |
| 281 | for (std::vector<Contour>::const_iterator contour = shape.contours.begin(); contour != shape.contours.end(); ++contour) { |
| 282 | fprintf(output, "{\n"); |
| 283 | if (!contour->edges.empty()) { |
| 284 | for (std::vector<EdgeHolder>::const_iterator edge = contour->edges.begin(); edge != contour->edges.end(); ++edge) { |
| 285 | char colorCode = '\0'; |
| 286 | if (writeColors) { |
| 287 | switch ((*edge)->color) { |
| 288 | case YELLOW: colorCode = 'y'; break; |
| 289 | case MAGENTA: colorCode = 'm'; break; |
| 290 | case CYAN: colorCode = 'c'; break; |
| 291 | case WHITE: colorCode = 'w'; break; |
| 292 | default:; |
| 293 | } |
| 294 | } |
| 295 | const Point2 *p = (*edge)->controlPoints(); |
| 296 | switch ((*edge)->type()) { |
| 297 | case (int) LinearSegment::EDGE_TYPE: |
| 298 | fprintf(output, "\t"); |
| 299 | writeCoord(output, p[0]); |
| 300 | fprintf(output, ";\n"); |
| 301 | if (colorCode) |
| 302 | fprintf(output, "\t\t%c;\n", colorCode); |
| 303 | break; |
| 304 | case (int) QuadraticSegment::EDGE_TYPE: |
| 305 | fprintf(output, "\t"); |
| 306 | writeCoord(output, p[0]); |
| 307 | fprintf(output, ";\n\t\t"); |
| 308 | if (colorCode) |
| 309 | fprintf(output, "%c", colorCode); |
| 310 | fprintf(output, "("); |
| 311 | writeCoord(output, p[1]); |
| 312 | fprintf(output, ");\n"); |
| 313 | break; |
| 314 | case (int) CubicSegment::EDGE_TYPE: |
| 315 | fprintf(output, "\t"); |
| 316 | writeCoord(output, p[0]); |
| 317 | fprintf(output, ";\n\t\t"); |
| 318 | if (colorCode) |
| 319 | fprintf(output, "%c", colorCode); |
| 320 | fprintf(output, "("); |
| 321 | writeCoord(output, p[1]); |
| 322 | fprintf(output, "; "); |
| 323 | writeCoord(output, p[2]); |
| 324 | fprintf(output, ");\n"); |
| 325 | break; |
| 326 | } |
no test coverage detected