| 
									
										
										
										
											2022-03-06 13:48:32 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2023-06-06 15:42:43 +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 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-06 19:02:26 +01:00
										 |  |  | #include <AK/String.h>
 | 
					
						
							| 
									
										
										
										
											2022-03-06 13:48:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::CSS { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // https://www.w3.org/TR/css-values-4/#ratios
 | 
					
						
							|  |  |  | class Ratio { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2023-08-20 13:02:41 +01:00
										 |  |  |     Ratio(double first, double second = 1); | 
					
						
							|  |  |  |     double value() const { return m_first_value / m_second_value; } | 
					
						
							| 
									
										
										
										
											2022-03-06 13:48:32 +00:00
										 |  |  |     bool is_degenerate() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-22 12:25:30 +01:00
										 |  |  |     String to_string() const; | 
					
						
							| 
									
										
										
										
											2022-03-06 13:48:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-06 15:42:43 +01:00
										 |  |  |     bool operator==(Ratio const& other) const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         return value() == other.value(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     int operator<=>(Ratio const& other) const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         auto this_value = value(); | 
					
						
							|  |  |  |         auto other_value = other.value(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (this_value < other_value) | 
					
						
							|  |  |  |             return -1; | 
					
						
							|  |  |  |         if (this_value > other_value) | 
					
						
							|  |  |  |             return 1; | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-06 13:48:32 +00:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2023-08-20 13:02:41 +01:00
										 |  |  |     double m_first_value { 0 }; | 
					
						
							|  |  |  |     double m_second_value { 1 }; | 
					
						
							| 
									
										
										
										
											2022-03-06 13:48:32 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |