Skip to content

Commit 96335f3

Browse files
ronak69tcl3
authored andcommitted
LibWebView: Do floating-point-error-free zoom calculation using rounding
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... .
1 parent 276ad23 commit 96335f3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Userland/Libraries/LibWebView/ViewImplementation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,15 @@ void ViewImplementation::zoom_in()
107107
{
108108
if (m_zoom_level >= ZOOM_MAX_LEVEL)
109109
return;
110-
m_zoom_level += ZOOM_STEP;
110+
m_zoom_level = round_to<int>((m_zoom_level + ZOOM_STEP) * 100) / 100.0f;
111111
update_zoom();
112112
}
113113

114114
void ViewImplementation::zoom_out()
115115
{
116116
if (m_zoom_level <= ZOOM_MIN_LEVEL)
117117
return;
118-
m_zoom_level -= ZOOM_STEP;
118+
m_zoom_level = round_to<int>((m_zoom_level - ZOOM_STEP) * 100) / 100.0f;
119119
update_zoom();
120120
}
121121

0 commit comments

Comments
 (0)