Skip to content

Commit 47e5e12

Browse files
Delete IPath.Length
1 parent f27a95a commit 47e5e12

7 files changed

Lines changed: 10 additions & 36 deletions

File tree

src/ImageSharp.Drawing/Shapes/ComplexPolygon.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public sealed class ComplexPolygon : IPath, IPathInternals, IInternalPathOwner
2020
private readonly IPath[] paths;
2121
private readonly List<InternalPath> internalPaths;
2222
private readonly int maxIntersections;
23+
private readonly float length;
2324

2425
/// <summary>
2526
/// Initializes a new instance of the <see cref="ComplexPolygon" /> class.
@@ -52,7 +53,6 @@ public ComplexPolygon(params IPath[] paths)
5253

5354
foreach (IPath p in this.paths)
5455
{
55-
length += p.Length;
5656
if (p.Bounds.Left < minX)
5757
{
5858
minX = p.Bounds.Left;
@@ -77,30 +77,25 @@ public ComplexPolygon(params IPath[] paths)
7777
{
7878
var ip = new InternalPath(s.Points, s.IsClosed);
7979
intersections += ip.PointCount;
80-
80+
length += ip.Length;
8181
this.internalPaths.Add(ip);
8282
}
8383
}
8484

8585
this.maxIntersections = intersections;
86-
this.Length = length;
86+
this.length = length;
8787
this.Bounds = new RectangleF(minX, minY, maxX - minX, maxY - minY);
8888
}
8989
else
9090
{
9191
this.maxIntersections = 0;
92-
this.Length = 0;
92+
this.length = 0;
9393
this.Bounds = RectangleF.Empty;
9494
}
9595

9696
this.PathType = PathTypes.Mixed;
9797
}
9898

99-
/// <summary>
100-
/// Gets the length of the path.
101-
/// </summary>
102-
public float Length { get; }
103-
10499
/// <summary>
105100
/// Gets a value indicating whether this instance is closed, open or a composite path with a mixture of open and closed figures.
106101
/// </summary>
@@ -271,7 +266,7 @@ public IPath AsClosedPath()
271266
/// </returns>
272267
SegmentInfo IPathInternals.PointAlongPath(float distance)
273268
{
274-
distance %= this.Length;
269+
distance %= this.length;
275270
foreach (InternalPath p in this.internalPaths)
276271
{
277272
if (p.Length >= distance)

src/ImageSharp.Drawing/Shapes/EllipsePolygon.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,8 @@ private EllipsePolygon(CubicBezierLineSegment segment)
8282
/// </summary>
8383
PathTypes IPath.PathType => PathTypes.Closed;
8484

85-
/// <summary>
86-
/// Gets the maximum number intersections that a shape can have when testing a line.
87-
/// </summary>
88-
int IPathInternals.MaxIntersections => this.innerPath.PointCount;
89-
9085
/// <inheritdoc />
91-
public float Length => this.innerPath.Length;
86+
int IPathInternals.MaxIntersections => this.innerPath.PointCount;
9287

9388
/// <summary>
9489
/// Transforms the rectangle using specified matrix.

src/ImageSharp.Drawing/Shapes/IPath.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,18 @@ public interface IPath
2121
/// </summary>
2222
RectangleF Bounds { get; }
2323

24-
/// <summary>
25-
/// Gets the length of the path.
26-
/// </summary>
27-
float Length { get; }
28-
2924
/// <summary>
3025
/// Converts the <see cref="IPath" /> into a simple linear path.
3126
/// </summary>
3227
/// <returns>Returns the current <see cref="IPath" /> as simple linear path.</returns>
3328
IEnumerable<ISimplePath> Flatten();
3429

3530
/// <summary>
36-
/// Determines whether the <see cref="IPath"/> contains the specified point
31+
/// Determines whether the <see cref="IPath"/> contains the specified point.
3732
/// </summary>
3833
/// <param name="point">The point.</param>
3934
/// <returns>
40-
/// <c>true</c> if the <see cref="IPath"/> contains the specified point; otherwise, <c>false</c>.
35+
/// <see langword="true"/> if the <see cref="IPath"/> contains the specified point; otherwise, <see langword="false"/>.
4136
/// </returns>
4237
bool Contains(PointF point);
4338

src/ImageSharp.Drawing/Shapes/ISimplePath.cs

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

44
using System;
5-
using System.Collections.Generic;
65

76
namespace SixLabors.ImageSharp.Drawing
87
{
@@ -21,4 +20,4 @@ public interface ISimplePath
2120
/// </summary>
2221
ReadOnlyMemory<PointF> Points { get; }
2322
}
24-
}
23+
}

src/ImageSharp.Drawing/Shapes/Path.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ public Path(Path path)
4242
public Path(params ILineSegment[] segments)
4343
=> this.lineSegments = segments ?? throw new ArgumentNullException(nameof(segments));
4444

45-
/// <summary>
46-
/// Gets the length of the path.
47-
/// </summary>
48-
public float Length => this.InnerPath.Length;
49-
5045
/// <summary>
5146
/// Gets a value indicating whether this instance is a closed path.
5247
/// </summary>

src/ImageSharp.Drawing/Shapes/RectangularPolygon.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,6 @@ public RectangularPolygon(RectangleF rectangle)
124124
/// </summary>
125125
RectangleF IPath.Bounds => this.bounds;
126126

127-
/// <inheritdoc />
128-
float IPath.Length => this.length;
129-
130127
/// <inheritdoc/>
131128
int IPathInternals.MaxIntersections => 4;
132129

tests/ImageSharp.Drawing.Tests/Drawing/Paths/ShapeRegionTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ public abstract class MockPath : IPath, IPathInternals
2929

3030
public abstract int MaxIntersections { get; }
3131

32-
public abstract float Length { get; }
33-
3432
public int FindIntersections(PointF start, PointF end, Span<PointF> intersections, Span<PointOrientation> orientations)
3533
=> this.FindIntersections(start, end, intersections, orientations, IntersectionRule.OddEven);
3634

0 commit comments

Comments
 (0)