/// <summary> /// 在轮廓中查找keyPoint /// </summary> /// <returns></returns> public bool FindKeyPoint(RLEGridMap grid, ref Float2 keyPoint) { if (grid == null) { return(false); } Polygon2D poly = new Polygon2D(pts.ToArray()); Double2 lb = poly.leftBottom; Double2 ru = poly.rightUp; Short2 slb = grid.GetIndex(lb) + Short2.one; Short2 sru = grid.GetIndex(ru) - Short2.one; for (int x = slb.x; x < sru.x; x++) { double xpos = x * (double)grid.TileSize; Double2 yminPos1 = Double2.zero; Double2 ymaxPos2 = Double2.zero; if (poly.GetPointsInAreabyXaixs(xpos, 1.0f, ref yminPos1, ref ymaxPos2) == true) { int ymin = (int)(yminPos1.y / grid.TileSize); int ymax = (int)(ymaxPos2.y / grid.TileSize); if (grid.CheckXDirHaveBlock(x, ymin, ymax) == true) { keyPoint = new Float2(x * grid.TileSize, ymax * grid.TileSize); return(true); } } } return(false); }
/// <summary> /// 获取轮廓起点及轮廓挡格起点 /// </summary> /// <param name="ContourStartPoint">轮廓起点</param> /// <param name="ContourStartBlockPoint">轮廓挡格起点</param> /// <param name="startSearchPoint">悬针搜索点</param> /// <param name="grid"></param> /// <returns></returns> public bool GetStartingPoint(ref Short2 ContourStartPoint, ref Short2 ContourStartBlockPoint, Float2 startSearchPoint, RLEGridMap grid) { Short2 center = grid.GetIndex(startSearchPoint); if (grid.CheckInMap(center) == false) { return(false); } for (int j = 0; j <= center.y; j++) { if (grid.CheckBlock(center - new Short2(0, j)) == true) { ContourStartPoint = center - new Short2(0, j - 1); ContourStartBlockPoint = center - new Short2(0, j); return(true); } } return(false); }