Skip to content

Commit dd9bf54

Browse files
committed
algo(geometry): change from sqrt to hypot
1 parent 388c706 commit dd9bf54

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

algorithms/geometry/point-to-segment.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
typedef pair<double, double> pdb;
22

3-
#define fst first
4-
#define snd second
5-
63
double pt2segment(pdb A, pdb B, pdb E) {
74
pdb AB = {B.fst - A.fst, B.snd - A.snd};
85
pdb BE = {E.fst - B.fst, E.snd - B.snd};
@@ -15,15 +12,15 @@ double pt2segment(pdb A, pdb B, pdb E) {
1512
if (AB_BE > 0) {
1613
double y = E.snd - B.snd;
1714
double x = E.fst - B.fst;
18-
ans = sqrt(x * x + y * y);
15+
ans = hypot(x, y);
1916
} else if (AB_AE < 0) {
2017
double y = E.snd - A.snd;
2118
double x = E.fst - A.fst;
22-
ans = sqrt(x * x + y * y);
19+
ans = hypot(x, y);
2320
} else {
2421
auto [x1, y1] = AB;
2522
auto [x2, y2] = AE;
26-
double mod = sqrt(x1 * x1 + y1 * y1);
23+
double mod = hypot(x1, y1);
2724
ans = abs(x1 * y2 - y1 * x2) / mod;
2825
}
2926

0 commit comments

Comments
 (0)