/src/serenity/Userland/Libraries/LibWeb/CSS/Ratio.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2022-2023, Sam Atkins <atkinssj@serenityos.org> |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #pragma once |
8 | | |
9 | | #include <AK/String.h> |
10 | | |
11 | | namespace Web::CSS { |
12 | | |
13 | | // https://www.w3.org/TR/css-values-4/#ratios |
14 | | class Ratio { |
15 | | public: |
16 | | Ratio(double first, double second = 1); |
17 | 0 | double numerator() const { return m_first_value; } |
18 | 0 | double denominator() const { return m_second_value; } |
19 | 0 | double value() const { return m_first_value / m_second_value; } |
20 | | bool is_degenerate() const; |
21 | | |
22 | | String to_string() const; |
23 | | |
24 | | bool operator==(Ratio const& other) const |
25 | 0 | { |
26 | 0 | return value() == other.value(); |
27 | 0 | } |
28 | | |
29 | | int operator<=>(Ratio const& other) const |
30 | 0 | { |
31 | 0 | auto this_value = value(); |
32 | 0 | auto other_value = other.value(); |
33 | 0 |
|
34 | 0 | if (this_value < other_value) |
35 | 0 | return -1; |
36 | 0 | if (this_value > other_value) |
37 | 0 | return 1; |
38 | 0 | return 0; |
39 | 0 | } |
40 | | |
41 | | private: |
42 | | double m_first_value { 0 }; |
43 | | double m_second_value { 1 }; |
44 | | }; |
45 | | |
46 | | } |