Skip to content

JAVA2D renderer: PShape.beginContour() bug for shapes with multiple contours #791

Closed
@processing-bot

Description

Created by: hx2A

Description

My PR #776 was an inadequate fix for bug #643 . The fix worked great for shapes with 1 contour but not shapes with 2 or more. I regret the shortcoming in my PR.

I was able to figure out the problem and will make a new PR to fix it correctly.

Expected Behavior

The JAVA2D renderer should draw multiple contours the same as the P2D renderer.

Current Behavior

The contours are messed up because the codeIndex variable needs to be incremented when starting a contour to keep the vertexCodes array aligned with the vertices array.

Steps to Reproduce

Here's a more robust test case with 25 contours:

PShape s;

void setup() {
  size(400, 200);
  fill(255, 0, 0);
  noLoop();
}

void draw() {
  translate(50, 50);
  s = createShape();
  s.beginShape();
  s.fill(255, 0, 0);
  s.vertex(  0, 0);
  s.vertex(100, 0);
  s.vertex(100, 100);
  s.vertex(  0, 100);

  for (int x = 5; x <= 85; x += 20) {
    for (int y = 5; y <= 85; y += 20) {
      s.beginContour();
      s.vertex(x, y);
      s.vertex(x, y + 10);
      s.vertex(x + 10, y + 10);
      s.vertex(x + 10, y);
      s.endContour();
    }
  }

  s.endShape(CLOSE);
  shape(s, 0, 0);

  translate(200, 0);

  beginShape();
  fill(255, 0, 0);
  vertex( 0, 0);
  vertex(100, 0);
  vertex(100, 100);
  vertex(0, 100);

  for (int x = 5; x <= 85; x += 20) {
    for (int y = 5; y <= 85; y += 20) {
      beginContour();
      vertex(x, y);
      vertex(x, y + 10);
      vertex(x + 10, y + 10);
      vertex(x + 10, y);
      endContour();
    }
  }
 
  endShape(CLOSE);
}

image

Your Environment

  • Processing version: dev build from main branch
  • Operating System and OS version: Linux / Fedora
  • Other information:

Possible Causes / Solutions

Will make a PR right now with the fix.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    has attachmentAttachment was not transfered from GitLab

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions