Browse Source

Standardize Default member in Rect

robloo 2 years ago
parent
commit
509ebddcc4
26 changed files with 40 additions and 36 deletions
  1. 2 2
      src/Avalonia.Base/Media/Geometry.cs
  2. 1 1
      src/Avalonia.Base/Media/GeometryDrawing.cs
  3. 1 1
      src/Avalonia.Base/Media/GlyphRunDrawing.cs
  4. 2 2
      src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs
  5. 8 4
      src/Avalonia.Base/Rect.cs
  6. 1 1
      src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionDrawListVisual.cs
  7. 1 1
      src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionTarget.cs
  8. 1 1
      src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionVisual.cs
  9. 1 1
      src/Avalonia.Base/Rendering/ImmediateRenderer.cs
  10. 1 1
      src/Avalonia.Base/Rendering/SceneGraph/BitmapBlendModeNode.cs
  11. 1 1
      src/Avalonia.Base/Rendering/SceneGraph/ClipNode.cs
  12. 1 1
      src/Avalonia.Base/Rendering/SceneGraph/GeometryClipNode.cs
  13. 2 2
      src/Avalonia.Base/Rendering/SceneGraph/OpacityMaskNode.cs
  14. 1 1
      src/Avalonia.Base/Rendering/SceneGraph/OpacityNode.cs
  15. 3 3
      src/Avalonia.Base/Rendering/SceneGraph/SceneBuilder.cs
  16. 1 1
      src/Avalonia.Controls.DataGrid/Primitives/DataGridCellsPresenter.cs
  17. 1 1
      src/Avalonia.Controls/Flyouts/FlyoutBase.cs
  18. 1 1
      src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs
  19. 1 1
      src/Browser/Avalonia.Browser/WebEmbeddableControlRoot.cs
  20. 1 1
      src/Skia/Avalonia.Skia/GeometryImpl.cs
  21. 1 1
      src/Skia/Avalonia.Skia/StreamGeometryImpl.cs
  22. 1 1
      tests/Avalonia.Base.UnitTests/RectTests.cs
  23. 2 2
      tests/Avalonia.Base.UnitTests/Rendering/DeferredRendererTests_HitTesting.cs
  24. 2 2
      tests/Avalonia.Base.UnitTests/Rendering/SceneGraph/DrawOperationTests.cs
  25. 1 1
      tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs
  26. 1 1
      tests/Avalonia.Controls.UnitTests/Shapes/RectangleTests.cs

+ 2 - 2
src/Avalonia.Base/Media/Geometry.cs

@@ -30,7 +30,7 @@ namespace Avalonia.Media
         /// <summary>
         /// Gets the geometry's bounding rectangle.
         /// </summary>
-        public Rect Bounds => PlatformImpl?.Bounds ?? Rect.Empty;
+        public Rect Bounds => PlatformImpl?.Bounds ?? Rect.Default;
 
         /// <summary>
         /// Gets the platform-specific implementation of the geometry.
@@ -84,7 +84,7 @@ namespace Avalonia.Media
         /// </summary>
         /// <param name="pen">The stroke thickness.</param>
         /// <returns>The bounding rectangle.</returns>
-        public Rect GetRenderBounds(IPen pen) => PlatformImpl?.GetRenderBounds(pen) ?? Rect.Empty;
+        public Rect GetRenderBounds(IPen pen) => PlatformImpl?.GetRenderBounds(pen) ?? Rect.Default;
 
         /// <summary>
         /// Indicates whether the geometry's fill contains the specified point.

+ 1 - 1
src/Avalonia.Base/Media/GeometryDrawing.cs

@@ -69,7 +69,7 @@ namespace Avalonia.Media
         public override Rect GetBounds()
         {
             IPen pen = Pen ?? s_boundsPen;
-			return Geometry?.GetRenderBounds(pen) ?? Rect.Empty;
+			return Geometry?.GetRenderBounds(pen) ?? Rect.Default;
         }
     }
 }

+ 1 - 1
src/Avalonia.Base/Media/GlyphRunDrawing.cs

@@ -32,7 +32,7 @@
 
         public override Rect GetBounds()
         {
-            return GlyphRun != null ? new Rect(GlyphRun.Size) : Rect.Empty;
+            return GlyphRun != null ? new Rect(GlyphRun.Size) : Rect.Default;
         }
     }
 }

