public float getDistanceTo(District another, RoadNetwork roadNetwork) { if (!distancesCache.ContainsKey(another)) { float result = float.MaxValue; HashSet <RoadSegment> roadSegments = this.getRelatedRoadSegments(roadNetwork); HashSet <RoadSegment> anotherRoadSegments = another.getRelatedRoadSegments(roadNetwork); foreach (RoadSegment segment in roadSegments) { if (segment == null) { continue; } foreach (RoadSegment anotherSegment in anotherRoadSegments) { if (anotherSegment == null) { continue; } float distance = RoadHelper.getDistance(roadNetwork, segment, anotherSegment); if (distance < result) { result = distance; } } } distancesCache[another] = result; } return(distancesCache[another]); }
public float getDistanceTo(District another, RoadNetwork roadNetwork) { if (!distancesCache.ContainsKey(another)) { float result = float.MaxValue; HashSet <RoadSegment> roadSegments = this.getRelatedRoadSegments(roadNetwork); HashSet <RoadSegment> anotherRoadSegments = another.getRelatedRoadSegments(roadNetwork); foreach (RoadSegment segment in roadSegments) { if (segment == null) { continue; } foreach (RoadSegment anotherSegment in anotherRoadSegments) { if (anotherSegment == null) { continue; } float distance = RoadHelper.getDistance(roadNetwork, segment, anotherSegment); if (distance < result) { result = distance; } } } distancesCache[another] = result; } return(distancesCache[another]); //Vector2 thisPosition = new Vector2(); //foreach (DistrictCell cell in cells) //{ // thisPosition.x += cell.x; // thisPosition.y += cell.y; //} //thisPosition.x /= cells.Count; //thisPosition.y /= cells.Count; //Vector2 anotherPosition = new Vector2(); //foreach (DistrictCell cell in another.cells) //{ // anotherPosition.x += cell.x; // anotherPosition.y += cell.y; //} //anotherPosition.x /= cells.Count; //anotherPosition.y /= cells.Count; //return Vector2.Distance(thisPosition, anotherPosition); }