Skip to content

Commit 7bfabc3

Browse files
Use descriptive parameter names
1 parent 10f1823 commit 7bfabc3

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

geometry/ramer_douglas_peucker.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,48 +28,49 @@
2828
# ---------------------------------------------------------------------------
2929

3030

31-
def _euclidean_distance(a: tuple[float, float], b: tuple[float, float]) -> float:
31+
def _euclidean_distance(
32+
point_1: tuple[float, float], point_2: tuple[float, float]
33+
) -> float:
3234
"""Return the Euclidean distance between two 2-D points.
3335
3436
>>> _euclidean_distance((0.0, 0.0), (3.0, 4.0))
3537
5.0
3638
>>> _euclidean_distance((1.0, 1.0), (1.0, 1.0))
3739
0.0
3840
"""
39-
return math.hypot(b[0] - a[0], b[1] - a[1])
41+
return math.hypot(point_2[0] - point_1[0], point_2[1] - point_1[1])
4042

4143

4244
def _perpendicular_distance(
43-
p: tuple[float, float],
44-
a: tuple[float, float],
45-
b: tuple[float, float],
45+
point: tuple[float, float],
46+
line_start: tuple[float, float],
47+
line_end: tuple[float, float],
4648
) -> float:
47-
"""Return the perpendicular distance from point *p* to the line through *a* and *b*.
49+
"""Return the perpendicular distance from *point* to the line through
50+
*line_start* and *line_end*.
4851
49-
The result is the absolute value of the signed area of the triangle (a, b, p)
50-
divided by the length of segment ab, which equals the altitude of that triangle
51-
from p.
52+
The result is the absolute value of the signed area of the triangle
53+
(line_start, line_end, point) divided by the length of the segment, which
54+
equals the altitude of that triangle from point.
5255
5356
>>> _perpendicular_distance((4.0, 0.0), (0.0, 0.0), (0.0, 3.0))
5457
4.0
55-
>>> _perpendicular_distance((4.0, 0.0), (0.0, 0.0), (0.0, 3.0))
56-
4.0
57-
>>> # order of a and b does not affect the result
58+
>>> # order of line_start and line_end does not affect the result
5859
>>> _perpendicular_distance((4.0, 0.0), (0.0, 3.0), (0.0, 0.0))
5960
4.0
6061
>>> _perpendicular_distance((4.0, 1.0), (0.0, 1.0), (0.0, 4.0))
6162
4.0
6263
>>> _perpendicular_distance((2.0, 1.0), (-2.0, 1.0), (-2.0, 4.0))
6364
4.0
6465
"""
65-
px, py = p
66-
ax, ay = a
67-
bx, by = b
66+
px, py = point
67+
ax, ay = line_start
68+
bx, by = line_end
6869
numerator = abs((by - ay) * px - (bx - ax) * py + bx * ay - by * ax)
69-
denominator = _euclidean_distance(a, b)
70+
denominator = _euclidean_distance(line_start, line_end)
7071
if denominator == 0.0:
71-
# a and b coincide; fall back to point-to-point distance
72-
return _euclidean_distance(p, a)
72+
# line_start and line_end coincide; fall back to point-to-point distance
73+
return _euclidean_distance(point, line_start)
7374
return numerator / denominator
7475

7576

0 commit comments

Comments
 (0)