ofPolyline curveTo - The first point is off from vertex

Hi,

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

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

Is there any way I can guarantee that the first point of an ofPolyline.curveTo will be at a specific position? As it happens with the last point?

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

1 Like

Hey Zach!

Wow, that was fast! It really fixed the problem:

Thank you super much Zach! Very grateful for the help!

Here’s the issue: https://github.com/openframeworks/openFrameworks/issues/6869