summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/CSS/Ratio.cpp
blob: f6285dfa45722bc4dbcbb061bdc9ed3b603f5af3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
 * 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;
}

String Ratio::to_string() const
{
    return String::formatted("{} / {}", m_first_value, m_second_value);
}

auto Ratio::operator<=>(const Ratio& other) const
{
    return value() - other.value();
}

}