RuiwenTang / Skity

A light weight 2D Vector Graphic renderer library writing in c++ for OpenGL3.3+ / OpenGLES3.0+ / Vulkan 1.1+/ WebGL2 with WASM
https://ruiwentang.github.io/Skity/
MIT License
219 stars 28 forks source link

Cubic curves degenerate to lines #42

Closed tuzhong007 closed 1 year ago

tuzhong007 commented 1 year ago

The following code draws a cubic Bezier curve from (0, 100) to (150, 100) whose control points are (50, 50) and (150, 100). In addition, the control points are connected by line strips.

skity::Paint paint;
  paint.setAntiAlias(true);
  paint.setStyle(skity::Paint::kStroke_Style);
  skity::Point cubicPts[] = {
      {0, 100, 0, 1}, {50, 50, 0, 1}, {100, 150, 0, 1}, {150, 100, 0, 1}};
  skity::Color color = 0xff88ff00;
  paint.setColor(0x7fffffff & color);
  paint.setStrokeWidth(1);
  for (unsigned j = 0; j < 3; ++j) {
    //     canvas->drawLine(cubicPts[j], cubicPts[j + 1], paint); //.
    canvas->drawLine(cubicPts[j].x, cubicPts[j].y, 
        cubicPts[j + 1].x,cubicPts[j + 1].y, paint);
  }
    skity::Path path;
    path.moveTo(cubicPts[0]);
    path.cubicTo(cubicPts[1], cubicPts[2], cubicPts[3]);
    paint.setStrokeWidth(3);
    paint.setColor(color);
    canvas->drawPath(path, paint);

But the result of cubic curve is a horizontal line segment: image

RuiwenTang commented 1 year ago

Thanks for reporting this. I checked this code in my local project, and is fixed. image I will push this patch in this weekend.