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); }
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; }
OSErr SegmentToRgn (SegmentsHdl theSegment, PolyObjectHdl newPoly) // newPoly must be a polygon without any points added { Boolean DrawFromSegFlag; long SegCount, SegIndex, SegIndexPlus; LongPoint MatrixPt; PolyObjectHdl newPolyHdl = nil; OSErr err = noErr; LongRect emptyLRect; // set region rect to empty to start with SetLRect (&emptyLRect, kWorldRight, kWorldBottom, kWorldLeft, kWorldTop); SegCount = _GetHandleSize ((Handle) theSegment) / sizeof (Segment); if (SegCount > 0) { DrawFromSegFlag = true; for (SegIndex = 0; SegIndex < SegCount; ++SegIndex) { if (DrawFromSegFlag) /* start of new poly */ { /* create a new polygon object */ CreateNewPtsHdl (newPolyHdl, 0); /* mark the newly added polygon */ SetObjectMarked ((ObjectRecHdl) newPolyHdl, true); /* set bounds to empty rect */ SetObjectLRect ((ObjectRecHdl) newPolyHdl, &emptyLRect); if (!err) { MatrixPt.h = (*theSegment) [SegIndex].fromLong; MatrixPt.v = (*theSegment) [SegIndex].fromLat; AddPointToPoly (newPolyHdl, &MatrixPt); DrawFromSegFlag = false; } } MatrixPt.h = (*theSegment) [SegIndex].toLong; MatrixPt.v = (*theSegment) [SegIndex].toLat; AddPointToPoly (newPolyHdl, &MatrixPt); SegIndexPlus = SegIndex + 1; if (SegIndexPlus == SegCount) SegIndexPlus = 0; /* check for end of current poly */ if (((*theSegment) [SegIndex].toLat != (*theSegment) [SegIndexPlus].fromLat || (*theSegment) [SegIndex].toLong != (*theSegment) [SegIndexPlus].fromLong)) { DrawFromSegFlag = true; } } } return err; }
void CalcSetPolyLRect (PolyObjectHdl thePolyHdl) { LongRect ObjectLRect; long PointCount, PointIndex; LongPoint MatrixPt; LongPoint **thisPtsHdl = nil; if (thePolyHdl != nil) { thisPtsHdl = GetPolyPointsHdl (thePolyHdl); PointCount = GetPolyPointCount (thePolyHdl); /* set region rect to empty to start with */ SetLRect (&ObjectLRect, kWorldRight, kWorldBottom, kWorldLeft, kWorldTop); for (PointIndex = 1; PointIndex <= PointCount; ++PointIndex) { MatrixPt = (*thisPtsHdl) [PointIndex - 1]; if (MatrixPt.h < ObjectLRect.left) ObjectLRect.left = MatrixPt.h; if (MatrixPt.v > ObjectLRect.top) ObjectLRect.top = MatrixPt.v; if (MatrixPt.h > ObjectLRect.right) ObjectLRect.right = MatrixPt.h; if (MatrixPt.v < ObjectLRect.bottom) ObjectLRect.bottom = MatrixPt.v; } SetObjectLRect ((ObjectRecHdl) thePolyHdl, &ObjectLRect); } return; }
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; }
void SetObjectLPoint (ObjectRecHdl ObjectHdl, LongPoint *objectLPointPtr) { OSType thisObjectType; (**ObjectHdl).objectLPoint = *objectLPointPtr; GetObjectType (ObjectHdl, &thisObjectType); if (thisObjectType == kSymbolType) { LongRect thisObjectLRect; SetLRect (&thisObjectLRect, objectLPointPtr -> h, objectLPointPtr -> v, objectLPointPtr -> h, objectLPointPtr -> v); SetObjectLRect (ObjectHdl, &thisObjectLRect); } return; }
OSErr IntersectPoly (PolyObjectHdl MainPolyHdl, LongRect *sectLRect, CMyList *theObjectList) { SegmentsHdl SectSegHdl = nil; CMyList *sectPolyList = nil; PolyObjectHdl newPolyHdl = nil; OSErr err = noErr; SectSegHdl = MakeSectPoly (sectLRect, MainPolyHdl); if (SectSegHdl != nil) { Boolean DrawFromSegFlag; long SegCount, SegIndex, SegIndexPlus; LongPoint MatrixPt; LongRect emptyLRect; /* set region rect to empty to start with */ SetLRect (&emptyLRect, kWorldRight, kWorldBottom, kWorldLeft, kWorldTop); SegCount = _GetHandleSize ((Handle) SectSegHdl) / sizeof (Segment); if (SegCount > 0) { DrawFromSegFlag = true; for (SegIndex = 0; SegIndex < SegCount; ++SegIndex) { if (DrawFromSegFlag) /* start of new poly */ { /* create a new polygon object */ newPolyHdl = MainPolyHdl; err = _HandToHand((Handle *) &newPolyHdl); if (!err) /* create new points handle */ { CreateNewPtsHdl (newPolyHdl, 0); /* mark the new polygon */ SetObjectMarked ((ObjectRecHdl) newPolyHdl, true); /* set bounds to empty rect */ SetObjectLRect ((ObjectRecHdl) newPolyHdl, &emptyLRect); /* add polygon to objects list */ theObjectList -> AppendItem ((Ptr) &newPolyHdl); } if (!err) { MatrixPt.h = (*SectSegHdl) [SegIndex].fromLong; MatrixPt.v = (*SectSegHdl) [SegIndex].fromLat; AddPointToPoly (newPolyHdl, &MatrixPt); DrawFromSegFlag = false; } } MatrixPt.h = (*SectSegHdl) [SegIndex].toLong; MatrixPt.v = (*SectSegHdl) [SegIndex].toLat; AddPointToPoly (newPolyHdl, &MatrixPt); SegIndexPlus = SegIndex + 1; if (SegIndexPlus == SegCount) SegIndexPlus = 0; /* check for end of current poly */ if (((*SectSegHdl) [SegIndex].toLat != (*SectSegHdl) [SegIndexPlus].fromLat || (*SectSegHdl) [SegIndex].toLong != (*SectSegHdl) [SegIndexPlus].fromLong)) { DrawFromSegFlag = true; } } } } else err = memFullErr; if (err == memFullErr) TechError ("IntersectPoly()", "Out of memory while intersecting polgons!", err); else if (err) TechError ("IntersectPoly()", "Error while intersecting polygons!", err); return err; }