Browse Source

Removed Rotation as separate geometry feature

flabbet 11 months ago
parent
commit
950163ab79

+ 0 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Interfaces/Shapes/IReadOnlyEllipseData.cs

@@ -6,5 +6,4 @@ public interface IReadOnlyEllipseData : IReadOnlyShapeVectorData
 {
 {
     public VecD Center { get; }
     public VecD Center { get; }
     public VecD Radius { get; }
     public VecD Radius { get; }
-    public double RotationRadians { get; }
 }
 }

+ 5 - 9
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/Data/EllipseVectorData.cs

@@ -10,13 +10,11 @@ public class EllipseVectorData : ShapeVectorData, IReadOnlyEllipseData
     public VecD Radius { get; set; }
     public VecD Radius { get; set; }
     public VecD Center { get; set; }
     public VecD Center { get; set; }
     
     
-    public double RotationRadians { get; set; } = 0;
-
     public override RectD GeometryAABB =>
     public override RectD GeometryAABB =>
-        new ShapeCorners(Center, Radius * 2).AsRotated(RotationRadians, Center).AABBBounds;
+        new ShapeCorners(Center, Radius * 2).AABBBounds;
 
 
     public override ShapeCorners TransformationCorners =>
     public override ShapeCorners TransformationCorners =>
-        new ShapeCorners(Center, Radius * 2).AsRotated(RotationRadians, Center).WithMatrix(TransformationMatrix);
+        new ShapeCorners(Center, Radius * 2).WithMatrix(TransformationMatrix);
 
 
 
 
     public EllipseVectorData(VecD center, VecD radius)
     public EllipseVectorData(VecD center, VecD radius)
@@ -31,13 +29,12 @@ public class EllipseVectorData : ShapeVectorData, IReadOnlyEllipseData
         
         
         using ChunkyImage img = new ChunkyImage((VecI)GeometryAABB.Size);
         using ChunkyImage img = new ChunkyImage((VecI)GeometryAABB.Size);
 
 
-        RectD rotated = new ShapeCorners(RectD.FromTwoPoints(VecD.Zero, imageSize))
-            .AsRotated(RotationRadians, imageSize / 2f).AABBBounds;
+        RectD rotated = new ShapeCorners(RectD.FromTwoPoints(VecD.Zero, imageSize)).AABBBounds;
 
 
         VecI shift = new VecI((int)Math.Floor(-rotated.Left), (int)Math.Floor(-rotated.Top));
         VecI shift = new VecI((int)Math.Floor(-rotated.Left), (int)Math.Floor(-rotated.Top));
         RectI drawRect = new(shift, imageSize);
         RectI drawRect = new(shift, imageSize);
         
         
-        img.EnqueueDrawEllipse(drawRect, StrokeColor, FillColor, StrokeWidth, RotationRadians);
+        img.EnqueueDrawEllipse(drawRect, StrokeColor, FillColor, StrokeWidth);
         img.CommitChanges();
         img.CommitChanges();
 
 
         VecI topLeft = new VecI((int)Math.Round(Center.X - Radius.X), (int)Math.Round(Center.Y - Radius.Y)) - shift;
         VecI topLeft = new VecI((int)Math.Round(Center.X - Radius.X), (int)Math.Round(Center.Y - Radius.Y)) - shift;
@@ -59,7 +56,7 @@ public class EllipseVectorData : ShapeVectorData, IReadOnlyEllipseData
 
 
     public override int CalculateHash()
     public override int CalculateHash()
     {
     {
-        return HashCode.Combine(Center, Radius, StrokeColor, FillColor, StrokeWidth, RotationRadians, TransformationMatrix);
+        return HashCode.Combine(Center, Radius, StrokeColor, FillColor, StrokeWidth,  TransformationMatrix);
     }
     }
 
 
     public override int GetCacheHash()
     public override int GetCacheHash()
@@ -74,7 +71,6 @@ public class EllipseVectorData : ShapeVectorData, IReadOnlyEllipseData
             StrokeColor = StrokeColor,
             StrokeColor = StrokeColor,
             FillColor = FillColor,
             FillColor = FillColor,
             StrokeWidth = StrokeWidth,
             StrokeWidth = StrokeWidth,
-            RotationRadians = RotationRadians,
             TransformationMatrix = TransformationMatrix
             TransformationMatrix = TransformationMatrix
         };
         };
     }
     }

+ 29 - 26
src/PixiEditor/Models/DocumentModels/UpdateableChangeExecutors/VectorEllipseToolExecutor.cs

@@ -1,7 +1,9 @@
 using ChunkyImageLib.DataHolders;
 using ChunkyImageLib.DataHolders;
+using ChunkyImageLib.Operations;
 using PixiEditor.ChangeableDocument.Actions;
 using PixiEditor.ChangeableDocument.Actions;
 using PixiEditor.ChangeableDocument.Actions.Generated;
 using PixiEditor.ChangeableDocument.Actions.Generated;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes.Data;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes.Data;
+using PixiEditor.DrawingApi.Core.Numerics;
 using PixiEditor.Models.Handlers.Tools;
 using PixiEditor.Models.Handlers.Tools;
 using PixiEditor.Models.Tools;
 using PixiEditor.Models.Tools;
 using PixiEditor.Numerics;
 using PixiEditor.Numerics;
@@ -13,6 +15,9 @@ internal class VectorEllipseToolExecutor : ShapeToolExecutor<IVectorEllipseToolH
     public override ExecutorType Type => ExecutorType.ToolLinked;
     public override ExecutorType Type => ExecutorType.ToolLinked;
     protected override DocumentTransformMode TransformMode => DocumentTransformMode.Scale_Rotate_Shear_NoPerspective;
     protected override DocumentTransformMode TransformMode => DocumentTransformMode.Scale_Rotate_Shear_NoPerspective;
 
 
