소스 검색

Fixed losing precision

Krzysztof Krysiński 6 달 전
부모
커밋
f0d26d0c88

+ 2 - 2
src/ChunkyImageLib/Chunk.cs

@@ -74,9 +74,9 @@ public class Chunk : IDisposable
     /// </summary>
     /// <param name="pos">The destination for the <paramref name="surface"/></param>
     /// <param name="paint">The paint to use while drawing</param>
-    public void DrawChunkOn(DrawingSurface surface, VecI pos, Paint? paint = null)
+    public void DrawChunkOn(DrawingSurface surface, VecD pos, Paint? paint = null)
     {
-        surface.Canvas.DrawSurface(Surface.DrawingSurface, pos.X, pos.Y, paint);
+        surface.Canvas.DrawSurface(Surface.DrawingSurface, (float)pos.X, (float)pos.Y, paint);
     }
     
     public unsafe RectI? FindPreciseBounds(RectI? passedSearchRegion = null)

+ 2 - 2
src/ChunkyImageLib/ChunkyImage.cs

@@ -359,7 +359,7 @@ public class ChunkyImage : IReadOnlyChunkyImage, IDisposable, ICloneable, ICache
     /// True if the chunk existed and was drawn, otherwise false
     /// </returns>
     /// <exception cref="ObjectDisposedException">This image is disposed</exception>
-    public bool DrawMostUpToDateChunkOn(VecI chunkPos, ChunkResolution resolution, DrawingSurface surface, VecI pos,
+    public bool DrawMostUpToDateChunkOn(VecI chunkPos, ChunkResolution resolution, DrawingSurface surface, VecD pos,
         Paint? paint = null)
     {
         lock (lockObject)
@@ -452,7 +452,7 @@ public class ChunkyImage : IReadOnlyChunkyImage, IDisposable, ICloneable, ICache
     }
 
     /// <exception cref="ObjectDisposedException">This image is disposed</exception>
-    public bool DrawCommittedChunkOn(VecI chunkPos, ChunkResolution resolution, DrawingSurface surface, VecI pos,
+    public bool DrawCommittedChunkOn(VecI chunkPos, ChunkResolution resolution, DrawingSurface surface, VecD pos,
         Paint? paint = null)
     {
         lock (lockObject)

+ 4 - 4
src/ChunkyImageLib/ChunkyImageEx.cs

@@ -19,7 +19,7 @@ public static class IReadOnlyChunkyImageEx
     /// <param name="pos">Starting position on the surface</param>
     /// <param name="paint">Paint to use for drawing</param>
     public static void DrawMostUpToDateRegionOn
-        (this IReadOnlyChunkyImage image, RectI fullResRegion, ChunkResolution resolution, DrawingSurface surface, VecI pos, Paint? paint = null)
+        (this IReadOnlyChunkyImage image, RectI fullResRegion, ChunkResolution resolution, DrawingSurface surface, VecD pos, Paint? paint = null)
     {
         DrawRegionOn(fullResRegion, resolution, surface, pos, image.DrawMostUpToDateChunkOn, paint);
     }
@@ -44,12 +44,12 @@ public static class IReadOnlyChunkyImageEx
         RectI fullResRegion,
         ChunkResolution resolution,
         DrawingSurface surface,
-        VecI pos,
-        Func<VecI, ChunkResolution, DrawingSurface, VecI, Paint?, bool> drawingFunc,
+        VecD pos,
+        Func<VecI, ChunkResolution, DrawingSurface, VecD, Paint?, bool> drawingFunc,
         Paint? paint = null)
     {
         int count = surface.Canvas.Save();
-        surface.Canvas.ClipRect(RectD.Create(pos, fullResRegion.Size));
+        surface.Canvas.ClipRect(new RectD(pos, fullResRegion.Size));
 
         VecI chunkTopLeft = OperationHelper.GetChunkPos(fullResRegion.TopLeft, ChunkyImage.FullChunkSize);
         VecI chunkBotRight = OperationHelper.GetChunkPos(fullResRegion.BottomRight, ChunkyImage.FullChunkSize);

+ 2 - 2
src/ChunkyImageLib/IReadOnlyChunkyImage.cs

@@ -10,8 +10,8 @@ namespace ChunkyImageLib;
 
 public interface IReadOnlyChunkyImage
 {
-    bool DrawMostUpToDateChunkOn(VecI chunkPos, ChunkResolution resolution, DrawingSurface surface, VecI pos, Paint? paint = null);
-    bool DrawCommittedChunkOn(VecI chunkPos, ChunkResolution resolution, DrawingSurface surface, VecI pos, Paint? paint = null);
+    bool DrawMostUpToDateChunkOn(VecI chunkPos, ChunkResolution resolution, DrawingSurface surface, VecD pos, Paint? paint = null);
+    bool DrawCommittedChunkOn(VecI chunkPos, ChunkResolution resolution, DrawingSurface surface, VecD pos, Paint? paint = null);
     RectI? FindChunkAlignedMostUpToDateBounds();
     RectI? FindChunkAlignedCommittedBounds();
     RectI? FindTightCommittedBounds(ChunkResolution precision = ChunkResolution.Full);

+ 1 - 1
src/ChunkyImageLib/Operations/ChunkyImageOperation.cs

@@ -63,7 +63,7 @@ internal class ChunkyImageOperation : IMirroredDrawOperation
         VecI bottomLeft = OperationHelper.GetChunkPos(
             new VecI(chunkCenterOnImage.X - halfChunk.X, chunkCenterOnImage.Y + halfChunk.Y), ChunkyImage.FullChunkSize);
 
-        Func<VecI, ChunkResolution, DrawingSurface, VecI, Paint?, bool> drawMethod = drawUpToDate ? imageToDraw.DrawMostUpToDateChunkOn : imageToDraw.DrawCommittedChunkOn;
+        Func<VecI, ChunkResolution, DrawingSurface, VecD, Paint?, bool> drawMethod = drawUpToDate ? imageToDraw.DrawMostUpToDateChunkOn : imageToDraw.DrawCommittedChunkOn;
         
         drawMethod(
             topLeft,

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

@@ -100,7 +100,7 @@ public class ImageLayerNode : LayerNode, IReadOnlyImageNode
             GetLayerImageAtFrame(ctx.FrameTime.Frame).DrawMostUpToDateRegionOn(
                 new RectI(0, 0, layerImage.LatestSize.X, layerImage.LatestSize.Y),
                 ChunkResolution.Full,
-                workingSurface, -(VecI)topLeft, paint);
+                workingSurface, -topLeft, paint);
         }
         else
         {

+ 2 - 2
src/PixiEditor/Views/Visuals/SurfaceControl.cs

@@ -215,8 +215,8 @@ internal class DrawSurfaceOperation : SkiaDrawOperation
             float scaleX = (float)Bounds.Width / Surface.Size.X;
             float scaleY = (float)Bounds.Height / Surface.Size.Y;
             var scale = Math.Min(scaleX, scaleY);
-            float dX = (float)Bounds.Width / 2 / scale - Surface.Size.X / 2;
-            float dY = (float)Bounds.Height / 2 / scale - Surface.Size.Y / 2;
+            float dX = (float)Bounds.Width / 2f / scale - Surface.Size.X / 2f;
+            float dY = (float)Bounds.Height / 2f / scale - Surface.Size.Y / 2f;
             canvas.Scale(scale, scale);
             canvas.Translate(dX, dY);
         }