Ratio.h 539 B

12345678910111213141516171819202122232425262728
  1. /*
  2. * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/String.h>
  8. namespace Web::CSS {
  9. // https://www.w3.org/TR/css-values-4/#ratios
  10. class Ratio {
  11. public:
  12. Ratio(float first, float second = 1);
  13. float value() const { return m_first_value / m_second_value; }
  14. bool is_degenerate() const;
  15. String to_string() const;
  16. auto operator<=>(Ratio const& other) const;
  17. private:
  18. float m_first_value { 0 };
  19. float m_second_value { 1 };
  20. };
  21. }