/// <summary> /// Scans the surface of a segment's occupancy matrix for a specific spot type and computes it's ratio. /// </summary> /// <param name="type">Value to search for.</param> /// <param name="spots">Ref to occupancy matrix.</param> /// <param name="pivot">Start of area.</param> /// <param name="size">Extents of area.</param> /// <returns>A value between [0f, 1f].</returns> public static float GetSpotRatio(PlacerSpot.Type type, int[,] spots, PlacerSpot pivot, int size) { int count = 0; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { if (spots[pivot.x + i, pivot.y + j] == (int)type) { count++; } } } return((float)count / (size * size)); }
/// <summary> /// Returns all the spots of a certain type from a specified area. /// </summary> /// <param name="type">Value to search for.</param> /// <param name="spots">Ref to occupancy matrix.</param> /// <param name="pivot">Start of area.</param> /// <param name="size">Extents of area.</param> /// <param name="output">List to add the spots to.</param> public static void GetSpots(PlacerSpot.Type type, int[,] spots, PlacerSpot pivot, int size, List <PlacerSpot> output) { PlacerSpot spot = new PlacerSpot(); //be gentle with the stack, allocate only once for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { spot.x = pivot.x + i; spot.y = pivot.y + j; if (spots[spot.x, spot.y] == (int)type) { output.Add(spot); } } } }
/// <summary> /// Scans the surface of the occupancy matrix for a specific spot type and computes it's ratio. /// </summary> /// <param name="type">Value to search for.</param> /// <returns>A value between [0f, 1f].</returns> public float GetSpotRatio(PlacerSpot.Type type) { return(GetSpotRatio(type, spots, pivot, size)); }
/// <summary> /// Returns all the spots of a certain type. /// </summary> /// <param name="type">Value to search for.</param> /// <param name="output">List to add the spots to.</param> public void GetSpots(PlacerSpot.Type type, List <PlacerSpot> output) { GetSpots(type, spots, pivot, size, output); }