LibGfx: Nudge points away from the start point in radial gradients

Avoids a division by zero, and an incorrect pixel in some repeating
radial gradient cases.

(Ref tests updated)
This commit is contained in:
MacDue 2023-08-22 22:29:43 +01:00 committed by Andreas Kling
parent df58fa8653
commit a98201f889
4 changed files with 3 additions and 4 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 859 KiB

After

Width:  |  Height:  |  Size: 861 KiB

View file

@ -129,7 +129,6 @@
<rect x="0" y="0" width="400" height="300" fill="url(#reflectTest6)"></rect>
</svg>
<!-- spreadMethod=repeat -->
<!-- spreadMethod=repeat -->
<svg width="400" height="300" version="1.1" xmlns="http://www.w3.org/2000/svg">
<defs>
<!-- Start circle inside end circle -->

View file

@ -523,9 +523,9 @@ static auto create_radial_gradient_between_two_circles(Gfx::FloatPoint start_cen
[=](float x, float y) {
auto loc = [&] {
FloatPoint point { x, y };
auto dist = point.distance_from(start_point);
if (dist == 0)
return 0.0f;
// Add a little to avoid division by zero at the focal point.
if (point == start_point)
point += FloatPoint { 0.001f, 0.001f };
// The "vec" (unit) vector points from the focal point to the current point.
auto dist = point.distance_from(start_point);
auto vec = (point - start_point) / dist;