Selaa lähdekoodia

Fix FindPreciseCommittedBounds returning invalid bounds

Equbuxu 2 vuotta sitten
vanhempi
commit
9221bbba69

+ 11 - 13
src/ChunkyImageLib/ChunkyImage.cs

@@ -137,26 +137,24 @@ public class ChunkyImage : IReadOnlyChunkyImage, IDisposable
             return rect;
             return rect;
         }
         }
     }
     }
-    
-    public RectI? FindPreciseBounds()
+
+    /// <exception cref="ObjectDisposedException">This image is disposed</exception>
+    public RectI? FindPreciseCommittedBounds()
     {
     {
         lock (lockObject)
         lock (lockObject)
         {
         {
             ThrowIfDisposed();
             ThrowIfDisposed();
-            RectI? chunkBounds = FindLatestBounds();
-            if(!chunkBounds.HasValue) return null;
 
 
             RectI? preciseBounds = null;
             RectI? preciseBounds = null;
-
-            foreach (var chunk in committedChunks[ChunkResolution.Full])
+            foreach (var (chunkPos, chunk) in committedChunks[ChunkResolution.Full])
             {
             {
-                if(!chunkBounds.Value.Intersects(new RectI(chunk.Key, new VecI(FullChunkSize)))) continue;
-                
-                RectI? chunkPreciseBounds = chunk.Value.FindPreciseBounds();
-                if(!chunkPreciseBounds.HasValue) continue;
-                
-                preciseBounds ??= chunkPreciseBounds.Value;
-                preciseBounds = preciseBounds.Value.Union(chunkPreciseBounds.Value);
+                RectI? chunkPreciseBounds = chunk.FindPreciseBounds();
+                if(chunkPreciseBounds is null) 
+                    continue;
+                RectI globalChunkBounds = chunkPreciseBounds.Value.Offset(chunkPos * FullChunkSize);
+
+                preciseBounds ??= globalChunkBounds;
+                preciseBounds = preciseBounds.Value.Union(globalChunkBounds);
             }
             }
 
 
             return preciseBounds;
             return preciseBounds;

+ 1 - 0
src/Custom.ruleset

@@ -58,6 +58,7 @@
     <Rule Id="SA1310" Action="None" />
     <Rule Id="SA1310" Action="None" />
     <Rule Id="SA1311" Action="None" />
     <Rule Id="SA1311" Action="None" />
     <Rule Id="SA1313" Action="None" />
     <Rule Id="SA1313" Action="None" />
+    <Rule Id="SA1316" Action="None" />
     <Rule Id="SA1400" Action="None" />
     <Rule Id="SA1400" Action="None" />
     <Rule Id="SA1401" Action="None" />
     <Rule Id="SA1401" Action="None" />
     <Rule Id="SA1402" Action="None" />
     <Rule Id="SA1402" Action="None" />

+ 1 - 1
src/PixiEditor.ChangeableDocument/Changes/Root/CenterContent_Change.cs

@@ -41,7 +41,7 @@ internal class CenterContent_Change : Change
         foreach (var layerGuid in _affectedLayers)
         foreach (var layerGuid in _affectedLayers)
         {
         {
             Layer layer = document.FindMemberOrThrow<Layer>(layerGuid);
             Layer layer = document.FindMemberOrThrow<Layer>(layerGuid);
-            RectI? tightBounds = layer.LayerImage.FindPreciseBounds();
+            RectI? tightBounds = layer.LayerImage.FindPreciseCommittedBounds();
             if (tightBounds.HasValue)
             if (tightBounds.HasValue)
             {
             {
                 currentBounds = currentBounds.HasValue ? currentBounds.Value.Union(tightBounds.Value) : tightBounds;
                 currentBounds = currentBounds.HasValue ? currentBounds.Value.Union(tightBounds.Value) : tightBounds;

+ 1 - 1
src/PixiEditor.ChangeableDocument/Changes/Root/ClipCanvas_Change.cs

@@ -15,7 +15,7 @@ internal class ClipCanvas_Change : ResizeBasedChangeBase
         {
         {
             if (member is Layer layer)
             if (member is Layer layer)
             {
             {
-                var layerBounds = layer.LayerImage.FindPreciseBounds();
+                var layerBounds = layer.LayerImage.FindPreciseCommittedBounds();
                 if (layerBounds.HasValue)
                 if (layerBounds.HasValue)
                 {
                 {
                     bounds ??= layerBounds.Value;
                     bounds ??= layerBounds.Value;