private void PlotDayInternal(bool track_intersect, Graphics g, Color col, Position pos, UTCDate udt) { UTCDate udt_lower = new UTCDate(udt.Timezone, udt.DST, udt.Year, udt.Month, udt.Day, 0, 0, 1); // record points to place labels UTCDate dt_midyear = new UTCDate(udt.Timezone, udt.DST, udt.Year, 6, 5, 0, 0, 1); double el_min = 90; Point? pt = null; double step = GetResolutionStep(dayseconds); for (double cursor = 0; cursor < dayseconds; cursor+=step) { UTCDate udt_new = udt_lower.AddSeconds(cursor); SolarPosition sp = Orbit.CalcSolarPosition(pos, udt_new); Point? point = FindPoint(sp.Azimuth, sp.Elevation); if (point != null) { using (SolidBrush br = new SolidBrush(col)) { PlotPoint(g, br, point.Value); } // collect points to place labels if (track_intersect) { double el = Math.Abs(sp.Elevation); // first half of the year if (udt_lower < dt_midyear) { // make sure we keep to the left of the graph if (point.Value.X < graph.Origin.X) { if (el_min > el) { el_min = el; pt = point; } } } // second half of the year if (udt_lower >= dt_midyear) { // make sure we keep to the right of the graph if (point.Value.X >= graph.Origin.X) { if (el_min > el) { el_min = el; pt = point; } } } } } } if (track_intersect) { intersects.Add(udt_lower, new KeyValuePair<Color,Point?>(col, pt)); } }
public static void Bench(int step, bool timebased, bool verbose) { Stopwatch watch = new Stopwatch(); watch.Start(); int it = 0; if (timebased) { for (int s = 0; s < 86400; s += step) { it++; int lon = 10; int lat = 59; int timezone = (int) (lon / 15); Position pos = new Position(Position.LatDirFromVal(lat), lat, 0, 0, Position.LonDirFromVal(lon), lon, 0, 0); int year = 2009; int month = 2; int day = 1; UTCDate dt = new UTCDate(timezone, null, year, month, day, 0, 0, 0); dt = dt.AddSeconds(s); SolarPosition sp = Orbit.CalcSolarPosition(pos, dt); SolarTimes sns = Orbit.CalcSolarTimes(pos, dt); if (verbose) { Printing.Print(sp, sns); } } } else { for (int lon = -180; lon <= 180; lon += step) { for (int lat = -90; lat <= 90; lat += step) { it++; int timezone = (int) (lon / 15); Position pos = new Position(Position.LatDirFromVal(lat), lat, 0, 0, Position.LonDirFromVal(lon), lon, 0, 0); int hour = 11; int min = 0; int sec = 0; int year = 2009; int month = 2; int day = 1; UTCDate dt = new UTCDate(timezone, null, year, month, day, hour, min, sec); SolarPosition sp = Orbit.CalcSolarPosition(pos, dt); SolarTimes sns = Orbit.CalcSolarTimes(pos, dt); if (verbose) { Printing.Print(sp, sns); } } } } watch.Stop(); Console.WriteLine("Iterations: {0}", it); Console.WriteLine("Elapsed: {0}",watch.Elapsed); Console.WriteLine("In milliseconds: {0}",watch.ElapsedMilliseconds); Console.WriteLine("In timer ticks: {0}",watch.ElapsedTicks); }