Bug with shape or intended?

edited December 2014 in General Discussion

The following makes me wonder why the family kind is geometry instead of path. Should I consider it a bug and fill in a bug report?

void setup() {

  size(400, 400, P2D);

PShape sBezierVertexPath = createShape();
        sBezierVertexPath.setName("sBezierVertexPath");
        sBezierVertexPath.beginShape();
        sBezierVertexPath.noFill();
        sBezierVertexPath.vertex(30, 20);
        sBezierVertexPath.bezierVertex(80, 0, 380, 375, 330, 375);
        sBezierVertexPath.endShape();

        if (sBezierVertexPath.getFamily() == PShape.GEOMETRY) {
          println("why is it GEOMETRY instead of a PATH"); 
        }
}

Answers

  • edited December 2014

    Note sure. Some links:

    1. https://github.com/processing/processing/blob/master/core/src/processing/opengl/PGraphics2D.java#L284-L293
    2. https://github.com/processing/processing/blob/master/core/src/processing/core/PShape.java#L84-L94
    3. https://www.processing.org/reference/createShape_.html

    Ad 1. Without a parameter, the default family type of a createShape() call in the P2D renderer is GEOMETRY. If you want to set it to something else, you can supply a parameter. Such as: createShape(PShape.PATH);

    Ad 2. Inconclusive. bezierVertex indeed mentioned with PATH. But perhaps when you use beginShape(), it's always GEOMETRY? Maybe PATH is reserved for SVG?

    Ad 3. Documentation provides some info, but is perhaps not completely up to date with the latest, incremental development of the code.

  • Try this:

    void setup() {
    
      size(400, 400, P2D);
    
      PShape sBezierVertexPath = createShape(PShape.PATH);
      //PShape sBezierVertexPath = createShape();
    
      sBezierVertexPath.setName("sBezierVertexPath");
      sBezierVertexPath.beginShape();
      sBezierVertexPath.noFill();
      sBezierVertexPath.stroke(0);
      sBezierVertexPath.vertex(30, 20);
      sBezierVertexPath.bezierVertex(80, 0, 380, 375, 330, 375);
      sBezierVertexPath.endShape();
    
      shape(sBezierVertexPath);
    
      int family = sBezierVertexPath.getFamily();
    
      println(family == PShape.GEOMETRY);
    
    }
    

    Now PShape.PATH is set. It won't draw anything! So that has to be a bug. I think I go debug some processing tomorrow. createShape(ARC, ... is also screwed up. If you end it with the options for PIE, CHORD or OPEN then they are used for that, but they are used for ellipseMode at the same time...

    And it's missing some things. The vertices are stored in PShape as a float[][]. You can get about anything except the vertices as an array. To get the vertices for example you have to make something like this:

    public float[][] getVertices(PShape s) {

        if (s.getVertexCount() == 0) return null;
    
        boolean is3D = s.is3D();
    
        float[][] result = new float[s.getVertexCount()][is3D ? 3 : 2];
    
        PVector dest = new PVector();
    
        for (int i = 0; i < s.getVertexCount(); i++) {
            s.getVertex(i, dest);
            result[i][0] = dest.x;
            result[i][1] = dest.y;
            if (is3D) result[i][2] = dest.z;
        }
    
        return result;
    
    }
    
  • There has been a lot of development on these, so doing some debugging is probably a good idea. With regard to the PShape.PATH, and it not displaying, I am still unsure. If it displays as is, with the family type GEOMETRY, then perhaps this is the intended way for beginShape-endShape PShapes and all their types of vertices (see ad 2 above). If it works, why do you need it to be of family type PATH? $0.02

  • I work on a library to have a lot of additional methods for the PShape. Some of the bugs I come across forces me to either make work arounds, ignore them, or fix them. And for the future of processing I think it's best to fix them.

    I'm investigating at the moment what is causing it.

  • hmm, createShape should not be used with PShape.PATH or PShape.GEOMETRY. In other words, the user can not create a shape of type path, only geometry. (Unless avoiding the createShape method).

    I think processing has never ever drawn a shape of type Path yet :)

Sign In or Register to comment.