Browse Source

Fixed multiple subshapes with unclosed one case

flabbet 8 months ago
parent
commit
c448f5e3b2

+ 5 - 1
src/PixiEditor/Views/Overlays/PathOverlay/EditableVectorPath.cs

@@ -125,7 +125,11 @@ public class EditableVectorPath
                 isSubShapeClosed = false;
                 if (data.verb == PathVerb.Move)
                 {
-                    currentSubShapePoints.Clear();
+                    if (currentSubShapePoints.Count > 0)
+                    {
+                        subShapes.Add(new SubShape(currentSubShapePoints, isSubShapeClosed));
+                        currentSubShapePoints.Clear();
+                    }
                 }
                 else
                 {

+ 30 - 0
tests/PixiEditor.Tests/EditableVectorPathTests.cs

@@ -332,6 +332,36 @@ public class EditableVectorPathTests
         Assert.Equal(new VecF(0, 0), editablePath.SubShapes[0].Points[4].Verb.To);
     }
 
+    [Fact]
+    public void TestThatMultiSubShapesWithUnclosedReturnsCorrectPoints()
+    {
+        VectorPath path = new VectorPath();
+        
+        path.LineTo(new VecF(2, 2));
+        path.LineTo(new VecF(0, 4));
+        
+        path.AddOval(RectD.FromCenterAndSize(new VecD(5, 5), new VecD(10, 10)));
+        
+        EditableVectorPath editablePath = new EditableVectorPath(path);
+        
+        Assert.Equal(2, editablePath.SubShapes.Count);
+        
+        Assert.Equal(3, editablePath.SubShapes[0].Points.Count);
+        Assert.Equal(new VecF(0, 0), editablePath.SubShapes[0].Points[0].Position);
+        Assert.Equal(new VecF(2, 2), editablePath.SubShapes[0].Points[1].Position);
+        Assert.Equal(new VecF(0, 4), editablePath.SubShapes[0].Points[2].Position);
+        
+        Assert.False(editablePath.SubShapes[0].IsClosed);
+        
+        Assert.Equal(4, editablePath.SubShapes[1].Points.Count);
+        Assert.Equal(new VecF(10, 5), editablePath.SubShapes[1].Points[0].Position);
+        Assert.Equal(new VecF(5, 10), editablePath.SubShapes[1].Points[1].Position);
+        Assert.Equal(new VecF(0, 5), editablePath.SubShapes[1].Points[2].Position);
+        Assert.Equal(new VecF(5, 0), editablePath.SubShapes[1].Points[3].Position);
+        
+        Assert.True(editablePath.SubShapes[1].IsClosed);
+    }
+
     [Fact]
     public void TestThatEditingPointResultsInCorrectVectorPath()
     {