From 34b09eb0994a9feee1adaff08f865593ffa87a3e Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Fri, 17 Mar 2017 19:37:13 +0000 Subject: [PATCH] code cleanup --- .../Brushes/ImageBrush{TColor}.cs | 4 +- .../Brushes/PatternBrush{TColor}.cs | 4 +- .../Brushes/Processors/BrushApplicator.cs | 4 +- .../Brushes/RecolorBrush{TColor}.cs | 4 +- .../Brushes/SolidBrush{TColor}.cs | 4 +- src/ImageSharp.Drawing/Paths/ShapeRegion.cs | 25 +---------- .../Processors/FillRegionProcessor.cs | 4 +- src/ImageSharp.Drawing/Region.cs | 16 ++----- .../Drawing/FillPatternTests.cs | 2 +- .../Drawing/Paths/ShapeRegionTests.cs | 43 +------------------ 10 files changed, 19 insertions(+), 91 deletions(-) diff --git a/src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs index 400c85bc7..f3ea81cf6 100644 --- a/src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs +++ b/src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs @@ -116,9 +116,9 @@ namespace ImageSharp.Drawing.Brushes { using (PinnedBuffer buffer = new PinnedBuffer(scanline)) { - var slice = buffer.Slice(offset); + BufferPointer slice = buffer.Slice(offset); - for (var xPos = 0; xPos < scanlineWidth; xPos++) + for (int xPos = 0; xPos < scanlineWidth; xPos++) { int targetX = xPos + x; int targetY = y; diff --git a/src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs index 9ebaf811a..55152d234 100644 --- a/src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs +++ b/src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs @@ -148,9 +148,9 @@ namespace ImageSharp.Drawing.Brushes { using (PinnedBuffer buffer = new PinnedBuffer(scanline)) { - var slice = buffer.Slice(offset); + BufferPointer slice = buffer.Slice(offset); - for (var xPos = 0; xPos < scanlineWidth; xPos++) + for (int xPos = 0; xPos < scanlineWidth; xPos++) { int targetX = xPos + x; int targetY = y; diff --git a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs index 87cf949e8..679d87170 100644 --- a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs +++ b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs @@ -54,9 +54,9 @@ namespace ImageSharp.Drawing.Processors { using (PinnedBuffer buffer = new PinnedBuffer(scanline)) { - var slice = buffer.Slice(offset); + BufferPointer slice = buffer.Slice(offset); - for (var xPos = 0; xPos < scanlineWidth; xPos++) + for (int xPos = 0; xPos < scanlineWidth; xPos++) { int targetX = xPos + x; int targetY = y; diff --git a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs index 158f0309f..92e519161 100644 --- a/src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs +++ b/src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs @@ -140,9 +140,9 @@ namespace ImageSharp.Drawing.Brushes { using (PinnedBuffer buffer = new PinnedBuffer(scanline)) { - var slice = buffer.Slice(offset); + BufferPointer slice = buffer.Slice(offset); - for (var xPos = 0; xPos < scanlineWidth; xPos++) + for (int xPos = 0; xPos < scanlineWidth; xPos++) { int targetX = xPos + x; int targetY = y; diff --git a/src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs b/src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs index 67d484435..bdac7fdc7 100644 --- a/src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs +++ b/src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs @@ -88,9 +88,9 @@ namespace ImageSharp.Drawing.Brushes { using (PinnedBuffer buffer = new PinnedBuffer(scanline)) { - var slice = buffer.Slice(offset); + BufferPointer slice = buffer.Slice(offset); - for (var xPos = 0; xPos < scanlineWidth; xPos++) + for (int xPos = 0; xPos < scanlineWidth; xPos++) { int targetX = xPos + x; int targetY = y; diff --git a/src/ImageSharp.Drawing/Paths/ShapeRegion.cs b/src/ImageSharp.Drawing/Paths/ShapeRegion.cs index 9a350857c..086894531 100644 --- a/src/ImageSharp.Drawing/Paths/ShapeRegion.cs +++ b/src/ImageSharp.Drawing/Paths/ShapeRegion.cs @@ -40,30 +40,7 @@ namespace ImageSharp.Drawing public override Rectangle Bounds { get; } /// - public override int ScanX(float x, float[] buffer, int length, int offset) - { - Vector2 start = new Vector2(x, this.Bounds.Top - 1); - Vector2 end = new Vector2(x, this.Bounds.Bottom + 1); - Vector2[] innerbuffer = ArrayPool.Shared.Rent(length); - try - { - int count = this.Shape.FindIntersections(start, end, innerbuffer, length, 0); - - for (int i = 0; i < count; i++) - { - buffer[i + offset] = innerbuffer[i].Y; - } - - return count; - } - finally - { - ArrayPool.Shared.Return(innerbuffer); - } - } - - /// - public override int ScanY(float y, float[] buffer, int length, int offset) + public override int Scan(float y, float[] buffer, int length, int offset) { Vector2 start = new Vector2(this.Bounds.Left - 1, y); Vector2 end = new Vector2(this.Bounds.Right + 1, y); diff --git a/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs b/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs index 81de21b5f..66e1f4380 100644 --- a/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs @@ -88,7 +88,7 @@ namespace ImageSharp.Drawing.Processors try { bool scanlineDirty = true; - for (var y = minY; y < maxY; y++) + for (int y = minY; y < maxY; y++) { if (scanlineDirty) { @@ -105,7 +105,7 @@ namespace ImageSharp.Drawing.Processors float subpixelFractionPoint = subpixelFraction / subpixelCount; for (float subPixel = (float)y; subPixel < y + 1; subPixel += subpixelFraction) { - int pointsFound = region.ScanY(subPixel, buffer, maxIntersections, 0); + int pointsFound = region.Scan(subPixel, buffer, maxIntersections, 0); if (pointsFound == 0) { // nothing on this line skip diff --git a/src/ImageSharp.Drawing/Region.cs b/src/ImageSharp.Drawing/Region.cs index f62fb0b03..8cab88502 100644 --- a/src/ImageSharp.Drawing/Region.cs +++ b/src/ImageSharp.Drawing/Region.cs @@ -19,28 +19,18 @@ namespace ImageSharp.Drawing /// Gets the bounding box that entirely surrounds this region. /// /// - /// This should always contains all possible points returned from either or . + /// This should always contains all possible points returned from . /// public abstract Rectangle Bounds { get; } /// - /// Scans the X axis for intersections. - /// - /// The position along the X axis to find intersections. - /// The buffer. - /// The length. - /// The offset. - /// The number of intersections found. - public abstract int ScanX(float x, float[] buffer, int length, int offset); - - /// - /// Scans the Y axis for intersections. + /// Scans the X axis for intersections at the Y axis position. /// /// The position along the y axis to find intersections. /// The buffer. /// The length. /// The offset. /// The number of intersections found. - public abstract int ScanY(float y, float[] buffer, int length, int offset); + public abstract int Scan(float y, float[] buffer, int length, int offset); } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs b/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs index 56066a7aa..8162bc531 100644 --- a/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs @@ -33,7 +33,7 @@ namespace ImageSharp.Tests.Drawing { // lets pick random spots to start checking Random r = new Random(); - var expectedPatternFast = new Fast2DArray(expectedPattern); + Fast2DArray expectedPatternFast = new Fast2DArray(expectedPattern); int xStride = expectedPatternFast.Width; int yStride = expectedPatternFast.Height; int offsetX = r.Next(image.Width / xStride) * xStride; diff --git a/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs b/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs index aa7c0575c..78c349233 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs @@ -67,25 +67,6 @@ namespace ImageSharp.Tests.Drawing.Paths pathMock.Verify(x => x.MaxIntersections); } - [Fact] - public void ShapeRegionFromPathScanXProxyToShape() - { - int xToScan = 10; - ShapeRegion region = new ShapeRegion(pathMock.Object); - - pathMock.Setup(x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((s, e, b, c, o) => { - Assert.Equal(xToScan, s.X); - Assert.Equal(xToScan, e.X); - Assert.True(s.Y < bounds.Top); - Assert.True(e.Y > bounds.Bottom); - }).Returns(0); - - int i = region.ScanX(xToScan, new float[0], 0, 0); - - pathMock.Verify(x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); - } - [Fact] public void ShapeRegionFromPathScanYProxyToShape() { @@ -100,27 +81,7 @@ namespace ImageSharp.Tests.Drawing.Paths Assert.True(e.X > bounds.Right); }).Returns(0); - int i = region.ScanY(yToScan, new float[0], 0, 0); - - pathMock.Verify(x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); - } - - - [Fact] - public void ShapeRegionFromShapeScanXProxyToShape() - { - int xToScan = 10; - ShapeRegion region = new ShapeRegion(pathMock.Object); - - pathMock.Setup(x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny())) - .Callback((s, e, b, c, o) => { - Assert.Equal(xToScan, s.X); - Assert.Equal(xToScan, e.X); - Assert.True(s.Y < bounds.Top); - Assert.True(e.Y > bounds.Bottom); - }).Returns(0); - - int i = region.ScanX(xToScan, new float[0], 0, 0); + int i = region.Scan(yToScan, new float[0], 0, 0); pathMock.Verify(x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); } @@ -139,7 +100,7 @@ namespace ImageSharp.Tests.Drawing.Paths Assert.True(e.X > bounds.Right); }).Returns(0); - int i = region.ScanY(yToScan, new float[0], 0, 0); + int i = region.Scan(yToScan, new float[0], 0, 0); pathMock.Verify(x => x.FindIntersections(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); }