Skip to content

Commit

Permalink
LibGfx: Increase bezier splitting tolerance to 0.5
Browse files Browse the repository at this point in the history
No noticeable difference a bit faster. This is still arbitrary and
should be somehow derived from the curve.
  • Loading branch information
MacDue authored and awesomekling committed Jan 8, 2024
1 parent 65b87ba commit 13a4fb0
Show file tree
Hide file tree
Showing 11 changed files with 8 additions and 5 deletions.
Binary file modified Tests/LibWeb/Ref/reference/images/border-radius-ref.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Tests/LibWeb/Ref/reference/images/canvas-path-rect-ref.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Tests/LibWeb/Ref/reference/images/css-backgrounds-ref.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Tests/LibWeb/Ref/reference/images/inline-node-ref.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Tests/LibWeb/Ref/reference/images/object-fit-position.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Tests/LibWeb/Ref/reference/images/outer-box-shadow-ref.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Tests/LibWeb/Ref/reference/images/svg-textPath-ref.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Tests/LibWeb/Ref/reference/images/text-shadow-ref.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions Userland/Libraries/LibGfx/Painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2086,7 +2086,8 @@ void Painter::draw_triangle_wave(IntPoint a_p1, IntPoint a_p2, Color color, int

static bool can_approximate_bezier_curve(FloatPoint p1, FloatPoint p2, FloatPoint control)
{
constexpr float tolerance = 0.015f;
// TODO: Somehow calculate the required number of splits based on the curve (and its size).
constexpr float tolerance = 0.5f;

auto p1x = 3 * control.x() - 2 * p1.x() - p2.x();
auto p1y = 3 * control.y() - 2 * p1.y() - p2.y();
Expand Down Expand Up @@ -2163,7 +2164,8 @@ void Painter::for_each_line_segment_on_cubic_bezier_curve(FloatPoint control_poi

static bool can_approximate_cubic_bezier_curve(FloatPoint p1, FloatPoint p2, FloatPoint control_0, FloatPoint control_1)
{
constexpr float tolerance = 0.015f;
// TODO: Somehow calculate the required number of splits based on the curve (and its size).
constexpr float tolerance = 0.5f;

auto ax = 3 * control_0.x() - 2 * p1.x() - p2.x();
auto ay = 3 * control_0.y() - 2 * p1.y() - p2.y();
Expand Down
7 changes: 4 additions & 3 deletions Userland/Libraries/LibGfx/Path.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,10 @@ Path Path::stroke_to_fill(float thickness) const
}

// Note: This is the same as the tolerance from bezier curve splitting.
constexpr auto flatness = 0.015f;
auto pen_vertex_count = max(
static_cast<int>(ceilf(AK::Pi<float> / acosf(1 - (2 * flatness) / thickness))), 4);
constexpr auto flatness = 0.5f;
auto pen_vertex_count = (thickness >= 2 * flatness) ? max(
static_cast<int>(ceilf(AK::Pi<float> / acosf(1 - (2 * flatness) / thickness))), 4)
: 4;
if (pen_vertex_count % 2 == 1)
pen_vertex_count += 1;

Expand Down

0 comments on commit 13a4fb0

Please sign in to comment.