| 
									
										
										
										
											2025-04-24 16:39:24 +02:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  | MIT License | 
					
						
							|  |  |  | Copyright (c) 2024 - 2025 René Amthor (tobid7) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Permission is hereby granted, free of charge, to any person obtaining a copy | 
					
						
							|  |  |  | of this software and associated documentation files (the "Software"), to deal | 
					
						
							|  |  |  | in the Software without restriction, including without limitation the rights | 
					
						
							|  |  |  | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | 
					
						
							|  |  |  | copies of the Software, and to permit persons to whom the Software is | 
					
						
							|  |  |  | furnished to do so, subject to the following conditions: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | The above copyright notice and this permission notice shall be included in all | 
					
						
							|  |  |  | copies or substantial portions of the Software. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | 
					
						
							|  |  |  | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | 
					
						
							|  |  |  | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | 
					
						
							|  |  |  | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | 
					
						
							|  |  |  | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | 
					
						
							|  |  |  | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | 
					
						
							|  |  |  | SOFTWARE. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <pd/core/core.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace PD { | 
					
						
							| 
									
										
										
										
											2025-06-22 21:05:09 +02:00
										 |  |  | namespace Li { | 
					
						
							| 
									
										
										
										
											2025-04-24 16:39:24 +02:00
										 |  |  | class Rect { | 
					
						
							|  |  |  |  public: | 
					
						
							| 
									
										
										
										
											2025-06-22 21:05:09 +02:00
										 |  |  |   Rect() : Top(0), Bot(0) {} | 
					
						
							|  |  |  |   ~Rect() = default; | 
					
						
							| 
									
										
										
										
											2025-04-24 16:39:24 +02:00
										 |  |  |   /**
 | 
					
						
							|  |  |  |    * Constructor that initializes the rectangle using top and bottom positions. | 
					
						
							|  |  |  |    * @param t Top left and right corner positions. | 
					
						
							|  |  |  |    * @param b Bottom left and right corner positions. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   Rect(const fvec4& t, const fvec4& b) { | 
					
						
							| 
									
										
										
										
											2025-06-22 21:05:09 +02:00
										 |  |  |     Top = t; | 
					
						
							|  |  |  |     Bot = b; | 
					
						
							| 
									
										
										
										
											2025-04-24 16:39:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Constructor that initializes the rectangle using individual corner | 
					
						
							|  |  |  |    * positions. | 
					
						
							|  |  |  |    * @param tl Top left corner position. | 
					
						
							|  |  |  |    * @param tr Top right corner position. | 
					
						
							|  |  |  |    * @param bl Bottom left corner position. | 
					
						
							|  |  |  |    * @param br Bottom right corner position. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   Rect(const fvec2& tl, const fvec2& tr, const fvec2& bl, const fvec2& br) { | 
					
						
							| 
									
										
										
										
											2025-06-22 21:05:09 +02:00
										 |  |  |     Top = fvec4(tl, tr); | 
					
						
							|  |  |  |     Bot = fvec4(bl, br); | 
					
						
							| 
									
										
										
										
											2025-04-24 16:39:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Constructor that initializes the rectangle using a UV mapping vector. | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * - The old API used vec4 for UV mapping. | 
					
						
							|  |  |  |    * - Spritesheets have rotated images, so this was updated to use Rect for UV. | 
					
						
							|  |  |  |    * | 
					
						
							|  |  |  |    * @param uv Vec4 UV map. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   Rect(const fvec4& uv) { | 
					
						
							| 
									
										
										
										
											2025-06-22 21:05:09 +02:00
										 |  |  |     Top = vec4(uv.x, uv.y, uv.z, uv.y); | 
					
						
							|  |  |  |     Bot = vec4(uv.x, uv.w, uv.z, uv.w); | 
					
						
							| 
									
										
										
										
											2025-04-24 16:39:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Get the top-left corner position. | 
					
						
							|  |  |  |    * @return Top-left position as vec2. | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2025-06-22 21:05:09 +02:00
										 |  |  |   fvec2 TopLeft() const { return fvec2(Top.x, Top.y); } | 
					
						
							| 
									
										
										
										
											2025-04-24 16:39:24 +02:00
										 |  |  |   /**
 | 
					
						
							|  |  |  |    * Get the top-right corner position. | 
					
						
							|  |  |  |    * @return Top-right position as vec2. | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2025-06-22 21:05:09 +02:00
										 |  |  |   fvec2 TopRight() const { return fvec2(Top.z, Top.w); } | 
					
						
							| 
									
										
										
										
											2025-04-24 16:39:24 +02:00
										 |  |  |   /**
 | 
					
						
							|  |  |  |    * Get the bottom-left corner position. | 
					
						
							|  |  |  |    * @return Bottom-left position as vec2. | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2025-06-22 21:05:09 +02:00
										 |  |  |   fvec2 BotLeft() const { return fvec2(Bot.x, Bot.y); } | 
					
						
							| 
									
										
										
										
											2025-04-24 16:39:24 +02:00
										 |  |  |   /**
 | 
					
						
							|  |  |  |    * Get the bottom-right corner position. | 
					
						
							|  |  |  |    * @return Bottom-right position as vec2. | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2025-07-01 21:43:35 +02:00
										 |  |  |   fvec2 BotRight() const { return fvec2(Bot.z, Bot.w); } | 
					
						
							| 
									
										
										
										
											2025-04-24 16:39:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Set the top-left corner position. | 
					
						
							|  |  |  |    * @param v New top-left position. | 
					
						
							|  |  |  |    * @return Reference to the updated Rect. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   Rect& TopLeft(const fvec2& v) { | 
					
						
							| 
									
										
										
										
											2025-06-22 21:05:09 +02:00
										 |  |  |     Top.x = v.x; | 
					
						
							|  |  |  |     Top.y = v.y; | 
					
						
							| 
									
										
										
										
											2025-04-24 16:39:24 +02:00
										 |  |  |     return *this; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Set the top-right corner position. | 
					
						
							|  |  |  |    * @param v New top-right position. | 
					
						
							|  |  |  |    * @return Reference to the updated Rect. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   Rect& TopRight(const fvec2& v) { | 
					
						
							| 
									
										
										
										
											2025-06-22 21:05:09 +02:00
										 |  |  |     Top.z = v.x; | 
					
						
							|  |  |  |     Top.w = v.y; | 
					
						
							| 
									
										
										
										
											2025-04-24 16:39:24 +02:00
										 |  |  |     return *this; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Set the bottom-left corner position. | 
					
						
							|  |  |  |    * @param v New bottom-left position. | 
					
						
							|  |  |  |    * @return Reference to the updated Rect. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   Rect& BotLeft(const fvec2& v) { | 
					
						
							| 
									
										
										
										
											2025-06-22 21:05:09 +02:00
										 |  |  |     Bot.x = v.x; | 
					
						
							|  |  |  |     Bot.y = v.y; | 
					
						
							| 
									
										
										
										
											2025-04-24 16:39:24 +02:00
										 |  |  |     return *this; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Set the bottom-right corner position. | 
					
						
							|  |  |  |    * @param v New bottom-right position. | 
					
						
							|  |  |  |    * @return Reference to the updated Rect. | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   Rect& BotRight(const fvec2& v) { | 
					
						
							| 
									
										
										
										
											2025-06-22 21:05:09 +02:00
										 |  |  |     Bot.z = v.x; | 
					
						
							|  |  |  |     Bot.w = v.y; | 
					
						
							| 
									
										
										
										
											2025-04-24 16:39:24 +02:00
										 |  |  |     return *this; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void SwapVec2XY() { | 
					
						
							| 
									
										
										
										
											2025-06-22 21:05:09 +02:00
										 |  |  |     Top.SwapXY(); | 
					
						
							|  |  |  |     Top.SwapZW(); | 
					
						
							|  |  |  |     Bot.SwapXY(); | 
					
						
							|  |  |  |     Bot.SwapZW(); | 
					
						
							| 
									
										
										
										
											2025-04-24 16:39:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-22 21:05:09 +02:00
										 |  |  |   /** Data Section */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   fvec4 Top; | 
					
						
							|  |  |  |   fvec4 Bot; | 
					
						
							| 
									
										
										
										
											2025-04-24 16:39:24 +02:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2025-06-22 21:05:09 +02:00
										 |  |  | }  // namespace Li
 | 
					
						
							| 
									
										
										
										
											2025-01-29 03:14:29 +01:00
										 |  |  | }  // namespace PD
 |