From e61cb2285f33656ebeafd76e0cd7f74f0f2dd965 Mon Sep 17 00:00:00 2001 From: Retro-Junk Date: Sat, 1 Oct 2016 15:03:00 +0300 Subject: FULLPIPE: Fix MctlGraph::getNearestLink --- engines/fullpipe/motion.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/fullpipe') diff --git a/engines/fullpipe/motion.cpp b/engines/fullpipe/motion.cpp index 744032353e..331799f9b5 100644 --- a/engines/fullpipe/motion.cpp +++ b/engines/fullpipe/motion.cpp @@ -2735,16 +2735,16 @@ MovGraphLink *MctlGraph::getNearestLink(int x, int y) { double n1y = lnk->_graphSrc->_y; double n2x = lnk->_graphDst->_x; double n2y = lnk->_graphDst->_y; - double n1dx = n1x - x; + double n1dx = x - n1x; double n1dy = n1y - y; double dst1 = sqrt(n1dy * n1dy + n1dx * n1dx); double coeff1 = ((n1y - n2y) * n1dy + (n2x - n1x) * n1dx) / lnk->_length / dst1; double dst3 = coeff1 * dst1; double dst2 = sqrt(1.0 - coeff1 * coeff1) * dst1; - if (coeff1 * dst1 < 0.0) { + if (dst3 < 0.0) { dst3 = 0.0; - dst2 = sqrt(n1dy * n1dy + n1dx * n1dx); + dst2 = sqrt((n1x - x) * (n1x - x) + (n1y - y) * (n1y - y)); } if (dst3 > lnk->_length) { dst3 = lnk->_length; -- cgit v1.2.3