2
0
Эх сурвалжийг харах

Fixed ellipse not taking position into account for rasterization

CPKreuz 1 жил өмнө
parent
commit
a7e0b916ff

+ 8 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/Data/EllipseData.cs

@@ -16,7 +16,14 @@ public class EllipseData : ShapeData
     
     public override void Rasterize(DrawingSurface drawingSurface)
     {
-        using ChunkyImage img = new ChunkyImage(new VecI((int)Radius.X * 2, (int)Radius.Y * 2));
+        var imageSize = new VecI((int)Radius.X * 2, (int)Radius.Y * 2) + (VecI)Center;
+
+        if (imageSize.HasNegativeComponent())
+        {
+            return;
+        }
+        
+        using ChunkyImage img = new ChunkyImage(imageSize);
         RectI rect = new RectI((int)Center.X - (int)Radius.X, (int)Center.Y - (int)Radius.Y, (int)Radius.X * 2, (int)Radius.Y * 2);
         
         img.EnqueueDrawEllipse(rect, StrokeColor, FillColor, StrokeWidth);

+ 2 - 0
src/PixiEditor.Numerics/VecI.cs

@@ -86,6 +86,8 @@ public struct VecI : IEquatable<VecI>, IComparable<VecI>
         return new VecI(Math.Clamp(X, rect.Left, rect.Right), Math.Clamp(Y, rect.Top, rect.Bottom));
     }
 
+    public bool HasNegativeComponent() => X < 0 || Y < 0;
+
     public byte[] ToByteArray()
     {
         var data = new byte[sizeof(int) * 2];