1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:07:45 +00:00

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

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 859 KiB

After

Width:  |  Height:  |  Size: 861 KiB

Before After
Before After

View file

@ -129,7 +129,6 @@
<rect x="0" y="0" width="400" height="300" fill="url(#reflectTest6)"></rect> <rect x="0" y="0" width="400" height="300" fill="url(#reflectTest6)"></rect>
</svg> </svg>
<!-- spreadMethod=repeat --> <!-- spreadMethod=repeat -->
<!-- spreadMethod=repeat -->
<svg width="400" height="300" version="1.1" xmlns="http://www.w3.org/2000/svg"> <svg width="400" height="300" version="1.1" xmlns="http://www.w3.org/2000/svg">
<defs> <defs>
<!-- Start circle inside end circle --> <!-- 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) { [=](float x, float y) {
auto loc = [&] { auto loc = [&] {
FloatPoint point { x, y }; FloatPoint point { x, y };
auto dist = point.distance_from(start_point); // Add a little to avoid division by zero at the focal point.
if (dist == 0) if (point == start_point)
return 0.0f; point += FloatPoint { 0.001f, 0.001f };
// The "vec" (unit) vector points from the focal point to the current point. // The "vec" (unit) vector points from the focal point to the current point.
auto dist = point.distance_from(start_point); auto dist = point.distance_from(start_point);
auto vec = (point - start_point) / dist; auto vec = (point - start_point) / dist;