Browse Source

code cleanup

pull/140/head
Scott Williams 9 years ago
parent
commit
34b09eb099
  1. 4
      src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs
  2. 4
      src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs
  3. 4
      src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs
  4. 4
      src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs
  5. 4
      src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs
  6. 25
      src/ImageSharp.Drawing/Paths/ShapeRegion.cs
  7. 4
      src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs
  8. 16
      src/ImageSharp.Drawing/Region.cs
  9. 2
      tests/ImageSharp.Tests/Drawing/FillPatternTests.cs
  10. 43
      tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs

4
src/ImageSharp.Drawing/Brushes/ImageBrush{TColor}.cs

@ -116,9 +116,9 @@ namespace ImageSharp.Drawing.Brushes
{
using (PinnedBuffer<float> buffer = new PinnedBuffer<float>(scanline))
{
var slice = buffer.Slice(offset);
BufferPointer<float> 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;

4
src/ImageSharp.Drawing/Brushes/PatternBrush{TColor}.cs

@ -148,9 +148,9 @@ namespace ImageSharp.Drawing.Brushes
{
using (PinnedBuffer<float> buffer = new PinnedBuffer<float>(scanline))
{
var slice = buffer.Slice(offset);
BufferPointer<float> 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;

4
src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs

@ -54,9 +54,9 @@ namespace ImageSharp.Drawing.Processors
{
using (PinnedBuffer<float> buffer = new PinnedBuffer<float>(scanline))
{
var slice = buffer.Slice(offset);
BufferPointer<float> 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;

4
src/ImageSharp.Drawing/Brushes/RecolorBrush{TColor}.cs

@ -140,9 +140,9 @@ namespace ImageSharp.Drawing.Brushes
{
using (PinnedBuffer<float> buffer = new PinnedBuffer<float>(scanline))
{
var slice = buffer.Slice(offset);
BufferPointer<float> 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;

4
src/ImageSharp.Drawing/Brushes/SolidBrush{TColor}.cs

@ -88,9 +88,9 @@ namespace ImageSharp.Drawing.Brushes
{
using (PinnedBuffer<float> buffer = new PinnedBuffer<float>(scanline))
{
var slice = buffer.Slice(offset);
BufferPointer<float> 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;

25
src/ImageSharp.Drawing/Paths/ShapeRegion.cs

@ -40,30 +40,7 @@ namespace ImageSharp.Drawing
public override Rectangle Bounds { get; }
/// <inheritdoc/>
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<Vector2>.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<Vector2>.Shared.Return(innerbuffer);
}
}
/// <inheritdoc/>
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);

4
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

16
src/ImageSharp.Drawing/Region.cs

@ -19,28 +19,18 @@ namespace ImageSharp.Drawing
/// Gets the bounding box that entirely surrounds this region.
/// </summary>
/// <remarks>
/// This should always contains all possible points returned from either <see cref="ScanX(float, float[], int, int)"/> or <see cref="ScanY(float, float[], int, int)"/>.
/// This should always contains all possible points returned from <see cref="Scan(float, float[], int, int)"/>.
/// </remarks>
public abstract Rectangle Bounds { get; }
/// <summary>
/// Scans the X axis for intersections.
/// </summary>
/// <param name="x">The position along the X axis to find intersections.</param>
/// <param name="buffer">The buffer.</param>
/// <param name="length">The length.</param>
/// <param name="offset">The offset.</param>
/// <returns>The number of intersections found.</returns>
public abstract int ScanX(float x, float[] buffer, int length, int offset);
/// <summary>
/// Scans the Y axis for intersections.
/// Scans the X axis for intersections at the Y axis position.
/// </summary>
/// <param name="y">The position along the y axis to find intersections.</param>
/// <param name="buffer">The buffer.</param>
/// <param name="length">The length.</param>
/// <param name="offset">The offset.</param>
/// <returns>The number of intersections found.</returns>
public abstract int ScanY(float y, float[] buffer, int length, int offset);
public abstract int Scan(float y, float[] buffer, int length, int offset);
}
}

2
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<Color>(expectedPattern);
Fast2DArray<Color> expectedPatternFast = new Fast2DArray<Color>(expectedPattern);
int xStride = expectedPatternFast.Width;
int yStride = expectedPatternFast.Height;
int offsetX = r.Next(image.Width / xStride) * xStride;

43
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<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()))
.Callback<Vector2, Vector2, Vector2[], int, int>((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<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()), 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<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once);
}
[Fact]
public void ShapeRegionFromShapeScanXProxyToShape()
{
int xToScan = 10;
ShapeRegion region = new ShapeRegion(pathMock.Object);
pathMock.Setup(x => x.FindIntersections(It.IsAny<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()))
.Callback<Vector2, Vector2, Vector2[], int, int>((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<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()), 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<Vector2>(), It.IsAny<Vector2>(), It.IsAny<Vector2[]>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once);
}

Loading…
Cancel
Save