+ 2 - 2
src/Avalonia.Base/Media/TextFormatting/TextLineImpl.cs

@@ -528,7 +528,7 @@ namespace Avalonia.Media.TextFormatting
 
             var startX = Start;
             double currentWidth = 0;
-            var currentRect = Rect.Empty;
+            var currentRect = Rect.Default;
 
             TextRunBounds lastRunBounds = default;
 
@@ -762,7 +762,7 @@ namespace Avalonia.Media.TextFormatting
 
             var startX = WidthIncludingTrailingWhitespace;
             double currentWidth = 0;
-            var currentRect = Rect.Empty;
+            var currentRect = Rect.Default;
 
             for (var index = TextRuns.Count - 1; index >= 0; index--)
             {

+ 8 - 4
src/Avalonia.Base/Rect.cs

@@ -16,9 +16,13 @@ namespace Avalonia
         }
 
         /// <summary>
-        /// An empty rectangle.
+        /// A shared default instance representing an empty rectangle.
         /// </summary>
-        public static readonly Rect Empty = default(Rect);
+        public static readonly Rect Default = default;
+
+        /// <inheritdoc cref="Default"/>
+        [Obsolete("Use Default instead.")]
+        public static readonly Rect Empty = Default;
 
         /// <summary>
         /// The X position.
@@ -394,7 +398,7 @@ namespace Avalonia
             }
             else
             {
-                return Empty;
+                return Default;
             }
         }
 
@@ -467,7 +471,7 @@ namespace Avalonia
                 double.IsNaN(rect.X) || double.IsNaN(rect.Y) || 
                 double.IsNaN(Height) || double.IsNaN(Width))
             {
-                return Rect.Empty;
+                return Rect.Default;
             }
 
             if (rect.Width < 0)

+ 1 - 1
src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionDrawListVisual.cs

@@ -37,7 +37,7 @@ internal class ServerCompositionDrawListVisual : ServerCompositionContainerVisua
         {
             if (_contentBounds == null)
             {
-                var rect = Rect.Empty;
+                var rect = Rect.Default;
                 if(_renderCommands!=null)
                     foreach (var cmd in _renderCommands)
                         rect = rect.Union(cmd.Item.Bounds);

+ 1 - 1
src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionTarget.cs

@@ -160,7 +160,7 @@ namespace Avalonia.Rendering.Composition.Server
                 }
                 RenderedVisuals = 0;
 
-                _dirtyRect = Rect.Empty;
+                _dirtyRect = Rect.Default;
             }
         }
 

+ 1 - 1
src/Avalonia.Base/Rendering/Composition/Server/ServerCompositionVisual.cs

@@ -192,7 +192,7 @@ namespace Avalonia.Rendering.Composition.Server
 
         void AddDirtyRect(Rect rc)
         {
-            if(rc == Rect.Empty)
+            if(rc == Rect.Default)
                 return;
             Root?.AddDirtyRect(rc);
         }

+ 1 - 1
src/Avalonia.Base/Rendering/ImmediateRenderer.cs

@@ -127,7 +127,7 @@ namespace Avalonia.Rendering
         /// <inheritdoc/>
         public void AddDirty(Visual visual)
         {
-            if (visual.Bounds != Rect.Empty)
+            if (visual.Bounds != Rect.Default)
             {
                 var m = visual.TransformToVisual(_root);
 

+ 1 - 1
src/Avalonia.Base/Rendering/SceneGraph/BitmapBlendModeNode.cs

@@ -27,7 +27,7 @@ namespace Avalonia.Rendering.SceneGraph
         }
 
         /// <inheritdoc/>
-        public Rect Bounds => Rect.Empty;
+        public Rect Bounds => Rect.Default;
 
         /// <summary>
         /// Gets the BitmapBlend to be pushed or null if the operation represents a pop.

+ 1 - 1
src/Avalonia.Base/Rendering/SceneGraph/ClipNode.cs

@@ -40,7 +40,7 @@ namespace Avalonia.Rendering.SceneGraph
         }
 
         /// <inheritdoc/>
-        public Rect Bounds => Rect.Empty;
+        public Rect Bounds => Rect.Default;
 
         /// <summary>
         /// Gets the clip to be pushed or null if the operation represents a pop.

