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

Caps at beginning of curve #6817

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

Conversation

diyaayay
Copy link
Contributor

@diyaayay diyaayay commented Feb 17, 2024

Resolves #6816
Work in progress.

Changes:

-Handles add cap at the start of the stroke if not connected

Screenshots of the change:

sketch:

function setup() {
  createCanvas(400, 400, WEBGL)
}

function draw() {
  background(255)
  stroke(0)
  strokeWeight(20)
  beginShape()
  vertex(-40, -40)
  bezierVertex(40, -40, -40, 40, 40, 40)
  endShape()
}

Before:
image
After:
image

sketch:

function setup() {
  createCanvas(400, 400, WEBGL);
  background(255)
  noFill()
  stroke(0)
  strokeWeight(20)
  translate(-width/2, -height/2)
  beginShape()
  vertex(20, 20)
  quadraticVertex(
    280, 200,
    100, 380
  )
  endShape()
}

output:
image

PR Checklist

@diyaayay
Copy link
Contributor Author

diyaayay commented Feb 18, 2024

I think there is redundancy in storing values that is why the tests fail. I will look into it as soon as possible.

Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the strategy here is to immediately add a cap at the beginning, but I think that might break some other cases, if at a later segment of the stroke, a line connects from vertex 0 to somewhere else, e.g. in a triangle like this:

0      1
x----x
 \  /
  \/
  x
  2

With edges [[0,1], [1,2], [2,0]], I think we'd immediately mark the first vertex as needing a cap, when by the time we get to the end of the edges, we'll see that it's connected again.

I think the problem with curves may be something a bit simpler: when using the debugger on the sketch in the issue, I noticed this for i==0:
image

I think this means that when we add a curve after an initial vertex, we're outputting two identical vertices at the beginning. Because they're right on top of each other, we can't figure out the direction, so we don't add a cap. Maybe that's because when adding points along a quadratic vertex segment, we start at length 0 along the curve, which is equal to the previous vertex:

let start = 0;

So maybe we just need to start at step instead of 0? (Maybe also for bezierVertex? I haven't checked if it has the same problem as quadratic.)

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.

Beginning of WebGL curves don't have a cap since v1.8
2 participants