MCPcopy Create free account
hub / github.com/NetHack/NetHack / line_dist_coord

Function line_dist_coord

src/selvar.c:541–566  ·  view source on GitHub ↗

square of distance from line segment (x1,y1, x2,y2) to point (x3,y3) */

Source from the content-addressed store, hash-verified

539
540/* square of distance from line segment (x1,y1, x2,y2) to point (x3,y3) */
541staticfn long
542line_dist_coord(long x1, long y1, long x2, long y2, long x3, long y3)
543{
544 long px = x2 - x1;
545 long py = y2 - y1;
546 long s = px * px + py * py;
547 long x, y, dx, dy, distsq = 0;
548 float lu = 0;
549
550 if (x1 == x2 && y1 == y2)
551 return dist2(x1, y1, x3, y3);
552
553 lu = ((x3 - x1) * px + (y3 - y1) * py) / (float) s;
554 if (lu > 1)
555 lu = 1;
556 else if (lu < 0)
557 lu = 0;
558
559 x = x1 + lu * px;
560 y = y1 + lu * py;
561 dx = x - x3;
562 dy = y - y3;
563 distsq = dx * dx + dy * dy;
564
565 return distsq;
566}
567
568/* guts of l_selection_gradient */
569void

Callers 1

selection_do_gradientFunction · 0.85

Calls 1

dist2Function · 0.85

Tested by

no test coverage detected