From 60a3c207323ea6a43816fe249e5c43a59625d28f Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sun, 16 Jan 2022 14:20:32 +0100 Subject: [PATCH] Fixed small texture not beeing rendered at big rectangles --- RGB.NET.Core/Rendering/Textures/PixelTexture.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/RGB.NET.Core/Rendering/Textures/PixelTexture.cs b/RGB.NET.Core/Rendering/Textures/PixelTexture.cs index 5c25b6a..3672e2c 100644 --- a/RGB.NET.Core/Rendering/Textures/PixelTexture.cs +++ b/RGB.NET.Core/Rendering/Textures/PixelTexture.cs @@ -43,8 +43,8 @@ public abstract class PixelTexture : ITexture { if (Data.Length == 0) return Color.Transparent; - int x = (int)MathF.Round(Size.Width * point.X.Clamp(0, 1)); - int y = (int)MathF.Round(Size.Height * point.Y.Clamp(0, 1)); + int x = (int)MathF.Round((Size.Width - 1) * point.X.Clamp(0, 1)); + int y = (int)MathF.Round((Size.Height - 1) * point.Y.Clamp(0, 1)); return GetColor(GetPixelData(x, y)); } } @@ -56,11 +56,14 @@ public abstract class PixelTexture : ITexture { if (Data.Length == 0) return Color.Transparent; - int x = (int)MathF.Round(Size.Width * rectangle.Location.X.Clamp(0, 1)); - int y = (int)MathF.Round(Size.Height * rectangle.Location.Y.Clamp(0, 1)); + int x = (int)MathF.Round((Size.Width - 1) * rectangle.Location.X.Clamp(0, 1)); + int y = (int)MathF.Round((Size.Height - 1) * rectangle.Location.Y.Clamp(0, 1)); int width = (int)MathF.Round(Size.Width * rectangle.Size.Width.Clamp(0, 1)); int height = (int)MathF.Round(Size.Height * rectangle.Size.Height.Clamp(0, 1)); + if ((width == 0) && (rectangle.Size.Width > 0)) width = 1; + if ((height == 0) && (rectangle.Size.Height > 0)) height = 1; + return this[x, y, width, height]; } }