-- ***************************************************************************** -- Geometric Functions -- ***************************************************************************** --adjust point to the discretized grid used by the minimum path algorithm function Adjust(x1,y1) local x2,y2 local Ximg,Yimg,Xdim,Ydim,xOrg,yOrg local R R = Saaap.Project.r Ximg = Saaap.Project.Dimension.w Yimg = Saaap.Project.Dimension.h Xdim = floor((Ximg-1)/R+1); Ydim = floor((Yimg-1)/R+1); xOrg = floor((Ximg - R*(Xdim-1)-1)/2); yOrg = floor((Yimg - R*(Ydim-1)-1)/2); x1 = floor((x1 - xOrg)/R); y1 = floor((y1 - yOrg)/R); if (x1<0) then x1=0 end if (x1>Xdim-1) then x1=Xdim-1 end if (y1<0) then y1=0 end if (y1>Ydim-1) then y1=Ydim-1 end x2 = floor(xOrg + R*x1) y2 = floor(yOrg + R*y1) return x2,y2 end function CalculateScale(imageWidth,imageHeight,mapWidth,mapHeight) local sx,sy sx = mapWidth/imageWidth sy = mapHeight/imageHeight return sx,sy end function Dist(x0,y0,x1,y1) local dist = sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0)) return dist end function IsEqual(x0,y0,x1,y1) local ok = 0 if (Dist(x0,y0,x1,y1)<(2/Saaap.Project.ratio)) then ok = 1 end return ok end -- path pick functions function isOnLine(x,y,x0,y0,x1,y1) local picked = 0 local a,b,c local dist,lengh local t = {} t.x = x1-x0 t.y = y1-y0 lengh = sqrt(t.x*t.x+t.y*t.y) a = t.y/lengh b = -t.x/lengh c = -(a*x1+b*y1) dist = a*x+b*y+c if (abs(dist)<(Saaap.Project.PickTol/Saaap.Project.ratio)) then -- if (abs(dist)<(Saaap.Project.PickTol)) then local dx = x1-x0 local dy = y1-y0 local tol if (abs(dx)>abs(dy)) then ld = (x-x0)/dx -- tol = abs((Saaap.Project.PickTol)/dx) tol = abs((Saaap.Project.PickTol/Saaap.Project.ratio)/dx) else ld = (y-y0)/dy -- tol = abs((Saaap.Project.PickTol)/dy) tol = abs((Saaap.Project.PickTol/Saaap.Project.ratio)/dy) end -- print("dx "..dx) -- print("dy "..dy) -- print("tol"..tol) -- print("ok") if (ld>=(-tol)) and (ld<=(1+tol)) then picked = 1 end end return picked end function PickPath(x,y,path) local pck = 0 local ok = 0 local i = 0 local x0,y0,x1,y1 i=1 while (i