Browse Source

Use single instance func context

CPKreuz 1 year ago
parent
commit
f8ca6279af

+ 12 - 4
src/PixiEditor.ChangeableDocument/Changeables/Graph/Context/FuncContext.cs

@@ -3,11 +3,13 @@ using PixiEditor.Numerics;
 
 namespace PixiEditor.ChangeableDocument.Changeables.Graph.Context;
 
-public record struct FuncContext(VecD Position, VecI Size, bool HasContext)
+public class FuncContext
 {
-    public FuncContext(VecD position, VecI size) : this(position, size, true) { }
-
-    public static FuncContext NoContext => new(VecD.Zero, VecI.Zero, false);
+    public static FuncContext NoContext { get; } = new();
+    
+    public VecD Position { get; private set; }
+    public VecI Size { get; private set; }
+    public bool HasContext { get; private set; }
 
     public void ThrowOnMissingContext()
     {
@@ -16,4 +18,10 @@ public record struct FuncContext(VecD Position, VecI Size, bool HasContext)
             throw new NoNodeFuncContextException();
         }
     }
+
+    public void UpdateContext(VecD position, VecI size)
+    {
+        Position = position;
+        Size = size;
+    }
 }

+ 3 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/ModifyImageRightNode.cs

@@ -45,12 +45,14 @@ public class ModifyImageRightNode : Node
         var height = size.Y;
 
         var surface = new Surface(size);
+        
+        var context = new FuncContext();
 
         for (int y = 0; y < height; y++)
         {
             for (int x = 0; x < width; x++)
             {
-                var context = new FuncContext(new VecD((double)x / width, (double)y / height), new VecI(width, height));
+                context.UpdateContext(new VecD((double)x / width, (double)y / height), new VecI(width, height));
                 var color = Color.Value(context);
 
                 drawingPaint.Color = color;