Browse Source

reduce calls

pull/98/head
Scott Williams 9 years ago
parent
commit
2f8f8bd2c5
  1. 27
      src/ImageSharp.Drawing.Paths/PointInfoExtensions.cs
  2. 16
      src/ImageSharp.Drawing.Paths/ShapePath.cs

27
src/ImageSharp.Drawing.Paths/PointInfoExtensions.cs

@ -1,27 +0,0 @@
// <copyright file="PointInfoExtensions.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Drawing
{
/// <summary>
/// Extension methods for helping to bridge Shaper2D and ImageSharp primitives.
/// </summary>
internal static class PointInfoExtensions
{
/// <summary>
/// Converts a <see cref="SixLabors.Shapes.PointInfo"/> to an ImageSharp <see cref="PointInfo"/>.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <returns>A <see cref="PointInfo"/> representation of this <see cref="SixLabors.Shapes.PointInfo"/></returns>
public static PointInfo Convert(this SixLabors.Shapes.PointInfo source)
{
return new PointInfo
{
DistanceAlongPath = source.DistanceAlongPath,
DistanceFromPath = source.DistanceFromPath
};
}
}
}

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

@ -130,20 +130,24 @@ namespace ImageSharp.Drawing
public override PointInfo GetPointInfo(int x, int y) public override PointInfo GetPointInfo(int x, int y)
{ {
Vector2 point = new Vector2(x, y); Vector2 point = new Vector2(x, y);
SixLabors.Shapes.PointInfo result = default(SixLabors.Shapes.PointInfo); float distanceFromPath = float.MaxValue;
float distance = float.MaxValue; float distanceAlongPath = 0;
for (int i = 0; i < this.Paths.Length; i++) for (int i = 0; i < this.Paths.Length; i++)
{ {
SixLabors.Shapes.PointInfo p = this.Paths[i].Distance(point); SixLabors.Shapes.PointInfo p = this.Paths[i].Distance(point);
if (p.DistanceFromPath < distance) if (p.DistanceFromPath < distanceFromPath)
{ {
distance = p.DistanceFromPath; distanceFromPath = p.DistanceFromPath;
result = p; distanceAlongPath = p.DistanceAlongPath;
} }
} }
return result.Convert(); return new PointInfo
{
DistanceAlongPath = distanceAlongPath,
DistanceFromPath = distanceFromPath
};
} }
} }
} }

Loading…
Cancel
Save