@@ -42,12 +42,14 @@ Iterable<String> prepareRanges(List<VersionRangeCount> rangeDownloads) {
4242 return (ranges: ranges, weekLists: result.reversed.toList ());
4343}
4444
45- /// Calculates closest point from [point] to line defined by [startPoint] and
46- /// [endPoint] .
45+ /// Calculates the closest point on the line segment between [startPoint]
46+ /// and [endPoint] to a given [point ] .
4747///
48- /// This assumes that the closest point is on the line, that is within the
49- /// two endpoints. Returns `(double.maxFinite, double.maxFinite)` if this is
50- /// not the case.
48+ /// If [startPoint] and [endPoint] are the same, [startPoint] is returned.
49+ ///
50+ /// If [point] is outside the line segment, that is the closest point would not
51+ /// be within the thwo endpoints, `(double.maxFinite, double.maxFinite)`
52+ /// is returned.
5153 (num , num ) closestPointOnLine (
5254 (num , num ) startPoint, (num , num ) endPoint, (num , num ) point) {
5355 final directionVector =
@@ -57,16 +59,15 @@ Iterable<String> prepareRanges(List<VersionRangeCount> rangeDownloads) {
5759 return startPoint;
5860 }
5961
60- final vector = (point.$1 - startPoint.$1, point.$2 - startPoint.$2);
62+ final v = (point.$1 - startPoint.$1, point.$2 - startPoint.$2);
6163
62- // The dot product ((v · d) / (d · d)) where v = vector and d = directionVector
63- final t = ((vector .$1 * directionVector.$1 + vector .$2 * directionVector.$2) /
64+ // The dot product ((v · d) / (d · d))
65+ final t = ((v .$1 * directionVector.$1 + v .$2 * directionVector.$2) /
6466 (directionVector.$1 * directionVector.$1 +
6567 directionVector.$2 * directionVector.$2));
6668
6769 if (t < 0 || t > 1 ) {
68- // Closest point is before or after the line. This should not happen in
69- // our use case.
70+ // Closest point is before or after the line.
7071 return (double .maxFinite, double .maxFinite);
7172 }
7273
0 commit comments