+    private VecD firstRadius;
+    private VecD firstCenter;
+
     protected override void DrawShape(VecI curPos, double rotationRad, bool firstDraw)
     protected override void DrawShape(VecI curPos, double rotationRad, bool firstDraw)
     {
     {
         RectI rect;
         RectI rect;
@@ -22,48 +27,46 @@ internal class VectorEllipseToolExecutor : ShapeToolExecutor<IVectorEllipseToolH
             rect = GetSquaredCoordinates(startPos, curPos);
             rect = GetSquaredCoordinates(startPos, curPos);
         else
         else
             rect = RectI.FromTwoPixels(startPos, curPos);
             rect = RectI.FromTwoPixels(startPos, curPos);
-        
-        EllipseVectorData data = new EllipseVectorData(rect.Center, rect.Size / 2f) 
+
+        firstCenter = rect.Center;
+        firstRadius = rect.Size / 2f;
+
+        EllipseVectorData data = new EllipseVectorData(firstCenter, firstRadius)
         {
         {
-            RotationRadians = rotationRad, 
-            StrokeColor = StrokeColor, 
-            FillColor = FillColor, 
-            StrokeWidth = StrokeWidth
+            StrokeColor = StrokeColor, FillColor = FillColor, StrokeWidth = StrokeWidth,
         };
         };
-        
+
         lastRect = rect;
         lastRect = rect;
-        lastRadians = rotationRad;
-        
+
         internals!.ActionAccumulator.AddActions(new SetShapeGeometry_Action(memberGuid, data));
         internals!.ActionAccumulator.AddActions(new SetShapeGeometry_Action(memberGuid, data));
     }
     }
 
 
     protected override IAction SettingsChangedAction()
     protected override IAction SettingsChangedAction()
     {
     {
-        return new SetShapeGeometry_Action(memberGuid, new EllipseVectorData(lastRect.Center, lastRect.Size / 2f) 
-        {
-            RotationRadians = lastRadians, 
-            StrokeColor = StrokeColor, 
-            FillColor = FillColor, 
-            StrokeWidth = StrokeWidth
-        });
+        return new SetShapeGeometry_Action(memberGuid,
+            new EllipseVectorData(firstCenter, firstRadius)
+            {
+                StrokeColor = StrokeColor, FillColor = FillColor, StrokeWidth = StrokeWidth
+            });
     }
     }
 
 
     protected override IAction TransformMovedAction(ShapeData data, ShapeCorners corners)
     protected override IAction TransformMovedAction(ShapeData data, ShapeCorners corners)
     {
     {
         RectI rect = (RectI)RectD.FromCenterAndSize(data.Center, data.Size);
         RectI rect = (RectI)RectD.FromCenterAndSize(data.Center, data.Size);
-        double radians = corners.RectRotation;
-        
-        EllipseVectorData ellipseData = new EllipseVectorData(rect.Center, rect.Size / 2f) 
+        RectD firstRect = RectD.FromCenterAndSize(firstCenter, firstRadius * 2);
+        Matrix3X3 matrix = OperationHelper.CreateMatrixFromPoints(corners, firstRadius * 2);
+        matrix = matrix.Concat(Matrix3X3.CreateTranslation(-(float)firstRect.TopLeft.X, -(float)firstRect.TopLeft.Y));
+
+        EllipseVectorData ellipseData = new EllipseVectorData(firstCenter, firstRadius)
         {
         {
-            RotationRadians = radians, 
-            StrokeColor = StrokeColor, 
-            FillColor = FillColor, 
-            StrokeWidth = StrokeWidth
+            StrokeColor = StrokeColor,
+            FillColor = FillColor,
+            StrokeWidth = StrokeWidth,
+            TransformationMatrix = matrix
         };
         };
-        
+
         lastRect = rect;
         lastRect = rect;
-        lastRadians = radians;
-        
+
         return new SetShapeGeometry_Action(memberGuid, ellipseData);
         return new SetShapeGeometry_Action(memberGuid, ellipseData);
     }
     }
 
 

+ 0 - 2
src/PixiEditor/Models/Serialization/Factories/EllipseSerializationFactory.cs

@@ -13,7 +13,6 @@ public class EllipseSerializationFactory : SerializationFactory<byte[], EllipseV
         ByteBuilder builder = new ByteBuilder();
         ByteBuilder builder = new ByteBuilder();
         builder.AddVecD(original.Center);
         builder.AddVecD(original.Center);
         builder.AddVecD(original.Radius);
         builder.AddVecD(original.Radius);
-        builder.AddDouble(original.RotationRadians);
         builder.AddMatrix3X3(original.TransformationMatrix);
         builder.AddMatrix3X3(original.TransformationMatrix);
         builder.AddColor(original.StrokeColor);
         builder.AddColor(original.StrokeColor);
         builder.AddColor(original.FillColor);
         builder.AddColor(original.FillColor);
@@ -34,7 +33,6 @@ public class EllipseSerializationFactory : SerializationFactory<byte[], EllipseV
         
         
         VecD center = extractor.GetVecD();
         VecD center = extractor.GetVecD();
         VecD radius = extractor.GetVecD();
         VecD radius = extractor.GetVecD();
-        double rotationRadians = extractor.GetDouble();
         Matrix3X3 matrix = extractor.GetMatrix3X3();
         Matrix3X3 matrix = extractor.GetMatrix3X3();
         Color strokeColor = extractor.GetColor();
         Color strokeColor = extractor.GetColor();
         Color fillColor = extractor.GetColor();
         Color fillColor = extractor.GetColor();