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

Fix JAVA2D problem in shapes with multiple contours #871

Merged
merged 1 commit into from
Dec 9, 2024

Conversation

hx2A
Copy link
Collaborator

@hx2A hx2A commented Dec 9, 2024

This is a fix for issue #791 that I opened after I discovered my fix for #643 was inadequate.

Explanation

The JAVA2D renderer should be able to draw contours just like the P2D renderer.

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.

You can test the fix with this code:

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);
}

@Stefterv
Copy link
Collaborator

Stefterv commented Dec 9, 2024

Screenshot 2024-12-09 at 17 59 56 Works on macOS

@SableRaf SableRaf merged commit 162554f into processing:main Dec 9, 2024
6 checks passed
@SableRaf
Copy link
Collaborator

SableRaf commented Dec 9, 2024

Thanks @hx2A 😀 and thanks @Stefterv too ✨

@hx2A
Copy link
Collaborator Author

hx2A commented Dec 9, 2024

Thank you, @SableRaf & @Stefterv !

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

Successfully merging this pull request may close these issues.

3 participants