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 #791 #792

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

fix #791 #792

wants to merge 1 commit into from

Conversation

hx2A
Copy link
Contributor

@hx2A hx2A commented Oct 7, 2023

Fix for #791.

Regrettably, when I tested the fix for #643 I didn't test shapes with multiple contours. This fix will increment the codeIndex variable so that the vertex codes from the vertexCodes array stay in line with the vertices in the vertices array.

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

I should have thought to test with multiple contours when I made the previous PR #776 .

Here's a much more complex example using real-life data from OpenStreetMap:

image

There's a ton of contours in this shape it is drawn correctly.

@hx2A
Copy link
Contributor Author

hx2A commented Oct 7, 2023

I tested this on FX2D and it works there as well.

I reviewed the code I've been running over the past week and I see I did use shapes with multiple contours but I must have been using P2D each time, until today. Anyhow, I'm glad I found the shortcoming in my PR before someone else did.

Here's a real-world example with OpenStreetMap data employing the fix, adding a new drawing mode to the prettymaps library:

image

Thank you for all of your hard work over the years on Processing! I use it every day.

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.

1 participant