openframeworks / openframeworks/openFrameworks

ofPolyline curveTo - The first point is off from vertex

Open
#6,869 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
10.4k
Forks
2.6k
Avg merge
1d 21h
Merged PRs (30d)
9

Description

Hi,

I just noticed that ofPolyline draws the first point slightly off from the position I set.

Screenshot 2022-02-02 at 15 44 11

The first point of the line isn’t in the center of the red circle P2, which is where I set the second vertex of the ofPolyline.
It workds perfectly with the last point, which falls exactly in the middle of the third vertex (P3).

Here’s the code to reproduce that (everything inside draw() just to simplify testing):

void ofApp::draw()
{
  ofBackground(255);
  ofSetLineWidth(1);

  ofPoint p1(300, 100);
  ofPoint p2(450, 100);
  ofPoint p3(600, 100);
  ofPoint p4(750, 100);

  ofPolyline line;
  line.curveTo(p1);
  line.curveTo(p2);
  line.curveTo(p3);
  line.curveTo(p4);

  // Draw line
  ofSetColor(0);
  line.draw();

  // Draw Circles
  ofNoFill();
  ofSetColor(255, 0, 0);
  ofCircle(p1.x, p1.y, 5);
  ofCircle(p2.x, p2.y, 5);
  ofCircle(p3.x, p3.y, 5);
  ofCircle(p4.x, p4.y, 5);
}

I asked about that on OF forum: https://forum.openframeworks.cc/t/ofpolyline-curveto-the-first-point-is-off-from-vertex/39256

And Zach mentioned this:

good question. I took a look and believe this may be a bug in ofPolyline.inl (curveTo)

for (int i = 1; i <= curveResolution; i++){

should be (I think)

for (int i = 0; i <= curveResolution; i++){

can you open an issue on GitHub ? I think the fix is easy but it’s worth looking at a little longer (to see why that for loop starts from 1 and not 0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect ofPolyline.inl, especially curveTo and the loop beginning with for (int i = 1; i <= curveResolution; i++). Reproduce the issue with the four-point example from the report, then verify that the first curve point aligns with the second vertex without changing the correct endpoint behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.