Skip to content

Reduce scaling error when DPIUtil#scaleDown -> DPIUtil#scaleUp is used #305

@akoch-yatta

Description

@akoch-yatta

Description
Using DPIUtil.scaleDown is used and the value is then scaled up with DPIUtil.scaleUp again, the result could be different than the original values. We need to investigate how to improve that

Reproduction
For instance take a value int size = 12 at 125% (in pixels)
In points, we say DPIUtil.scaleDown(12, 125) = 10;
Then back to pixels using DPIUtil.scaleUp(10, 125) = 13

Hence, on scaling down certain values and scaling back up again, for those zooms which are not factor or multiple of 100, we do not get the same value due to the underlying floating point rounding in the scaleUp and scaleDown method, which leads to errorful results.

Since, we strictly use integer, we can prove esily that in number theory,
a function like f(x)=round(a×x) where a= z/100 rational, is invertible on Z iff a is an integer or reciprocal of an integer (meaning the multiplication factor is exact over integers), otherwise rounding errors break invertibility. Hence, the DPIUtil worked fantastically with full scaling in the past as there were no remainders in the scalingFactor calulation.

Expected Behavior

on DPIUtil.scaleUp, we should get 12 back as the result.

Necessary configuration:

--

Additional knowledge

--

Follow-up work

Metadata

Metadata

Assignees

Labels

HiDPIA HiDPI-Related Issue or FeatureSWTIssue for SWT

Type

No type

Projects

Status

✅ Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions