Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hx2A opened this issue Oct 7, 2023 · 0 comments
Open

Comments

@hx2A
Copy link
Contributor

hx2A commented Oct 7, 2023

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.

hx2A added a commit to hx2A/processing4 that referenced this issue Oct 7, 2023
@hx2A hx2A mentioned this issue Oct 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant