Skip to content

Commit

Permalink
LibWebView: Do floating-point-error-free zoom calculation using rounding
Browse files Browse the repository at this point in the history
The current min/max zoom levels are supposed to be: 30% and 500%.
Before, due to floating point error accumulation in incremental addition
of zoom-step into zoom-level, one extra zoom step would get allowed,
enabling user to zoom 20%-to-510%.

Now, using rounding, the intermediate zoom-level values should be as
close to the theoretical value as FP32 can represent. E.g. zoom-level of
70% (theoretical multiplier 0.7) is 0.69... .
  • Loading branch information
ronak69 authored and tcl3 committed Sep 20, 2024
1 parent 276ad23 commit 96335f3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Userland/Libraries/LibWebView/ViewImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ void ViewImplementation::zoom_in()
{
if (m_zoom_level >= ZOOM_MAX_LEVEL)
return;
m_zoom_level += ZOOM_STEP;
m_zoom_level = round_to<int>((m_zoom_level + ZOOM_STEP) * 100) / 100.0f;
update_zoom();
}

void ViewImplementation::zoom_out()
{
if (m_zoom_level <= ZOOM_MIN_LEVEL)
return;
m_zoom_level -= ZOOM_STEP;
m_zoom_level = round_to<int>((m_zoom_level - ZOOM_STEP) * 100) / 100.0f;
update_zoom();
}

Expand Down

0 comments on commit 96335f3

Please sign in to comment.