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

Added caching to point list

CPKreuz 1 жил өмнө
parent
commit
718a52cc7d

+ 7 - 3
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Points/DistributePointsNode.cs

@@ -46,9 +46,13 @@ public class DistributePointsNode : Node
 
     private PointList GetPointsRandomly()
     {
-        var random = new Random(Seed.Value);
+        var seed = Seed.Value;
+        var random = new Random(seed);
         var pointCount = MaxPointCount.Value;
-        var finalPoints = new PointList(pointCount);
+        var finalPoints = new PointList(pointCount)
+        {
+            HashValue = HashCode.Combine(Probability.Value, pointCount, seed)
+        };
 
         for (int i = 0; i < pointCount; i++)
         {
@@ -74,7 +78,7 @@ public class DistributePointsNode : Node
         Array.Fill(rowSumCache, -1);
         
         var pointCount = MaxPointCount.Value;
-        var finalPoints = new PointList(pointCount);
+        var finalPoints = new PointList(pointCount) { HashValue = 0 };
         
         for (int i = 0; i < pointCount; i++)
         {

+ 8 - 3
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Points/PointList.cs

@@ -1,9 +1,12 @@
-using PixiEditor.Numerics;
+using PixiEditor.Common;
+using PixiEditor.Numerics;
 
 namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Points;
 
-public class PointList : List<VecD>
+public class PointList : List<VecD>, ICacheable
 {
+    public required int HashValue { get; set; }
+
     public PointList()
     {
     }
@@ -16,5 +19,7 @@ public class PointList : List<VecD>
     {
     }
 
-    public static PointList Empty { get; } = new(0);
+    public static PointList Empty { get; } = new(0) { HashValue = 0 };
+
+    public int GetCacheHash() => HashValue;
 }

+ 2 - 2
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Points/RemoveClosePointsNode.cs

@@ -35,8 +35,8 @@ public class RemoveClosePointsNode : Node
             return null;
         }
 
-        var availablePoints = new PointList(Input.Value).Distinct().ToList();
-        var newPoints = new PointList(availablePoints.Count);
+        var availablePoints = Input.Value.Distinct().ToList();
+        var newPoints = new PointList(availablePoints.Count) { HashValue = HashCode.Combine(Input.Value.HashValue, MinDistance.Value, Seed.Value) };
 
         var minDistance = MinDistance.Value;
         var documentSize = context.DocumentSize;