ladybird/Userland/Libraries/LibWeb/CSS/Ratio.cpp
martinfalisse ce0f41b9fb LibWeb+WebContent: Use new String class in CSS::StyleValue
Converts uses of DeprecatedString to String in StyleValue, and patches
surrounding files that depend on these functions.
2023-01-09 11:09:31 +01:00

31 lines
607 B
C++

/*
* Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "Ratio.h"
#include <math.h>
namespace Web::CSS {
Ratio::Ratio(float first, float second)
: m_first_value(first)
, m_second_value(second)
{
}
// https://www.w3.org/TR/css-values-4/#degenerate-ratio
bool Ratio::is_degenerate() const
{
return !isfinite(m_first_value) || m_first_value == 0
|| !isfinite(m_second_value) || m_second_value == 0;
}
ErrorOr<String> Ratio::to_string() const
{
return String::formatted("{} / {}", m_first_value, m_second_value);
}
}