Browse Source

some cleanup

pull/98/head
Scott Williams 9 years ago
parent
commit
8994d9853b
  1. 18
      src/ImageSharp.Drawing.Paths/ShapePath.cs
  2. 12
      src/ImageSharp.Drawing.Paths/ShapeRegion.cs
  3. 12
      src/ImageSharp.Drawing/DrawPath.cs
  4. 6
      src/ImageSharp.Drawing/Drawable.cs
  5. 4
      src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs
  6. 6
      tests/ImageSharp.Tests/Drawing/DrawPathTests.cs
  7. 13
      tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs
  8. 2
      tests/ImageSharp.Tests/Drawing/PolygonTests.cs
  9. 8
      tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs
  10. 6
      tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs

18
src/ImageSharp.Drawing.Paths/ShapePath.cs

@ -18,7 +18,7 @@ namespace ImageSharp.Drawing
/// <summary> /// <summary>
/// A drawable mapping between a <see cref="SixLabors.Shapes.IShape"/>/<see cref="SixLabors.Shapes.IPath"/> and a drawable/fillable region. /// A drawable mapping between a <see cref="SixLabors.Shapes.IShape"/>/<see cref="SixLabors.Shapes.IPath"/> and a drawable/fillable region.
/// </summary> /// </summary>
internal class ShapePath : ImageSharp.Drawing.Path internal class ShapePath : ImageSharp.Drawing.Drawable
{ {
/// <summary> /// <summary>
/// The fillable shape /// The fillable shape
@ -92,8 +92,8 @@ namespace ImageSharp.Drawing
/// </returns> /// </returns>
public override int ScanX(int x, float[] buffer, int length, int offset) public override int ScanX(int x, float[] buffer, int length, int offset)
{ {
var start = new Vector2(x, this.Bounds.Top - 1); Vector2 start = new Vector2(x, this.Bounds.Top - 1);
var end = new Vector2(x, this.Bounds.Bottom + 1); Vector2 end = new Vector2(x, this.Bounds.Bottom + 1);
Vector2[] innerbuffer = ArrayPool<Vector2>.Shared.Rent(length); Vector2[] innerbuffer = ArrayPool<Vector2>.Shared.Rent(length);
try try
{ {
@ -104,7 +104,7 @@ namespace ImageSharp.Drawing
length, length,
0); 0);
for (var i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
buffer[i + offset] = innerbuffer[i].Y; buffer[i + offset] = innerbuffer[i].Y;
} }
@ -129,8 +129,8 @@ namespace ImageSharp.Drawing
/// </returns> /// </returns>
public override int ScanY(int y, float[] buffer, int length, int offset) public override int ScanY(int y, float[] buffer, int length, int offset)
{ {
var start = new Vector2(float.MinValue, y); Vector2 start = new Vector2(float.MinValue, y);
var end = new Vector2(float.MaxValue, y); Vector2 end = new Vector2(float.MaxValue, y);
Vector2[] innerbuffer = ArrayPool<Vector2>.Shared.Rent(length); Vector2[] innerbuffer = ArrayPool<Vector2>.Shared.Rent(length);
try try
{ {
@ -141,7 +141,7 @@ namespace ImageSharp.Drawing
length, length,
0); 0);
for (var i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
buffer[i + offset] = innerbuffer[i].X; buffer[i + offset] = innerbuffer[i].X;
} }
@ -162,13 +162,13 @@ namespace ImageSharp.Drawing
/// <returns>Information about the the point</returns> /// <returns>Information about the the point</returns>
public override PointInfo GetPointInfo(int x, int y) public override PointInfo GetPointInfo(int x, int y)
{ {
var point = new Vector2(x, y); Vector2 point = new Vector2(x, y);
SixLabors.Shapes.PointInfo result = default(SixLabors.Shapes.PointInfo); SixLabors.Shapes.PointInfo result = default(SixLabors.Shapes.PointInfo);
float distance = float.MaxValue; float distance = float.MaxValue;
for (int i = 0; i < this.Paths.Length; i++) for (int i = 0; i < this.Paths.Length; i++)
{ {
var p = this.Paths[i].Distance(point); SixLabors.Shapes.PointInfo p = this.Paths[i].Distance(point);
if (p.DistanceFromPath < distance) if (p.DistanceFromPath < distance)
{ {
distance = p.DistanceFromPath; distance = p.DistanceFromPath;

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

@ -72,8 +72,8 @@ namespace ImageSharp.Drawing
/// </returns> /// </returns>
public override int ScanX(int x, float[] buffer, int length, int offset) public override int ScanX(int x, float[] buffer, int length, int offset)
{ {
var start = new Vector2(x, this.Bounds.Top - 1); Vector2 start = new Vector2(x, this.Bounds.Top - 1);
var end = new Vector2(x, this.Bounds.Bottom + 1); Vector2 end = new Vector2(x, this.Bounds.Bottom + 1);
Vector2[] innerbuffer = ArrayPool<Vector2>.Shared.Rent(length); Vector2[] innerbuffer = ArrayPool<Vector2>.Shared.Rent(length);
try try
{ {
@ -84,7 +84,7 @@ namespace ImageSharp.Drawing
length, length,
0); 0);
for (var i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
buffer[i + offset] = innerbuffer[i].Y; buffer[i + offset] = innerbuffer[i].Y;
} }
@ -109,8 +109,8 @@ namespace ImageSharp.Drawing
/// </returns> /// </returns>
public override int ScanY(int y, float[] buffer, int length, int offset) public override int ScanY(int y, float[] buffer, int length, int offset)
{ {
var start = new Vector2(float.MinValue, y); Vector2 start = new Vector2(float.MinValue, y);
var end = new Vector2(float.MaxValue, y); Vector2 end = new Vector2(float.MaxValue, y);
Vector2[] innerbuffer = ArrayPool<Vector2>.Shared.Rent(length); Vector2[] innerbuffer = ArrayPool<Vector2>.Shared.Rent(length);
try try
{ {
@ -121,7 +121,7 @@ namespace ImageSharp.Drawing
length, length,
0); 0);
for (var i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
buffer[i + offset] = innerbuffer[i].X; buffer[i + offset] = innerbuffer[i].X;
} }

12
src/ImageSharp.Drawing/DrawPath.cs

@ -28,7 +28,7 @@ namespace ImageSharp
/// <returns> /// <returns>
/// The Image /// The Image
/// </returns> /// </returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, Path path, GraphicsOptions options) public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, Drawable path, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
return source.Apply(new DrawPathProcessor<TColor>(pen, path, options)); return source.Apply(new DrawPathProcessor<TColor>(pen, path, options));
@ -44,7 +44,7 @@ namespace ImageSharp
/// <returns> /// <returns>
/// The Image /// The Image
/// </returns> /// </returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, Path path) public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, Drawable path)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
return source.Draw(pen, path, GraphicsOptions.Default); return source.Draw(pen, path, GraphicsOptions.Default);
@ -62,7 +62,7 @@ namespace ImageSharp
/// <returns> /// <returns>
/// The Image /// The Image
/// </returns> /// </returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Path path, GraphicsOptions options) public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Drawable path, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
return source.Draw(new Pen<TColor>(brush, thickness), path, options); return source.Draw(new Pen<TColor>(brush, thickness), path, options);
@ -79,7 +79,7 @@ namespace ImageSharp
/// <returns> /// <returns>
/// The Image /// The Image
/// </returns> /// </returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Path path) public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Drawable path)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
return source.Draw(new Pen<TColor>(brush, thickness), path); return source.Draw(new Pen<TColor>(brush, thickness), path);
@ -97,7 +97,7 @@ namespace ImageSharp
/// <returns> /// <returns>
/// The Image /// The Image
/// </returns> /// </returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, Path path, GraphicsOptions options) public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, Drawable path, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
return source.Draw(new SolidBrush<TColor>(color), thickness, path, options); return source.Draw(new SolidBrush<TColor>(color), thickness, path, options);
@ -114,7 +114,7 @@ namespace ImageSharp
/// <returns> /// <returns>
/// The Image /// The Image
/// </returns> /// </returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, Path path) public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, Drawable path)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
return source.Draw(new SolidBrush<TColor>(color), thickness, path); return source.Draw(new SolidBrush<TColor>(color), thickness, path);

6
src/ImageSharp.Drawing/Path.cs → src/ImageSharp.Drawing/Drawable.cs

@ -1,4 +1,4 @@
// <copyright file="Path.cs" company="James Jackson-South"> // <copyright file="Drawable.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
@ -6,9 +6,9 @@
namespace ImageSharp.Drawing namespace ImageSharp.Drawing
{ {
/// <summary> /// <summary>
/// Represents a something that has knowledge about its outline. /// Represents a path or set of paths that can be drawn as an outline.
/// </summary> /// </summary>
public abstract class Path public abstract class Drawable
{ {
/// <summary> /// <summary>
/// Gets the maximum number of intersections to could be returned. /// Gets the maximum number of intersections to could be returned.

4
src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs

@ -31,7 +31,7 @@ namespace ImageSharp.Drawing.Processors
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="region">The region.</param> /// <param name="region">The region.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
public DrawPathProcessor(IPen<TColor> pen, Path region, GraphicsOptions options) public DrawPathProcessor(IPen<TColor> pen, Drawable region, GraphicsOptions options)
{ {
this.Path = region; this.Path = region;
this.Pen = pen; this.Pen = pen;
@ -60,7 +60,7 @@ namespace ImageSharp.Drawing.Processors
/// <value> /// <value>
/// The path. /// The path.
/// </value> /// </value>
public Path Path { get; } public Drawable Path { get; }
/// <inheritdoc/> /// <inheritdoc/>
protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle) protected override void OnApply(ImageBase<TColor> source, Rectangle sourceRectangle)

6
tests/ImageSharp.Tests/Drawing/DrawPathTests.cs

@ -33,13 +33,13 @@ namespace ImageSharp.Tests.Drawing
new Vector2(60, 10), new Vector2(60, 10),
new Vector2(10, 400)); new Vector2(10, 400));
ShapePath p = new ShapePath(linerSegemnt, bazierSegment); ShapePath p = new ShapePath(linerSegemnt, bazierSegment);
using (FileStream output = File.OpenWrite($"{path}/Simple.png")) using (FileStream output = File.OpenWrite($"{path}/Simple.png"))
{ {
image image
.BackgroundColor(Color.Blue) .BackgroundColor(Color.Blue)
.Draw(Color.HotPink, 5, p) .Draw(Color.HotPink, 5, p)
.Save(output); .Save(output);
} }
@ -82,7 +82,7 @@ namespace ImageSharp.Tests.Drawing
{ {
image image
.BackgroundColor(Color.Blue) .BackgroundColor(Color.Blue)
.Draw(color, 10, p) .Draw(color, 10, p)
.Save(output); .Save(output);
} }

13
tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs

@ -37,8 +37,8 @@ namespace ImageSharp.Tests.Drawing
{ {
image image
.BackgroundColor(Color.Blue) .BackgroundColor(Color.Blue)
.Draw(Color.HotPink, 5, simplePath.Clip(hole1)) .Draw(Color.HotPink, 5, simplePath.Clip(hole1))
.Save(output); .Save(output);
} }
using (PixelAccessor<Color> sourcePixels = image.Lock()) using (PixelAccessor<Color> sourcePixels = image.Lock())
@ -87,7 +87,7 @@ namespace ImageSharp.Tests.Drawing
{ {
image image
.BackgroundColor(Color.Blue) .BackgroundColor(Color.Blue)
.Draw(Color.HotPink, 5, simplePath.Clip(hole1)) .Draw(Color.HotPink, 5, simplePath.Clip(hole1))
.Save(output); .Save(output);
} }
@ -131,7 +131,6 @@ namespace ImageSharp.Tests.Drawing
new Vector2(37, 85), new Vector2(37, 85),
new Vector2(130, 40), new Vector2(130, 40),
new Vector2(65, 137))); new Vector2(65, 137)));
using (Image image = new Image(500, 500)) using (Image image = new Image(500, 500))
{ {
@ -139,7 +138,7 @@ namespace ImageSharp.Tests.Drawing
{ {
image image
.BackgroundColor(Color.Blue) .BackgroundColor(Color.Blue)
.Draw(Color.HotPink, 5, simplePath.Clip(hole1)) .Draw(Color.HotPink, 5, simplePath.Clip(hole1))
.Save(output); .Save(output);
} }
@ -185,7 +184,7 @@ namespace ImageSharp.Tests.Drawing
{ {
image image
.BackgroundColor(Color.Blue) .BackgroundColor(Color.Blue)
.Draw(Pens.Dash(Color.HotPink, 5), simplePath.Clip(hole1)) .Draw(Pens.Dash(Color.HotPink, 5), simplePath.Clip(hole1))
.Save(output); .Save(output);
} }
} }
@ -213,7 +212,7 @@ namespace ImageSharp.Tests.Drawing
{ {
image image
.BackgroundColor(Color.Blue) .BackgroundColor(Color.Blue)
.Draw(color, 5, simplePath.Clip(hole1)) .Draw(color, 5, simplePath.Clip(hole1))
.Save(output); .Save(output);
} }

2
tests/ImageSharp.Tests/Drawing/PolygonTests.cs

@ -97,7 +97,7 @@ namespace ImageSharp.Tests.Drawing
{ {
image image
.BackgroundColor(Color.Blue) .BackgroundColor(Color.Blue)
.Draw(Color.HotPink, 10, new Rectangle(10, 10, 190, 140)) .Draw(Color.HotPink, 10, new Rectangle(10, 10, 190, 140))
.Save(output); .Save(output);
} }

8
tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs

@ -35,7 +35,7 @@ namespace ImageSharp.Tests.Drawing
{ {
image image
.BackgroundColor(Color.Blue) .BackgroundColor(Color.Blue)
.Fill(Color.HotPink, simplePath.Clip(hole1)) .Fill(Color.HotPink, simplePath.Clip(hole1))
.Save(output); .Save(output);
} }
@ -78,7 +78,7 @@ namespace ImageSharp.Tests.Drawing
{ {
image image
.BackgroundColor(Color.Blue) .BackgroundColor(Color.Blue)
.Fill(Color.HotPink, simplePath.Clip(hole1)) .Fill(Color.HotPink, simplePath.Clip(hole1))
.Save(output); .Save(output);
} }
@ -121,8 +121,8 @@ namespace ImageSharp.Tests.Drawing
{ {
image image
.BackgroundColor(Color.Blue) .BackgroundColor(Color.Blue)
.Fill(color, simplePath.Clip(hole1)) .Fill(color, simplePath.Clip(hole1))
.Save(output); .Save(output);
} }
//shift background color towards forground color by the opacity amount //shift background color towards forground color by the opacity amount

6
tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs

@ -71,7 +71,7 @@ namespace ImageSharp.Tests.Drawing
{ {
Assert.Equal(Color.HotPink, sourcePixels[11, 11]); Assert.Equal(Color.HotPink, sourcePixels[11, 11]);
Assert.Equal(Color.HotPink, sourcePixels[199, 150]); Assert.Equal(Color.HotPink, sourcePixels[199, 150]);
Assert.Equal(Color.HotPink, sourcePixels[50, 50]); Assert.Equal(Color.HotPink, sourcePixels[50, 50]);
@ -144,14 +144,14 @@ namespace ImageSharp.Tests.Drawing
public void ImageShouldBeOverlayedByFilledRectangle() public void ImageShouldBeOverlayedByFilledRectangle()
{ {
string path = this.CreateOutputDirectory("Drawing", "FilledPolygons"); string path = this.CreateOutputDirectory("Drawing", "FilledPolygons");
using (Image image = new Image(500, 500)) using (Image image = new Image(500, 500))
{ {
using (FileStream output = File.OpenWrite($"{path}/Rectangle.png")) using (FileStream output = File.OpenWrite($"{path}/Rectangle.png"))
{ {
image image
.BackgroundColor(Color.Blue) .BackgroundColor(Color.Blue)
.Fill(Color.HotPink, new SixLabors.Shapes.Rectangle(10,10, 190, 140)) .Fill(Color.HotPink, new SixLabors.Shapes.Rectangle(10,10, 190, 140))
.Save(output); .Save(output);
} }

Loading…
Cancel
Save