/// <summary> /// Tries to align the minimap vertically. /// </summary> /// <param name="minimapControlPixelSize">The size of the minimap control in pixels.</param> /// <param name="mapCellSize">The size of the map in cells.</param> /// <param name="minimapPosition">The position of the minimap on the minimap control in pixels.</param> /// <param name="transformation">The transformation between the map (A) and minimap (B) coordinate-systems.</param> /// <returns>True if the alignment was successfully; otherwise false.</returns> private static bool TryAlignMinimapVertically( RCIntVector minimapControlPixelSize, RCIntVector mapCellSize, out RCIntRectangle minimapPosition, out RCCoordTransformation transformation) { RCNumber vertAlignedMinimapWidth = (RCNumber)(minimapControlPixelSize.Y * mapCellSize.X) / (RCNumber)mapCellSize.Y; if (vertAlignedMinimapWidth > minimapControlPixelSize.X) { /// Cannot align vertically. minimapPosition = RCIntRectangle.Undefined; transformation = null; return(false); } /// Align vertically int minimapPixelWidth = vertAlignedMinimapWidth > (int)vertAlignedMinimapWidth ? (int)vertAlignedMinimapWidth + 1 : (int)vertAlignedMinimapWidth; minimapPosition = new RCIntRectangle((minimapControlPixelSize.X - minimapPixelWidth) / 2, 0, minimapPixelWidth, minimapControlPixelSize.Y); /// Create the coordinate transformation RCNumVector pixelSizeOnMap = new RCNumVector((RCNumber)mapCellSize.Y / (RCNumber)minimapControlPixelSize.Y, (RCNumber)mapCellSize.Y / (RCNumber)minimapControlPixelSize.Y); RCNumVector nullVectorOfMinimap = (pixelSizeOnMap / 2) - (new RCNumVector(1, 1) / 2); RCNumVector baseVectorOfMinimapX = new RCNumVector(pixelSizeOnMap.X, 0); RCNumVector baseVectorOfMinimapY = new RCNumVector(0, pixelSizeOnMap.Y); transformation = new RCCoordTransformation(nullVectorOfMinimap, baseVectorOfMinimapX, baseVectorOfMinimapY); return(true); }
/// <summary> /// Tries to align the minimap horizontally. /// </summary> /// <param name="minimapControlPixelSize">The size of the minimap control in pixels.</param> /// <param name="mapCellSize">The size of the map in cells.</param> /// <param name="minimapPosition">The position of the minimap on the minimap control in pixels.</param> /// <param name="transformation">The transformation between the map (A) and minimap (B) coordinate-systems.</param> /// <returns>True if the alignment was successfully; otherwise false.</returns> private static bool TryAlignMinimapHorizontally( RCIntVector minimapControlPixelSize, RCIntVector mapCellSize, out RCIntRectangle minimapPosition, out RCCoordTransformation transformation) { RCNumber horzAlignedMinimapHeight = (RCNumber)(minimapControlPixelSize.X * mapCellSize.Y) / (RCNumber)mapCellSize.X; if (horzAlignedMinimapHeight > minimapControlPixelSize.Y) { /// Cannot align horizontally. minimapPosition = RCIntRectangle.Undefined; transformation = null; return(false); } /// Align horizontally int minimapPixelHeight = horzAlignedMinimapHeight > (int)horzAlignedMinimapHeight ? (int)horzAlignedMinimapHeight + 1 : (int)horzAlignedMinimapHeight; minimapPosition = new RCIntRectangle(0, (minimapControlPixelSize.Y - minimapPixelHeight) / 2, minimapControlPixelSize.X, minimapPixelHeight); /// Create the coordinate transformation RCNumVector pixelSizeOnMap = new RCNumVector((RCNumber)mapCellSize.X / (RCNumber)minimapControlPixelSize.X, (RCNumber)mapCellSize.X / (RCNumber)minimapControlPixelSize.X); RCNumVector nullVectorOfMinimap = (pixelSizeOnMap / 2) - (new RCNumVector(1, 1) / 2); RCNumVector baseVectorOfMinimapX = new RCNumVector(pixelSizeOnMap.X, 0); RCNumVector baseVectorOfMinimapY = new RCNumVector(0, pixelSizeOnMap.Y); transformation = new RCCoordTransformation(nullVectorOfMinimap, baseVectorOfMinimapX, baseVectorOfMinimapY); return(true); }
/// <summary> /// Constructs a MinimapPixel instance. /// </summary> /// <param name="targetScenario">Reference to the target scenario.</param> /// <param name="pixelCoords">The coordinates of this pixel on the minimap image.</param> /// <param name="mapToMinimapTransformation">Coordinate transformation between the map (A) and minimap (B) coordinate-systems.</param> public MinimapPixel(Scenario targetScenario, RCIntVector pixelCoords, RCCoordTransformation mapToMinimapTransformation) { this.isDisposed = false; this.pixelCoords = pixelCoords; /// Calculate the area on the map covered by this pixel. RCNumVector minimapPixelTopLeft = pixelCoords - (new RCNumVector(1, 1) / 2); RCNumVector minimapPixelBottomRight = pixelCoords + (new RCNumVector(1, 1) / 2); RCNumVector mapRectTopLeft = mapToMinimapTransformation.TransformBA(minimapPixelTopLeft); RCNumVector mapRectBottomRight = mapToMinimapTransformation.TransformBA(minimapPixelBottomRight); this.coveredArea = new RCNumRectangle(mapRectTopLeft, mapRectBottomRight - mapRectTopLeft); this.coveredArea.Intersect(new RCNumRectangle(new RCNumVector(0, 0), targetScenario.Map.CellSize) - (new RCNumVector(1, 1) / 2)); /// Find the quadratic tiles whose centers are inside the covered area. RCIntVector cellRectTopLeft = this.coveredArea.Location.Round(); RCIntVector cellRectBottomRight = (this.coveredArea.Location + this.coveredArea.Size).Round(); RCIntRectangle cellRect = new RCIntRectangle(cellRectTopLeft, cellRectBottomRight - cellRectTopLeft + new RCIntVector(1, 1)); RCIntRectangle quadRect = targetScenario.Map.CellToQuadRect(cellRect); RCIntVector coveredQuadTilesTopLeft = RCIntVector.Undefined; RCIntVector coveredQuadTilesBottomRight = RCIntVector.Undefined; for (int quadCoordX = quadRect.Left; quadCoordX < quadRect.Right; quadCoordX++) { for (int quadCoordY = quadRect.Top; quadCoordY < quadRect.Bottom; quadCoordY++) { RCNumRectangle quadTileRect = (RCNumRectangle)targetScenario.Map.QuadToCellRect(new RCIntRectangle(quadCoordX, quadCoordY, 1, 1)) - (new RCNumVector(1, 1) / 2); RCNumVector quadTileRectCenter = (quadTileRect.Location + quadTileRect.Location + quadTileRect.Size) / 2; if (this.coveredArea.Contains(quadTileRectCenter)) { RCIntVector quadCoords = new RCIntVector(quadCoordX, quadCoordY); if (coveredQuadTilesTopLeft == RCIntVector.Undefined) { coveredQuadTilesTopLeft = quadCoords; } if (coveredQuadTilesBottomRight == RCIntVector.Undefined || quadCoords.Y > coveredQuadTilesBottomRight.Y || quadCoords.X > coveredQuadTilesBottomRight.X) { coveredQuadTilesBottomRight = quadCoords; } } } } this.coveredQuadTiles = new RCIntRectangle(coveredQuadTilesTopLeft, coveredQuadTilesBottomRight - coveredQuadTilesTopLeft + new RCIntVector(1, 1)); }