diff --git a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Clustering.cs b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Clustering.cs index 044e7373..4c03b29a 100644 --- a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Clustering.cs +++ b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Clustering.cs @@ -197,7 +197,7 @@ if (filterPivot(pivot)) { - int index = Distances.FindIndexNearest(pivot, elements, candidatesLine, pivotLine, distMeasure, out double dist); + int index = Distances.FindIndexNearest(pivot, elements, pivotLine, candidatesLine, distMeasure, out double dist); if (index != -1) { diff --git a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Distances.cs b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Distances.cs index 2222a940..f019facb 100644 --- a/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Distances.cs +++ b/src/UglyToad.PdfPig.DocumentLayoutAnalysis/Distances.cs @@ -149,32 +149,32 @@ /// /// The reference point, for which to find the nearest neighbour. /// The list of neighbours candidates. - /// /// + /// /// The distance measure to use. - /// The distance between reference point, and its nearest neighbour. + /// The distance between the reference element and its nearest neighbour. public static int FindIndexNearest(T element, IReadOnlyList candidates, - Func candidatesPoint, Func pivotPoint, + Func pivotPoint, Func candidatePoint, Func distanceMeasure, out double distance) { if (candidates == null || candidates.Count == 0) { - throw new ArgumentException("Distances.FindIndexNearest(): The list of neighbours candidates is either null or empty.", "points"); + throw new ArgumentException("Distances.FindIndexNearest(): The list of neighbours candidates is either null or empty.", nameof(candidates)); } if (distanceMeasure == null) { - throw new ArgumentException("Distances.FindIndexNearest(): The distance measure must not be null.", "distanceMeasure"); + throw new ArgumentException("Distances.FindIndexNearest(): The distance measure must not be null.", nameof(distanceMeasure)); } distance = double.MaxValue; int closestPointIndex = -1; - var candidatesPoints = candidates.Select(candidatesPoint).ToList(); + var candidatesPoints = candidates.Select(candidatePoint).ToList(); var pivot = pivotPoint(element); for (var i = 0; i < candidates.Count; i++) { - double currentDistance = distanceMeasure(candidatesPoints[i], pivot); + double currentDistance = distanceMeasure(pivot, candidatesPoints[i]); if (currentDistance < distance && !candidates[i].Equals(element)) { distance = currentDistance; @@ -191,32 +191,32 @@ /// /// The reference line, for which to find the nearest neighbour. /// The list of neighbours candidates. - /// /// + /// /// The distance measure between two lines to use. - /// The distance between reference line, and its nearest neighbour. + /// The distance between the reference element and its nearest neighbour. public static int FindIndexNearest(T element, IReadOnlyList candidates, - Func candidatesLine, Func pivotLine, + Func pivotLine, Func candidateLine, Func distanceMeasure, out double distance) { if (candidates == null || candidates.Count == 0) { - throw new ArgumentException("Distances.FindIndexNearest(): The list of neighbours candidates is either null or empty.", "lines"); + throw new ArgumentException("Distances.FindIndexNearest(): The list of neighbours candidates is either null or empty.", nameof(candidates)); } if (distanceMeasure == null) { - throw new ArgumentException("Distances.FindIndexNearest(): The distance measure must not be null.", "distanceMeasure"); + throw new ArgumentException("Distances.FindIndexNearest(): The distance measure must not be null.", nameof(distanceMeasure)); } distance = double.MaxValue; int closestLineIndex = -1; - var candidatesLines = candidates.Select(candidatesLine).ToList(); + var candidatesLines = candidates.Select(candidateLine).ToList(); var pivot = pivotLine(element); for (var i = 0; i < candidates.Count; i++) { - double currentDistance = distanceMeasure(candidatesLines[i], pivot); + double currentDistance = distanceMeasure(pivot, candidatesLines[i]); if (currentDistance < distance && !candidates[i].Equals(element)) { distance = currentDistance;