Browse Source

Magic Wand fully works

flabbet 2 years ago
parent
commit
69eab65ac3

+ 9 - 6
src/PixiEditor.ChangeableDocument/Changes/Drawing/FloodFill/FloodFillHelper.cs

@@ -273,6 +273,7 @@ internal static class FloodFillHelper
                 chunkSize,
                 chunkPos * chunkSize,
                 realSize,
+                document.Size,
                 posOnChunk,
                 colorRange, lines);
 
@@ -389,6 +390,7 @@ internal static class FloodFillHelper
         int chunkSize,
         VecI chunkOffset,
         VecI maxSize,
+        VecI documentSize,
         VecI pos,
         ColorBounds bounds, List<Line> lines)
     {
@@ -411,7 +413,7 @@ internal static class FloodFillHelper
             Half* refPixel = refArray + pixelOffset * 4;
             pixelStates[pixelOffset] = Visited;
 
-            AddCornerLines(chunkSize, chunkOffset, lines, curPos, clampedPos);
+            AddCornerLines(documentSize, chunkOffset, lines, curPos, clampedPos);
             AddFillContourLines(chunkSize, chunkOffset, bounds, lines, curPos, pixelStates, pixelOffset, refPixel, toVisit, clampedPos);
         }
         
@@ -486,9 +488,10 @@ internal static class FloodFillHelper
         }
     }
 
-    private static void AddCornerLines(int chunkSize, VecI chunkOffset, List<Line> lines, VecI curPos, VecI clampedPos)
+    private static void AddCornerLines(VecI documentSize, VecI chunkOffset, List<Line> lines, VecI curPos, VecI clampedPos)
     {
-        if (curPos.X == 0)
+        VecI globalPos = curPos + chunkOffset;
+        if (globalPos.X == 0)
         {
             AddLine(
                 new Line(
@@ -496,7 +499,7 @@ internal static class FloodFillHelper
                     new VecI(clampedPos.X, clampedPos.Y) + chunkOffset), lines);
         }
 
-        if (curPos.X == chunkSize - 1)
+        if (globalPos.X == documentSize.X - 1)
         {
             AddLine(
                 new Line(
@@ -504,7 +507,7 @@ internal static class FloodFillHelper
                     new VecI(clampedPos.X + 1, clampedPos.Y + 1) + chunkOffset), lines);
         }
 
-        if (curPos.Y == 0)
+        if (globalPos.Y == 0)
         {
             AddLine(
                 new Line(
@@ -512,7 +515,7 @@ internal static class FloodFillHelper
                     new VecI(clampedPos.X + 1, clampedPos.Y) + chunkOffset), lines);
         }
 
-        if (curPos.Y == chunkSize - 1)
+        if (globalPos.Y == documentSize.Y - 1)
         {
             AddLine(
                 new Line(

+ 10 - 2
src/PixiEditor.ChangeableDocument/Changes/Selection/MagicWand_UpdateableChange.cs

@@ -15,7 +15,7 @@ internal class MagicWand_UpdateableChange : Change
     private readonly bool referenceAll;
     private readonly bool drawOnMask;
     private readonly SelectionMode mode;
-    
+
     [GenerateMakeChangeAction]
     public MagicWand_UpdateableChange(Guid memberGuid, VecI point, SelectionMode mode, bool referenceAll, bool drawOnMask)
     {
@@ -50,7 +50,9 @@ internal class MagicWand_UpdateableChange : Change
 
     public override OneOf<None, IChangeInfo, List<IChangeInfo>> Revert(Document target)
     {
-        return new None();
+        (var toDispose, target.Selection.SelectionPath) = (target.Selection.SelectionPath, new VectorPath(originalPath!));
+        toDispose.Dispose();
+        return new Selection_ChangeInfo(new VectorPath(target.Selection.SelectionPath));
     }
     
     private Selection_ChangeInfo CommonApply(Document target)
@@ -70,4 +72,10 @@ internal class MagicWand_UpdateableChange : Change
 
         return new Selection_ChangeInfo(new VectorPath(target.Selection.SelectionPath));
     }
+
+    public override void Dispose()
+    {
+        path.Dispose();
+        originalPath?.Dispose();
+    }
 }

+ 5 - 0
src/PixiEditor.DrawingApi.Core/Numerics/VecI.cs

@@ -152,4 +152,9 @@ public struct VecI : IEquatable<VecI>
     {
         return other.X == X && other.Y == Y;
     }
+
+    public VecD Normalized()
+    {
+        return this / Length;
+    }
 }