Переглянути джерело

Fixed cloning vector data

flabbet 8 місяців тому
батько
коміт
55f1e697d1

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

@@ -88,15 +88,9 @@ public class EllipseVectorData : ShapeVectorData, IReadOnlyEllipseData
         return CalculateHash();
     }
 
-    public override object Clone()
+    protected override void AdjustCopy(ShapeVectorData copy)
     {
-        return new EllipseVectorData(Center, Radius)
-        {
-            StrokeColor = StrokeColor,
-            FillColor = FillColor,
-            StrokeWidth = StrokeWidth,
-            TransformationMatrix = TransformationMatrix
-        };
+       
     }
 
     public override VectorPath ToPath()

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

@@ -101,14 +101,6 @@ public class LineVectorData(VecD startPos, VecD pos) : ShapeVectorData, IReadOnl
         return GetCacheHash();
     }
 
-    public override object Clone()
-    {
-        return new LineVectorData(Start, End)
-        {
-            StrokeColor = StrokeColor, StrokeWidth = StrokeWidth, TransformationMatrix = TransformationMatrix
-        };
-    }
-
     public override VectorPath ToPath()
     {
         // TODO: Apply transformation matrix

+ 5 - 8
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/Data/PathVectorData.cs

@@ -10,7 +10,7 @@ namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes.Data;
 
 public class PathVectorData : ShapeVectorData, IReadOnlyPathData
 {
-    public VectorPath Path { get; }
+    public VectorPath Path { get; private set; }
     public override RectD GeometryAABB => Path.TightBounds;
     public override RectD VisualAABB => GeometryAABB.Inflate(StrokeWidth / 2);
 
@@ -88,15 +88,12 @@ public class PathVectorData : ShapeVectorData, IReadOnlyPathData
         return Path.GetHashCode();
     }
 
-    public override object Clone()
+    protected override void AdjustCopy(ShapeVectorData copy)
     {
-        return new PathVectorData(new VectorPath(Path))
+        if (copy is PathVectorData pathData)
         {
-            StrokeColor = StrokeColor,
-            FillColor = FillColor,
-            StrokeWidth = StrokeWidth,
-            TransformationMatrix = TransformationMatrix
-        };
+            pathData.Path = new VectorPath(Path);
+        }
     }
 
     public override VectorPath ToPath()

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

@@ -71,12 +71,12 @@ public class PointsVectorData : ShapeVectorData
         return Points.GetHashCode();
     }
 
-    public override object Clone()
+    protected override void AdjustCopy(ShapeVectorData copy)
     {
-        return new PointsVectorData(Points)
+        if (copy is PointsVectorData pointsVectorData)
         {
-            StrokeColor = StrokeColor, FillColor = FillColor, StrokeWidth = StrokeWidth
-        };
+            pointsVectorData.Points = new List<VecD>(Points);
+        }
     }
 
     public override VectorPath ToPath()

+ 0 - 11
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/Data/RectangleVectorData.cs

@@ -100,17 +100,6 @@ public class RectangleVectorData : ShapeVectorData, IReadOnlyRectangleData
         return CalculateHash();
     }
 
-    public override object Clone()
-    {
-        return new RectangleVectorData(Center, Size)
-        {
-            StrokeColor = StrokeColor,
-            FillColor = FillColor,
-            StrokeWidth = StrokeWidth,
-            TransformationMatrix = TransformationMatrix
-        };
-    }
-
     public override VectorPath ToPath()
     {
         VectorPath path = new VectorPath();

+ 9 - 1
src/PixiEditor.ChangeableDocument/Changeables/Graph/Nodes/Shapes/Data/ShapeVectorData.cs

@@ -37,7 +37,15 @@ public abstract class ShapeVectorData : ICacheable, ICloneable, IReadOnlyShapeVe
     public abstract bool IsValid();
     public abstract int GetCacheHash();
     public abstract int CalculateHash();
-    public abstract object Clone();
+
+    public object Clone()
+    {
+        ShapeVectorData copy = (ShapeVectorData)MemberwiseClone();
+        AdjustCopy(copy);
+        return copy;
+    }
+
+    protected virtual void AdjustCopy(ShapeVectorData copy) {}
 
     public override int GetHashCode()
     {