//------------------------------------------------------------------------- public bool Pick(Int32 fromX, Int32 fromY, Int32 destX, Int32 destY, float value, ref ViPixelNavigatePickData result) { Int32 deltaX = destX - fromX; Int32 deltaY = destY - fromY; if (deltaX == 0 && deltaY == 0) { return(false); } float absDeltaX = Math.Abs((float)deltaX); float absDeltaY = Math.Abs((float)deltaY); if (absDeltaX >= absDeltaY) { if (deltaX < 0) { return(_PickXNegative(fromX, fromY, destX, destY, value, ref result)); } else { return(_PickXPositive(fromX, fromY, destX, destY, value, ref result)); } } else { if (deltaY < 0) { return(_PickYNegative(fromX, fromY, destX, destY, value, ref result)); } else { return(_PickYPositive(fromX, fromY, destX, destY, value, ref result)); } } }
//------------------------------------------------------------------------- bool _PickYPositive(Int32 fromX, Int32 fromY, Int32 destX, Int32 destY, float value, ref ViPixelNavigatePickData result) { Int32 deltaX = destX - fromX; Int32 deltaY = destY - fromY; float fromCenterX = (float)fromX + 0.5f; float fromCenterY = (float)fromY + 0.5f; float fDeltaX = (float)deltaX / Math.Abs((float)deltaY); float fDeltaY = 1.0f; float pickX = fromCenterX; float pickY = fromCenterY; for (Int32 idx = fromY; idx < destY; ++idx) { pickX += fDeltaX; pickY += fDeltaY; Int32 newCellX = (Int32)pickX; Int32 newCellY = (Int32)pickY; if (_steps[newCellX + newCellY * _sizeX].Cost == value) { result.blockX = newCellX; result.blockY = newCellY; result.lastFreeX = (Int32)(pickX - fDeltaX); result.lastFreeY = (Int32)(pickY - fDeltaY); return(true); } } if (_steps[destX + destY * _sizeX].Cost == value) { result.blockX = destX; result.blockY = destY; result.lastFreeX = (Int32)(pickX); result.lastFreeY = (Int32)(pickY); return(true); } return(false); }
//------------------------------------------------------------------------- public bool Pick(Int32 fromX, Int32 fromY, Int32 destX, Int32 destY) { ViPixelNavigatePickData data = new ViPixelNavigatePickData(); return(Pick(fromX, fromY, destX, destY, 1.0f, ref data)); }