Parse a polyline or polygon from an SVG file. Syntax defined at http://www.w3.org/TR/SVG/shapes.html#PointsBNF @param close true if shape is closed (polygon), false if not (polyline)
(boolean close)
| 473 | * @param close true if shape is closed (polygon), false if not (polyline) |
| 474 | */ |
| 475 | protected void parsePoly(boolean close) { |
| 476 | family = PATH; |
| 477 | this.close = close; |
| 478 | |
| 479 | String pointsAttr = element.getString("points"); |
| 480 | if (pointsAttr != null) { |
| 481 | Pattern pattern = Pattern.compile("([+-]?[\\d]+(\\.[\\d]+)?([eE][+-][\\d]+)?)(,?\\s*)([+-]?[\\d]+(\\.[\\d]+)?([eE][+-][\\d]+)?)"); |
| 482 | Matcher matcher = pattern.matcher(pointsAttr); |
| 483 | vertexCount = 0; |
| 484 | while (matcher.find()) { |
| 485 | vertexCount++; |
| 486 | } |
| 487 | matcher.reset(); |
| 488 | vertices = new float[vertexCount][2]; |
| 489 | for (int i = 0; i < vertexCount; i++) { |
| 490 | matcher.find(); |
| 491 | vertices[i][X] = Float.parseFloat(matcher.group(1)); |
| 492 | vertices[i][Y] = Float.parseFloat(matcher.group(5)); |
| 493 | } |
| 494 | // String[] pointsBuffer = PApplet.splitTokens(pointsAttr); |
| 495 | // vertexCount = pointsBuffer.length; |
| 496 | // vertices = new float[vertexCount][2]; |
| 497 | // for (int i = 0; i < vertexCount; i++) { |
| 498 | // String pb[] = PApplet.splitTokens(pointsBuffer[i], ", \t\r\n"); |
| 499 | // vertices[i][X] = Float.parseFloat(pb[0]); |
| 500 | // vertices[i][Y] = Float.parseFloat(pb[1]); |
| 501 | // } |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | |
| 506 | protected void parsePath() { |
no test coverage detected