long GridWndMover_c::GetVelocityIndex(WorldPoint p) { long rowNum, colNum; VelocityRec velocity; LongRect gridLRect, geoRect; ScaleRec thisScaleRec; TRectGridVel* rectGrid = (TRectGridVel*)fGrid; // fNumRows, fNumCols members of GridWndMover WorldRect bounds = rectGrid->GetBounds(); SetLRect (&gridLRect, 0, fNumRows, fNumCols, 0); SetLRect (&geoRect, bounds.loLong, bounds.loLat, bounds.hiLong, bounds.hiLat); GetLScaleAndOffsets (&geoRect, &gridLRect, &thisScaleRec); colNum = p.pLong * thisScaleRec.XScale + thisScaleRec.XOffset; rowNum = p.pLat * thisScaleRec.YScale + thisScaleRec.YOffset; if (colNum < 0 || colNum >= fNumCols || rowNum < 0 || rowNum >= fNumRows) { return -1; } return rowNum * fNumCols + colNum; }
VelocityRec RectGridVel_c::GetPatValue(WorldPoint p) { long rowNum, colNum; VelocityRec velocity; LongRect gridLRect, geoRect; ScaleRec thisScaleRec; SetLRect(&gridLRect, 0, fNumRows, fNumCols, 0); SetLRect(&geoRect, fGridBounds.loLong, fGridBounds.loLat, fGridBounds.hiLong, fGridBounds.hiLat); GetLScaleAndOffsets(&geoRect, &gridLRect, &thisScaleRec); // gridP = WorldToScreenPoint(p, bounds, CATSgridRect); colNum = (long)(p.pLong * thisScaleRec.XScale + thisScaleRec.XOffset); rowNum = (long)(p.pLat * thisScaleRec.YScale + thisScaleRec.YOffset); if (!fGridHdl || colNum < 0 || colNum >= fNumCols || rowNum < 0 || rowNum >= fNumRows) { velocity.u = 0.0; velocity.v = 0.0; return velocity; } return INDEXH(fGridHdl, rowNum * fNumCols + colNum); }
VelocityRec RectGridVel_c::GetSmoothVelocity(WorldPoint p) { long rowNum, colNum; VelocityRec velocity, velNew; LongRect gridLRect, geoRect; ScaleRec thisScaleRec; SetLRect(&gridLRect, 0, fNumRows, fNumCols, 0); SetLRect(&geoRect, fGridBounds.loLong, fGridBounds.loLat, fGridBounds.hiLong, fGridBounds.hiLat); GetLScaleAndOffsets(&geoRect, &gridLRect, &thisScaleRec); colNum = (long)(p.pLong * thisScaleRec.XScale + thisScaleRec.XOffset); rowNum = (long)(p.pLat * thisScaleRec.YScale + thisScaleRec.YOffset); velocity = GetPatValue(p); if (colNum > 0 && colNum < fNumCols - 1 && rowNum > 0 && rowNum < fNumRows - 1) { VelocityRec topV, leftV, bottomV, rightV; topV = INDEXH (fGridHdl, rowNum + 1 * fNumCols + colNum); bottomV = INDEXH (fGridHdl, rowNum - 1 * fNumCols + colNum); leftV = INDEXH (fGridHdl, rowNum * fNumCols + colNum - 1); rightV = INDEXH (fGridHdl, rowNum * fNumCols + colNum + 1); velNew.u = .5 * velocity.u + .125 * (topV.u + bottomV.u + leftV.u + rightV.u); velNew.v = .5 * velocity.v + .125 * (topV.v + bottomV.v + leftV.v + rightV.v); } else velNew = velocity; return velNew; }