mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 00:35:08 +00:00
LibWeb: Use doubles for CSS dimension types
Avoid unintentionally converting between float and double multiple times by just using double everywhere. Also, remove the unused `int` versions of their constructors.
This commit is contained in:
parent
95f80bc65b
commit
1feacd4b52
16 changed files with 34 additions and 73 deletions
|
@ -8,13 +8,7 @@
|
|||
|
||||
namespace Web::CSS {
|
||||
|
||||
Resolution::Resolution(int value, Type type)
|
||||
: m_type(type)
|
||||
, m_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
Resolution::Resolution(float value, Type type)
|
||||
Resolution::Resolution(double value, Type type)
|
||||
: m_type(type)
|
||||
, m_value(value)
|
||||
{
|
||||
|
@ -25,13 +19,13 @@ ErrorOr<String> Resolution::to_string() const
|
|||
return String::formatted("{}dppx", to_dots_per_pixel());
|
||||
}
|
||||
|
||||
float Resolution::to_dots_per_pixel() const
|
||||
double Resolution::to_dots_per_pixel() const
|
||||
{
|
||||
switch (m_type) {
|
||||
case Type::Dpi:
|
||||
return m_value * 96; // 1in = 2.54cm = 96px
|
||||
case Type::Dpcm:
|
||||
return m_value * (96.0f / 2.54f); // 1cm = 96px/2.54
|
||||
return m_value * (96.0 / 2.54); // 1cm = 96px/2.54
|
||||
case Type::Dppx:
|
||||
return m_value;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue