Browse Source

Fixed chunk resolution vector placement

flabbet 11 months ago
parent
commit
6acecac6ac

+ 8 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/Data/EllipseVectorData.cs

@@ -1,4 +1,5 @@
 using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces.Shapes;
+using PixiEditor.DrawingApi.Core.Numerics;
 using PixiEditor.DrawingApi.Core.Surfaces;
 using PixiEditor.DrawingApi.Core.Surfaces.PaintImpl;
 using PixiEditor.DrawingApi.Core.Surfaces.Vector;
@@ -49,6 +50,7 @@ public class EllipseVectorData : ShapeVectorData, IReadOnlyEllipseData
         img.CommitChanges();
 
         VecI topLeft = new VecI((int)Math.Round(Center.X - Radius.X), (int)Math.Round(Center.Y - Radius.Y)) - shift;
+        topLeft = (VecI)(topLeft * resolution.Multiplier());
         
         RectI region = new(VecI.Zero, (VecI)GeometryAABB.Size);
 
@@ -56,7 +58,12 @@ public class EllipseVectorData : ShapeVectorData, IReadOnlyEllipseData
         if (applyTransform)
         {
             num = drawingSurface.Canvas.Save();
-            drawingSurface.Canvas.SetMatrix(TransformationMatrix);
+            Matrix3X3 final = TransformationMatrix with
+            {
+                TransX = TransformationMatrix.TransX * (float)resolution.Multiplier(),
+                TransY = TransformationMatrix.TransY * (float)resolution.Multiplier()
+            };
+            drawingSurface.Canvas.SetMatrix(final);
         }
 
         img.DrawMostUpToDateRegionOn(region, resolution, drawingSurface, topLeft, paint);

+ 8 - 2
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/Data/LineVectorData.cs

@@ -1,5 +1,6 @@
 using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces.Shapes;
 using PixiEditor.DrawingApi.Core.ColorsImpl;
+using PixiEditor.DrawingApi.Core.Numerics;
 using PixiEditor.DrawingApi.Core.Surfaces;
 using PixiEditor.DrawingApi.Core.Surfaces.PaintImpl;
 using PixiEditor.Numerics;
@@ -63,7 +64,7 @@ public class LineVectorData(VecD startPos, VecD pos) : ShapeVectorData, IReadOnl
 
         img.CommitChanges();
         
-        VecI topLeft = (VecI)adjustedAABB.TopLeft; 
+        VecI topLeft = (VecI)(adjustedAABB.TopLeft * resolution.Multiplier()); 
         
         RectI region = new(VecI.Zero, imageSize);
         
@@ -72,7 +73,12 @@ public class LineVectorData(VecD startPos, VecD pos) : ShapeVectorData, IReadOnl
         if (applyTransform)
         {
             num = drawingSurface.Canvas.Save();
-            drawingSurface.Canvas.SetMatrix(TransformationMatrix);
+            Matrix3X3 final = TransformationMatrix with
+            {
+                TransX = TransformationMatrix.TransX * (float)resolution.Multiplier(),
+                TransY = TransformationMatrix.TransY * (float)resolution.Multiplier()
+            };
+            drawingSurface.Canvas.SetMatrix(final);
         }
 
         img.DrawMostUpToDateRegionOn(region, resolution, drawingSurface, topLeft, paint);

+ 19 - 13
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/Data/PointsVectorData.cs

@@ -1,4 +1,5 @@
-using PixiEditor.DrawingApi.Core.Surfaces;
+using PixiEditor.DrawingApi.Core.Numerics;
+using PixiEditor.DrawingApi.Core.Surfaces;
 using PixiEditor.DrawingApi.Core.Surfaces.PaintImpl;
 using PixiEditor.Numerics;
 
