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

LibGfx: Fix off-by-one for antialiased line length

Previously the line did not include the endpoint.
This commit is contained in:
MacDue 2022-11-29 23:53:46 +00:00 committed by Andreas Kling
parent 754b8a643d
commit 8dfe43273c

View file

@ -44,7 +44,8 @@ void AntiAliasingPainter::draw_anti_aliased_line(FloatPoint actual_from, FloatPo
int int_thickness = AK::ceil(thickness); int int_thickness = AK::ceil(thickness);
auto mapped_from = m_transform.map(actual_from); auto mapped_from = m_transform.map(actual_from);
auto mapped_to = m_transform.map(actual_to); auto mapped_to = m_transform.map(actual_to);
auto length = mapped_to.distance_from(mapped_from); auto distance = mapped_to.distance_from(mapped_from);
auto length = distance + 1;
// Axis-aligned lines: // Axis-aligned lines:
if (mapped_from.y() == mapped_to.y()) { if (mapped_from.y() == mapped_to.y()) {
@ -63,10 +64,10 @@ void AntiAliasingPainter::draw_anti_aliased_line(FloatPoint actual_from, FloatPo
if constexpr (path_hacks == FixmeEnableHacksForBetterPathPainting::Yes) { if constexpr (path_hacks == FixmeEnableHacksForBetterPathPainting::Yes) {
// FIXME: SVG stoke_path() hack: // FIXME: SVG stoke_path() hack:
// When painting stokes SVG asks for many thickness * < 1px lines. // When painting stokes SVG asks for many very short lines...
// It actually wants a thickness * thickness dot centered at that point. // These look better just painted as dots/AA rectangles
// (Technically this should be rotated or a circle, but that currently gives worse results) // (Technically this should be rotated or a circle, but that currently gives worse results)
if (length < 1.0f) if (distance < 1.0f)
return fill_rect(Gfx::FloatRect::centered_at(mapped_from, { thickness, thickness }), color); return fill_rect(Gfx::FloatRect::centered_at(mapped_from, { thickness, thickness }), color);
} }