/// <summary> /// Calc minimum distance for the same terrain types items (by terrain type) /// </summary> /// <param name="TT"></param> /// <returns></returns> public double GetNearestSameTerrainTypeMinDistance(TerrainType TT) { List <FieldElement> ItemsList; ItemsList = GetItemsByTerrainType(TT); var minDist = 100.0; foreach (var item in ItemsList) { FieldElement Nearest = GetNearestSameTerrainType(item); var dist = CalcDistance(item, Nearest); if (dist < minDist) { minDist = dist; } } return(minDist); }
/// <summary> /// Search for nearest item with the same terrain type /// </summary> /// <param name="AnalyzedFieldItem"></param> /// <returns></returns> public FieldElement GetNearestSameTerrainType(FieldElement AnalyzedFieldItem) { var dist = 0.0; var mindist = 1000.0; FieldElement retField = AnalyzedFieldItem; for (int i = 0; i < 18; i++) { if (FieldItems[i].Type == AnalyzedFieldItem.Type && AnalyzedFieldItem.id != i) { dist = CalcDistance(AnalyzedFieldItem, FieldItems[i]); if (dist < mindist) { mindist = dist; retField = FieldItems[i]; } } } return(retField); }
public double CalcDistance(FieldElement P1, FieldElement P2) { return(CalcDistance(P1.Coord, P2.Coord)); }