mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:47:35 +00:00
LibGfx: Implement cubic bezier curves by splitting them to subcurves
This makes them significantly more nicer-looking, and fixes a FIXME :^)
This commit is contained in:
parent
02d949cfb6
commit
433725fef2
6 changed files with 145 additions and 12 deletions
|
@ -132,6 +132,14 @@ void Gfx::AntiAliasingPainter::stroke_path(Path const& path, Color color, float
|
|||
cursor = segment.point();
|
||||
break;
|
||||
}
|
||||
case Segment::Type::CubicBezierCurveTo: {
|
||||
auto& curve = static_cast<CubicBezierCurveSegment const&>(segment);
|
||||
auto& through_0 = curve.through_0();
|
||||
auto& through_1 = curve.through_1();
|
||||
draw_cubic_bezier_curve(through_0, through_1, cursor, segment.point(), color, thickness);
|
||||
cursor = segment.point();
|
||||
break;
|
||||
}
|
||||
case Segment::Type::EllipticalArcTo:
|
||||
auto& arc = static_cast<EllipticalArcSegment const&>(segment);
|
||||
draw_elliptical_arc(cursor, segment.point(), arc.center(), arc.radii(), arc.x_axis_rotation(), arc.theta_1(), arc.theta_delta(), color, thickness);
|
||||
|
@ -154,3 +162,10 @@ void Gfx::AntiAliasingPainter::draw_quadratic_bezier_curve(FloatPoint const& con
|
|||
draw_line(fp1, fp2, color, thickness, style);
|
||||
});
|
||||
}
|
||||
|
||||
void Gfx::AntiAliasingPainter::draw_cubic_bezier_curve(const FloatPoint& control_point_0, const FloatPoint& control_point_1, const FloatPoint& p1, const FloatPoint& p2, Color color, float thickness, Painter::LineStyle style)
|
||||
{
|
||||
Gfx::Painter::for_each_line_segment_on_cubic_bezier_curve(control_point_0, control_point_1, p1, p2, [&](FloatPoint const& fp1, FloatPoint const& fp2) {
|
||||
draw_line(fp1, fp2, color, thickness, style);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue