Skip to content

Commit 97e3457

Browse files
Make Distance(PointF point) internal
1 parent fa58c22 commit 97e3457

9 files changed

Lines changed: 32 additions & 35 deletions

File tree

src/ImageSharp.Drawing/Shapes/ComplexPolygon.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,26 +125,29 @@ public ComplexPolygon(params IPath[] paths)
125125
/// <inheritdoc/>
126126
int IPathInternals.MaxIntersections => this.maxIntersections;
127127

128-
/// <summary>
129-
/// The distance of the point from the outline of the shape, if the value is negative it is inside the polygon bounds
130-
/// </summary>
131-
/// <param name="point">The point.</param>
132-
/// <returns>
133-
/// Returns the distance from thr shape to the point
134-
/// </returns>
128+
/// <inheritdoc/>
135129
/// <remarks>
136-
/// Due to the clipping we did during construction we know that out shapes do not overlap at there edges
130+
/// Due to the clipping we did during construction we know that out shapes do not overlap at their edges
137131
/// therefore for a point to be in more that one we must be in a hole of another, theoretically this could
138132
/// then flip again to be in a outline inside a hole inside an outline :)
139133
/// </remarks>
140-
public PointInfo Distance(PointF point)
134+
PointInfo IPathInternals.Distance(PointF point)
141135
{
142136
float dist = float.MaxValue;
143137
PointInfo pointInfo = default;
144138
bool inside = false;
145139
foreach (IPath shape in this.Paths)
146140
{
147-
PointInfo d = shape.Distance(point);
141+
PointInfo d;
142+
if (shape is IPathInternals internals)
143+
{
144+
d = internals.Distance(point);
145+
}
146+
else
147+
{
148+
// TODO: How can I solve this?
149+
throw new NotImplementedException();
150+
}
148151

149152
if (d.DistanceFromPath <= 0)
150153
{

src/ImageSharp.Drawing/Shapes/EllipsePolygon.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private EllipsePolygon(CubicBezierLineSegment segment)
9191
public float Length => this.innerPath.Length;
9292

9393
/// <inheritdoc />
94-
public PointInfo Distance(PointF point)
94+
PointInfo IPathInternals.Distance(PointF point)
9595
{
9696
PointInfo dist = this.innerPath.DistanceFromPath(point);
9797
bool isInside = this.innerPath.PointInPolygon(point);

src/ImageSharp.Drawing/Shapes/IPath.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@ public interface IPath
2626
/// </summary>
2727
float Length { get; }
2828

29-
/// <summary>
30-
/// Calculates the distance along and away from the path for a specified point.
31-
/// </summary>
32-
/// <param name="point">The point along the path.</param>
33-
/// <returns>
34-
/// Returns details about the point and its distance away from the path.
35-
/// </returns>
36-
PointInfo Distance(PointF point);
37-
3829
/// <summary>
3930
/// Converts the <see cref="IPath" /> into a simple linear path.
4031
/// </summary>

src/ImageSharp.Drawing/Shapes/IPathInternals.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ int FindIntersections(
5353
Span<PointOrientation> orientations,
5454
IntersectionRule intersectionRule);
5555

56+
/// <summary>
57+
/// Calculates the distance along and away from the path for a specified point.
58+
/// </summary>
59+
/// <param name="point">The point along the path.</param>
60+
/// <returns>
61+
/// Returns details about the point and its distance away from the path.
62+
/// </returns>
63+
PointInfo Distance(PointF point);
64+
5665
/// <summary>
5766
/// Returns information about a point at a given distance along a path.
5867
/// </summary>

src/ImageSharp.Drawing/Shapes/Path.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public Path(params ILineSegment[] segments)
8989
this.innerPath ??= new InternalPath(this.lineSegments, this.IsClosed, this.RemoveCloseAndCollinearPoints);
9090

9191
/// <inheritdoc />
92-
public PointInfo Distance(PointF point)
92+
PointInfo IPathInternals.Distance(PointF point)
9393
{
9494
PointInfo dist = this.InnerPath.DistanceFromPath(point);
9595

src/ImageSharp.Drawing/Shapes/RectangularPolygon.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,8 @@ SegmentInfo IPathInternals.PointAlongPath(float distance)
307307
}
308308
}
309309

310-
/// <summary>
311-
/// Calculates the distance along and away from the path for a specified point.
312-
/// </summary>
313-
/// <param name="point">The point along the path.</param>
314-
/// <returns>
315-
/// Returns details about the point and its distance away from the path.
316-
/// </returns>
317-
public PointInfo Distance(PointF point)
310+
/// <inheritdoc/>
311+
PointInfo IPathInternals.Distance(PointF point)
318312
{
319313
Vector2 vectorPoint = point;
320314

tests/ImageSharp.Drawing.Tests/Shapes/PathTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Six Labors.
1+
// Copyright (c) Six Labors.
22
// Licensed under the Apache License, Version 2.0.
33

44
using System.Linq;
@@ -56,7 +56,7 @@ public void Bounds()
5656
[MemberData(nameof(PathDistanceTheoryData))]
5757
public void DistanceFromPath_Path(TestPoint point, float expectedDistance, float alongPath)
5858
{
59-
var path = new Path(new LinearLineSegment(new PointF(0, 0), new PointF(10, 0), new PointF(10, 10), new PointF(0, 10)));
59+
IPathInternals path = new Path(new LinearLineSegment(new PointF(0, 0), new PointF(10, 0), new PointF(10, 10), new PointF(0, 10)));
6060
PointInfo info = path.Distance(point);
6161
Assert.Equal(expectedDistance, info.DistanceFromPath);
6262
Assert.Equal(alongPath, info.DistanceAlongPath);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public void PointInPolygon(TestPoint[] controlPoints, TestPoint point, bool isIn
6969
[MemberData(nameof(DistanceTheoryData))]
7070
public void Distance(TestPoint[] controlPoints, TestPoint point, float expected)
7171
{
72-
var shape = new Polygon(new LinearLineSegment(controlPoints.Select(x => (PointF)x).ToArray()));
72+
IPathInternals shape = new Polygon(new LinearLineSegment(controlPoints.Select(x => (PointF)x).ToArray()));
7373
Assert.Equal(expected, shape.Distance(point).DistanceFromPath);
7474
}
7575

@@ -104,7 +104,7 @@ public void Distance(TestPoint[] controlPoints, TestPoint point, float expected)
104104
[MemberData(nameof(PathDistanceTheoryData))]
105105
public void DistanceFromPath_Path(TestPoint point, float expectedDistance, float alongPath)
106106
{
107-
IPath path = new Polygon(new LinearLineSegment(new PointF(0, 0), new PointF(10, 0), new PointF(10, 10), new PointF(0, 10)));
107+
IPathInternals path = new Polygon(new LinearLineSegment(new PointF(0, 0), new PointF(10, 0), new PointF(10, 10), new PointF(0, 10)));
108108
PointInfo info = path.Distance(point);
109109
Assert.Equal(expectedDistance, info.DistanceFromPath);
110110
Assert.Equal(alongPath, info.DistanceAlongPath);

tests/ImageSharp.Drawing.Tests/Shapes/RectangleTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void PointInPolygon(TestPoint location, TestSize size, TestPoint point, b
112112
[MemberData(nameof(DistanceTheoryData))]
113113
public void Distance(TestPoint location, TestSize size, TestPoint point, float expectecDistance)
114114
{
115-
IPath shape = new RectangularPolygon(location, size);
115+
IPathInternals shape = new RectangularPolygon(location, size);
116116

117117
Assert.Equal(expectecDistance, shape.Distance(point).DistanceFromPath);
118118
}
@@ -121,7 +121,7 @@ public void Distance(TestPoint location, TestSize size, TestPoint point, float e
121121
[MemberData(nameof(PathDistanceTheoryData))]
122122
public void DistanceFromPath_Path(TestPoint point, float expectecDistance, float alongPath)
123123
{
124-
IPath shape = new RectangularPolygon(0, 0, 10, 10);
124+
IPathInternals shape = new RectangularPolygon(0, 0, 10, 10);
125125
PointInfo info = shape.Distance(point);
126126
Assert.Equal(expectecDistance, info.DistanceFromPath);
127127
Assert.Equal(alongPath, info.DistanceAlongPath);

0 commit comments

Comments
 (0)