Browse Source

some cleanup

pull/98/head
Scott Williams 10 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. 1
      tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.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)

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

@ -132,7 +132,6 @@ namespace ImageSharp.Tests.Drawing
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))
{ {
using (FileStream output = File.OpenWrite($"{path}/SimpleOverlapping.png")) using (FileStream output = File.OpenWrite($"{path}/SimpleOverlapping.png"))

Loading…
Cancel
Save