+ 1 - 1
src/Avalonia.Base/Rendering/SceneGraph/GeometryClipNode.cs

@@ -28,7 +28,7 @@ namespace Avalonia.Rendering.SceneGraph
         }
 
         /// <inheritdoc/>
-        public Rect Bounds => Rect.Empty;
+        public Rect Bounds => Rect.Default;
 
         /// <summary>
         /// Gets the clip to be pushed or null if the operation represents a pop.

+ 2 - 2
src/Avalonia.Base/Rendering/SceneGraph/OpacityMaskNode.cs

@@ -19,7 +19,7 @@ namespace Avalonia.Rendering.SceneGraph
         /// <param name="bounds">The bounds of the mask.</param>
         /// <param name="aux">Auxiliary data required to draw the brush.</param>
         public OpacityMaskNode(IBrush mask, Rect bounds, IDisposable? aux = null)
-            : base(Rect.Empty, Matrix.Identity, aux)
+            : base(Rect.Default, Matrix.Identity, aux)
         {
             Mask = mask.ToImmutable();
             MaskBounds = bounds;
@@ -30,7 +30,7 @@ namespace Avalonia.Rendering.SceneGraph
         /// opacity mask pop.
         /// </summary>
         public OpacityMaskNode()
-            : base(Rect.Empty, Matrix.Identity, null)
+            : base(Rect.Default, Matrix.Identity, null)
         {
         }
 

+ 1 - 1
src/Avalonia.Base/Rendering/SceneGraph/OpacityNode.cs

@@ -26,7 +26,7 @@ namespace Avalonia.Rendering.SceneGraph
         }
 
         /// <inheritdoc/>
-        public Rect Bounds => Rect.Empty;
+        public Rect Bounds => Rect.Default;
 
         /// <summary>
         /// Gets the opacity to be pushed or null if the operation represents a pop.

+ 3 - 3
src/Avalonia.Base/Rendering/SceneGraph/SceneBuilder.cs

@@ -331,8 +331,8 @@ namespace Avalonia.Rendering.SceneGraph
 
                 scene.Size = newSize;
 
-                Rect horizontalDirtyRect = Rect.Empty;
-                Rect verticalDirtyRect = Rect.Empty;
+                Rect horizontalDirtyRect = Rect.Default;
+                Rect verticalDirtyRect = Rect.Default;
 
                 if (newSize.Width > oldSize.Width)
                 {
@@ -429,7 +429,7 @@ namespace Avalonia.Rendering.SceneGraph
             else
             {
                 layer.OpacityMask = null;
-                layer.OpacityMaskRect = Rect.Empty;
+                layer.OpacityMaskRect = Rect.Default;
             }
 
             layer.GeometryClip = node.HasAncestorGeometryClip ?

+ 1 - 1
src/Avalonia.Controls.DataGrid/Primitives/DataGridCellsPresenter.cs

@@ -161,7 +161,7 @@ namespace Avalonia.Controls.Primitives
                 {
                     // Clip
                     RectangleGeometry rg = new RectangleGeometry();
-                    rg.Rect = Rect.Empty;
+                    rg.Rect = Rect.Default;
                     cell.Clip = rg;
                 }
             }

+ 1 - 1
src/Avalonia.Controls/Flyouts/FlyoutBase.cs

@@ -457,7 +457,7 @@ namespace Avalonia.Controls.Primitives
                     PopupPositioning.PopupPositionerConstraintAdjustment.SlideY;
             }
 
-            var trgtBnds = Target?.Bounds ?? Rect.Empty;
+            var trgtBnds = Target?.Bounds ?? Rect.Default;
 
             switch (Placement)
             {

+ 1 - 1
src/Avalonia.Headless/HeadlessPlatformRenderInterface.cs

@@ -212,7 +212,7 @@ namespace Avalonia.Headless
 
         class HeadlessStreamingGeometryStub : HeadlessGeometryStub, IStreamGeometryImpl
         {
-            public HeadlessStreamingGeometryStub() : base(Rect.Empty)
+            public HeadlessStreamingGeometryStub() : base(Rect.Default)
             {
             }
 

+ 1 - 1
src/Browser/Avalonia.Browser/WebEmbeddableControlRoot.cs

@@ -18,7 +18,7 @@ namespace Avalonia.Browser
                 _onFirstRender = onFirstRender;
             }
 
-            public Rect Bounds => Rect.Empty;
+            public Rect Bounds => Rect.Default;
 
             public bool HasRendered => _hasRendered;
 

+ 1 - 1
src/Skia/Avalonia.Skia/GeometryImpl.cs

@@ -244,7 +244,7 @@ namespace Avalonia.Skia
             public void Invalidate()
             {
                 CachedStrokePath?.Dispose();
-                CachedGeometryRenderBounds = Rect.Empty;
+                CachedGeometryRenderBounds = Rect.Default;
                 _cachedStrokeWidth = default(float);
             }
         }