@@ -7,7 +8,7 @@ namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes.Data;
 public class PointsVectorData : ShapeVectorData
 {
     public List<VecD> Points { get; set; } = new();
-    
+
     public PointsVectorData(IEnumerable<VecD> points)
     {
         Points = new List<VecD>(points);
@@ -15,33 +16,40 @@ public class PointsVectorData : ShapeVectorData
 
     public override RectD GeometryAABB => new RectD(Points.Min(p => p.X), Points.Min(p => p.Y), Points.Max(p => p.X),
         Points.Max(p => p.Y));
+
     public override ShapeCorners TransformationCorners => new ShapeCorners(
         GeometryAABB).WithMatrix(TransformationMatrix);
 
     public override void RasterizeGeometry(DrawingSurface drawingSurface, ChunkResolution resolution, Paint? paint)
     {
-        Rasterize(drawingSurface, paint, false);
+        Rasterize(drawingSurface, paint, resolution, false);
     }
 
     public override void RasterizeTransformed(DrawingSurface drawingSurface, ChunkResolution resolution, Paint paint)
     {
-        Rasterize(drawingSurface, paint, true);
+        Rasterize(drawingSurface, paint, resolution, true);
     }
 
-    private void Rasterize(DrawingSurface drawingSurface, Paint paint, bool applyTransform)
+    private void Rasterize(DrawingSurface drawingSurface, Paint paint, ChunkResolution resolution, bool applyTransform)
     {
         paint.Color = FillColor;
         paint.StrokeWidth = StrokeWidth;
-        
+
         int num = 0;
         if (applyTransform)
         {
             num = drawingSurface.Canvas.Save();
-            drawingSurface.Canvas.SetMatrix(TransformationMatrix);
+            Matrix3X3 final = TransformationMatrix with
+            {
+                TransX = TransformationMatrix.TransX * (float)resolution.Multiplier(),
+                TransY = TransformationMatrix.TransY * (float)resolution.Multiplier()
+            };
+            drawingSurface.Canvas.SetMatrix(final);
         }
-        
-        drawingSurface.Canvas.DrawPoints(PointMode.Points, Points.Select(p => new Point((int)p.X, (int)p.Y)).ToArray(), paint);
-        
+
+        drawingSurface.Canvas.DrawPoints(PointMode.Points, Points.Select(p => new Point((int)p.X, (int)p.Y)).ToArray(),
+            paint);
+
         if (applyTransform)
         {
             drawingSurface.Canvas.RestoreToCount(num);
@@ -67,9 +75,7 @@ public class PointsVectorData : ShapeVectorData
     {
         return new PointsVectorData(Points)
         {
-            StrokeColor = StrokeColor,
-            FillColor = FillColor,
-            StrokeWidth = StrokeWidth
+            StrokeColor = StrokeColor, FillColor = FillColor, StrokeWidth = StrokeWidth
         };
     }
 }

+ 10 - 4
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/Data/RectangleVectorData.cs

@@ -1,4 +1,6 @@
 using PixiEditor.ChangeableDocument.Changeables.Graph.Interfaces.Shapes;
+using PixiEditor.DrawingApi.Core;
+using PixiEditor.DrawingApi.Core.Numerics;
 using PixiEditor.DrawingApi.Core.Surfaces;
 using PixiEditor.DrawingApi.Core.Surfaces.PaintImpl;
 using PixiEditor.DrawingApi.Core.Surfaces.Vector;
@@ -44,16 +46,20 @@ public class RectangleVectorData : ShapeVectorData, IReadOnlyRectangleData
         ShapeData data = new ShapeData(drawRect.Center, drawRect.Size, 0, StrokeWidth, StrokeColor, FillColor);
         img.EnqueueDrawRectangle(data);
         img.CommitChanges();
-
-        VecI topLeft = (VecI)(Center - Size / 2); 
-
+        
+        VecI topLeft = (VecI)((Center - Size / 2) * resolution.Multiplier());
         RectI region = new(VecI.Zero, (VecI)GeometryAABB.Size);
 
         int num = 0;
         if (applyTransform)
         {
             num = drawingSurface.Canvas.Save();
-            drawingSurface.Canvas.SetMatrix(TransformationMatrix);
+            Matrix3X3 final = TransformationMatrix with
+            {
+                TransX = TransformationMatrix.TransX * (float)resolution.Multiplier(),
+                TransY = TransformationMatrix.TransY * (float)resolution.Multiplier()
+            };
+            drawingSurface.Canvas.SetMatrix(final);
         }
 
         img.DrawMostUpToDateRegionOn(region, resolution, drawingSurface, topLeft, paint);