|
1 | 1 | // Copyright (c) Six Labors. |
2 | 2 | // Licensed under the Six Labors Split License. |
3 | 3 |
|
| 4 | +using System.Numerics; |
| 5 | + |
4 | 6 | namespace SixLabors.ImageSharp.Drawing.Tests.Shapes; |
5 | 7 |
|
6 | 8 | /// <summary> |
@@ -34,4 +36,53 @@ public void SimplePath() |
34 | 36 | Assert.Equal(new PointF(10, 10), points[2]); |
35 | 37 | Assert.Equal(new PointF(0, 10), points[3]); |
36 | 38 | } |
| 39 | + |
| 40 | + [Fact] |
| 41 | + public void EmptyPath_SingletonsExposeExpectedPathTypes() |
| 42 | + { |
| 43 | + Assert.Same(EmptyPath.OpenPath, Path.Empty); |
| 44 | + Assert.Equal(PathTypes.Open, EmptyPath.OpenPath.PathType); |
| 45 | + Assert.Equal(PathTypes.Closed, EmptyPath.ClosedPath.PathType); |
| 46 | + } |
| 47 | + |
| 48 | + [Fact] |
| 49 | + public void EmptyPath_OperationsPreserveSingletons() |
| 50 | + { |
| 51 | + Matrix4x4 transform = Matrix4x4.CreateTranslation(12, 34, 0); |
| 52 | + |
| 53 | + Assert.Same(EmptyPath.ClosedPath, EmptyPath.OpenPath.AsClosedPath()); |
| 54 | + Assert.Same(EmptyPath.ClosedPath, EmptyPath.ClosedPath.AsClosedPath()); |
| 55 | + Assert.Same(EmptyPath.OpenPath, EmptyPath.OpenPath.Transform(transform)); |
| 56 | + Assert.Same(EmptyPath.ClosedPath, EmptyPath.ClosedPath.Transform(transform)); |
| 57 | + } |
| 58 | + |
| 59 | + [Fact] |
| 60 | + public void EmptyPath_ExposesNoPathData() |
| 61 | + { |
| 62 | + Assert.Equal(RectangleF.Empty, EmptyPath.OpenPath.Bounds); |
| 63 | + Assert.Equal(RectangleF.Empty, EmptyPath.ClosedPath.Bounds); |
| 64 | + Assert.Empty(EmptyPath.OpenPath.Flatten()); |
| 65 | + Assert.Empty(EmptyPath.ClosedPath.Flatten()); |
| 66 | + } |
| 67 | + |
| 68 | + [Fact] |
| 69 | + public void EmptyPath_ToLinearGeometry_ReturnsEmptyGeometry() |
| 70 | + { |
| 71 | + LinearGeometry identity = EmptyPath.OpenPath.ToLinearGeometry(Vector2.One); |
| 72 | + LinearGeometry scaled = EmptyPath.ClosedPath.ToLinearGeometry(new Vector2(2F, 3F)); |
| 73 | + |
| 74 | + Assert.Same(identity, scaled); |
| 75 | + Assert.Equal(RectangleF.Empty, identity.Info.Bounds); |
| 76 | + Assert.Equal(0, identity.Info.ContourCount); |
| 77 | + Assert.Equal(0, identity.Info.PointCount); |
| 78 | + Assert.Equal(0, identity.Info.SegmentCount); |
| 79 | + Assert.Equal(0, identity.Info.NonHorizontalSegmentCountPixelBoundary); |
| 80 | + Assert.Equal(0, identity.Info.NonHorizontalSegmentCountPixelCenter); |
| 81 | + Assert.Empty(identity.Contours); |
| 82 | + Assert.Empty(identity.Points); |
| 83 | + |
| 84 | + SegmentEnumerator segments = identity.GetSegments(); |
| 85 | + |
| 86 | + Assert.False(segments.MoveNext()); |
| 87 | + } |
37 | 88 | } |
0 commit comments