2022-03-06 13:48:32 +00:00
|
|
|
/*
|
2023-08-22 12:25:30 +01:00
|
|
|
* Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org>
|
2022-03-06 13:48:32 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Ratio.h"
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
2023-08-20 13:02:41 +01:00
|
|
|
Ratio::Ratio(double first, double second)
|
2022-03-06 13:48:32 +00:00
|
|
|
: 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;
|
|
|
|
}
|
|
|
|
|
2023-08-22 12:25:30 +01:00
|
|
|
String Ratio::to_string() const
|
2022-03-06 13:48:32 +00:00
|
|
|
{
|
2024-03-03 07:56:20 -07:00
|
|
|
return MUST(String::formatted("{:.5} / {:.5}", m_first_value, m_second_value));
|
2022-03-06 13:48:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|