+ 1 - 1
src/Skia/Avalonia.Skia/StreamGeometryImpl.cs

@@ -34,7 +34,7 @@ namespace Avalonia.Skia
         /// <summary>
         /// Initializes a new instance of the <see cref="StreamGeometryImpl"/> class.
         /// </summary>
-        public StreamGeometryImpl() : this(CreateEmptyPath(), Rect.Empty)
+        public StreamGeometryImpl() : this(CreateEmptyPath(), Rect.Default)
         {
         }
         

+ 1 - 1
tests/Avalonia.Base.UnitTests/RectTests.cs

@@ -52,7 +52,7 @@ namespace Avalonia.Base.UnitTests
                 double.PositiveInfinity, double.PositiveInfinity)
                 .Normalize();
 
-            Assert.Equal(Rect.Empty, result);
+            Assert.Equal(Rect.Default, result);
         }
     }
 }

+ 2 - 2
tests/Avalonia.Base.UnitTests/Rendering/DeferredRendererTests_HitTesting.cs

@@ -403,7 +403,7 @@ namespace Avalonia.Base.UnitTests.Rendering
                 root.Measure(Size.Infinity);
                 root.Arrange(new Rect(container.DesiredSize));
                 
-                root.Renderer.Paint(Rect.Empty);
+                root.Renderer.Paint(Rect.Default);
                 var result = root.Renderer.HitTest(new Point(50, 150), root, null).First();
 
                 Assert.Equal(item1, result);
@@ -419,7 +419,7 @@ namespace Avalonia.Base.UnitTests.Rendering
                 container.InvalidateArrange();
                 container.Arrange(new Rect(container.DesiredSize));
 
-                root.Renderer.Paint(Rect.Empty);
+                root.Renderer.Paint(Rect.Default);
                 result = root.Renderer.HitTest(new Point(50, 150), root, null).First();
                 Assert.Equal(item2, result);
 

+ 2 - 2
tests/Avalonia.Base.UnitTests/Rendering/SceneGraph/DrawOperationTests.cs

@@ -13,9 +13,9 @@ namespace Avalonia.Base.UnitTests.Rendering.SceneGraph
         [Fact]
         public void Empty_Bounds_Remain_Empty()
         {
-            var target = new TestDrawOperation(Rect.Empty, Matrix.Identity, null);
+            var target = new TestDrawOperation(Rect.Default, Matrix.Identity, null);
 
-            Assert.Equal(Rect.Empty, target.Bounds);
+            Assert.Equal(Rect.Default, target.Bounds);
         }
 
         [Theory]

+ 1 - 1
tests/Avalonia.Controls.UnitTests/Presenters/ItemsPresenterTests_Virtualization_Simple.cs

@@ -570,7 +570,7 @@ namespace Avalonia.Controls.UnitTests.Presenters
                 var items = (IList<string>)target.Items;
                 target.ApplyTemplate();
                 target.Measure(Size.Empty);
-                target.Arrange(Rect.Empty);
+                target.Arrange(Rect.Default);
 
                 // Check for issue #591: this should not throw.
                 target.ScrollIntoView(0);

+ 1 - 1
tests/Avalonia.Controls.UnitTests/Shapes/RectangleTests.cs

@@ -18,7 +18,7 @@ namespace Avalonia.Controls.UnitTests.Shapes
             target.Measure(new Size(100, 100));
 
             var geometry = Assert.IsType<RectangleGeometry>(target.RenderedGeometry);
-            Assert.Equal(Rect.Empty, geometry.Rect);
+            Assert.Equal(Rect.Default, geometry.Rect);
         }
 
         [Fact]