private List<Site> GetNeighbors(Site site,
int windDirection,
double windSpeed)
{
if (windDirection > 7)
windDirection = 7;
double[] windProbs =
{
(((4.0 - windSpeed)/8.0) * (1+windSpeed)), //Primary direction
(((4.0 - windSpeed)/8.0) * (1+windSpeed)),
(((4.0 - windSpeed)/8.0)),
(((4.0 - windSpeed)/8.0) * (1-windSpeed)),
(((4.0 - windSpeed)/8.0) * (1-windSpeed)), //Opposite of primary direction
(((4.0 - windSpeed)/8.0) * (1-windSpeed)),
(((4.0 - windSpeed)/8.0)),
(((4.0 - windSpeed)/8.0) * (1+windSpeed)),
};
double windProb = 0.0;
int index = 0;
int success = 0;
List<Site> neighbors = new List<Site>(9);
foreach (RelativeLocation relativeLoc in neighborhood)
{
Site neighbor = site.GetNeighbor(relativeLoc);
if (index + windDirection > 7)
windProb = windProbs[index + windDirection - 8];
else
windProb = windProbs[index + windDirection];
if (neighbor != null
&& PlugIn.ModelCore.NextDouble() < windProb)
{
neighbors.Add(neighbor);
success++;
}
index++;
}
//logger.Debug(string.Format("Successfully added {0} neighbors.", success));
//Next, add the 9th neighbor, a neighbor one cell beyond the
//8 nearest neighbors.
//array index 0 = north; 1 = northeast, 2 = east,...,8 = northwest
int[] vertical ={2,2,0,-2,-2,-2,0,2};
int[] horizontal={0,2,2,2,0,-2,-2,-2};
RelativeLocation relativeLoc9 =
new RelativeLocation(vertical[windDirection], horizontal[windDirection]);
Site neighbor9 = site.GetNeighbor(relativeLoc9);
// if (neighbor9 != null && Landis.Model.GenerateUniform() < windSpeed)
if (neighbor9 != null && PlugIn.ModelCore.GenerateUniform() < windSpeed)
neighbors.Add(neighbor9);
return neighbors;
}