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

LibGfx: Quadratic Bezier curve #2582

Closed
EXL opened this issue Jun 18, 2020 · 3 comments
Closed

LibGfx: Quadratic Bezier curve #2582

EXL opened this issue Jun 18, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@EXL
Copy link

EXL commented Jun 18, 2020

It seems that path with quadratic_bezier_curve_to() has some distortions compared to Qt 5, especially the fill. Maybe I'm using this method wrong?

@alimpfard @linusg

Screenshot from 2020-06-18 21-51-07

GIF Animation (open the image in full resolution in a new tab):

Untitled2

LibGfx Code:

void draw_rounded_rect(GUI::Painter &painter, const Gfx::Color &color, const Gfx::IntRect &rect, int rad, bool fill) {
	auto path = Gfx::Path();
	const float left = rect.left(), right = rect.right(), top = rect.top(), bottom = rect.bottom();
	path.move_to({ left + rad, top });
	path.line_to({ right - rad, top });
	path.quadratic_bezier_curve_to({ right, top }, { right, top + rad });
	path.line_to({ right, bottom - rad });
	path.quadratic_bezier_curve_to({ right, bottom }, { right - rad, bottom });
	path.line_to({ left + rad, bottom });
	path.quadratic_bezier_curve_to({ left, bottom }, { left, bottom - rad });
	path.line_to({ left, top + rad });
	path.quadratic_bezier_curve_to({ left, top }, { left + rad, top });
	path.close();
	painter.fill_path(path, color, Gfx::Painter::WindingRule::EvenOdd);
}

Qt 5 Code:

void drawRoundedRect(QPainter &painter, const QColor &color, const QRect &rect, int rad, bool fill) {
	int left = rect.left(), right = rect.right(), top = rect.top(), bottom = rect.bottom();
	QPainterPath p;
	p.moveTo(left + rad, top);
	p.lineTo(right - rad, top);
	p.quadTo(right, top, right, top + rad);
	p.lineTo(right, bottom - rad);
	p.quadTo(right, bottom, right - rad, bottom);
	p.lineTo(left + rad, bottom);
	p.quadTo(left, bottom, left, bottom - rad);
	p.lineTo(left, top + rad);
	p.quadTo(left, top, left + rad, top);
	p.closeSubpath();
	painter.fillPath(p, color);
}

Sample Code: QuadBezierSampleCode.zip

@alimpfard
Copy link
Member

The lines could probably be made more similar by tweaking the "can approximate bezier curve" tolerance.
However the fill seems to consistently draw an extra pixel on the outline, perhaps we're drawing a border somehow?
I think @SrimantaBarua made a new path-filling impl (see the TTF PR), perhaps try that one and see if it gets rid of these artifacts?

@EXL
Copy link
Author

EXL commented Jun 20, 2020

However the fill seems to consistently draw an extra pixel on the outline, perhaps we're drawing a border somehow?

Interesting. Can anyone check this out?

I think @SrimantaBarua made a new path-filling impl (see the TTF PR), perhaps try that one and see if it gets rid of these artifacts?

Thanks, I tried with patches from #2512:

$ git fetch origin pull/2512/head:ttf
$ git checkout ttf
$ make install && make image && make run

Result:

  1. LibGFX Original.
  2. LibGFX with @SrimantaBarua patches.
  3. Qt 5 Standard.

It's a little better, but the angles are still a bit different.

@linusg linusg added the enhancement New feature or request label Dec 12, 2020
@MacDue
Copy link
Member

MacDue commented Nov 10, 2023

Now we're in 2023 and LibGfx now looks like this:
image

I'd say this is now fixed :)

@MacDue MacDue closed this as completed Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants