int CTimer::StartTimer(double first, double interval){ if(m_timer == 0){ NLOG_ERROR("Timer Not Tnitialized!"); return -1; } //first == 0 if(fabs(first) < 0.000000001){ NLOG_ERROR("arg first [%lf] Is Invalid!", first); return -1; } //interval == 0 if(fabs(interval) < 0.000000001){ NLOG_ERROR("arg interval [%lf] Is Invalid!", interval); return -1; } m_first = first; m_interval = interval; struct itimerspec timespec; memset(×pec, 0, sizeof(timespec)); timespec.it_value.tv_sec = Floor(first); timespec.it_value.tv_nsec = ToNanoseconds(Frac(first)); timespec.it_interval.tv_sec = Floor(interval); timespec.it_interval.tv_nsec =ToNanoseconds(Frac(interval)); /* NLOG_DEBUG("Timer(%s) Start! First Run[%.6lf], Interval[%.6lf]", m_name,first, interval); */ return timer_settime(m_timer, 0, ×pec, NULL); }
static void ReplaceTime(TDateTime & DateTime, const TDateTime & NewTime) { DateTime = Trunc(DateTime); if (DateTime >= 0) DateTime = DateTime + Abs(Frac(NewTime)); else DateTime = DateTime - Abs(Frac(NewTime)); }
void StarGeneratorInterface::UpdateRAControls() { double hh = instance.centerRA/15; double hm = 60*Frac( hh ); double hs = Round( 60*Frac( hm ), 2 ); if ( hs == 60 ) { hs = 0; hm += 1; } if ( hm == 60 ) { hm = 0; hh += 1; } if ( hh >= 24 ) hh = hm = hs = 0; GUI->RAHours_SpinBox.SetValue( int( hh ) ); GUI->RAMins_SpinBox.SetValue( int( hm ) ); GUI->RASecs_NumericEdit.SetValue( hs ); }
void StarGeneratorInterface::UpdateDecControls() { double dd = Abs( instance.centerDec ); double dm = 60*Frac( dd ); double ds = Round( 60*Frac( dm ), 2 ); if ( ds == 60 ) { ds = 0; dm += 1; } if ( dm == 60 ) { dm = 0; dd += 1; } if ( dd >= 90 ) dm = ds = 0; GUI->DecDegs_SpinBox.SetValue( int( Sign( instance.centerDec )*dd ) ); GUI->DecMins_SpinBox.SetValue( int( dm ) ); GUI->DecSecs_NumericEdit.SetValue( ds ); GUI->DecSouth_CheckBox.SetChecked( instance.centerDec < 0 ); }
double ThetaG_JD(double jd) { /* Reference: The 1992 Astronomical Almanac, page B6. */ double UT, TU, GMST; UT=Frac(jd+0.5); jd=jd-UT; TU=(jd-2451545.0)/36525; GMST=24110.54841+TU*(8640184.812866+TU*(0.093104-TU*6.2E-6)); GMST=Modulus(GMST+secday*omega_E*UT,secday); return (2*M_PI*GMST/secday); }
/* Converts a Julian epoch to NORAD TLE epoch format */ double Epoch_Time(double jd) { double yr,time,epoch_time; struct tm edate; Calendar_Date(jd, &edate); yr = edate.tm_year - 100*(edate.tm_year/100) ; time = Frac(jd + 0.5); epoch_time = yr*1000 + DOY(edate.tm_year, edate.tm_mon, edate.tm_mday) + time; return( epoch_time ); } /*Function Epoch_Time*/
/* portion of that date. Only tm_hour, tm_min and tm_sec are set */ void Time_of_Day(double jd, struct tm *cdate) { int hr,mn,sc; double time; time = Frac(jd - 0.5)*secday; time = Round(time); hr = floor(time/3600.0); time = time - 3600.0*hr; if( hr == 24 ) hr = 0; mn = floor(time/60.0); sc = time - 60.0*mn; cdate->tm_hour = hr; cdate->tm_min = mn; cdate->tm_sec = sc; } /*Function Time_of_Day*/
/* Only the members tm_year, tm_mon and tm_mday are calculated and set */ void Calendar_Date(double jd, struct tm *cdate) { /* Astronomical Formulae for Calculators, Jean Meeus, pages 26-27 */ int Z,month; double A,B,C,D,E,F,alpha,day,year,factor; factor = 0.5/secday/1000; F = Frac(jd + 0.5); if (F + factor >= 1.0) { jd = jd + factor; F = 0.0; } /*if*/ Z = Round(jd); if( Z < 2299161 ) A = Z; else { alpha = Int((Z - 1867216.25)/36524.25); A = Z + 1 + alpha - Int(alpha/4); } /*else*/ B = A + 1524; C = Int((B - 122.1)/365.25); D = Int(365.25 * C); E = Int((B - D)/30.6001); day = B - D - Int(30.6001 * E) + F; if( E < 13.5 ) month = Round(E - 1); else month = Round(E - 13); if( month > 2.5 ) year = C - 4716; else year = C - 4715; cdate->tm_year = (int) year; cdate->tm_mon = month; cdate->tm_mday = (int) floor(day); } /*Function Calendar_Date*/
float3 Polygon::PointOnEdge(float normalizedDistance) const { if (p.empty()) return float3::nan; if (p.size() < 2) return p[0]; normalizedDistance = Frac(normalizedDistance); // Take modulo 1 so we have the range [0,1[. float perimeter = Perimeter(); float d = normalizedDistance * perimeter; for(int i = 0; i < NumVertices(); ++i) { LineSegment edge = Edge(i); float len = edge.Length(); assume(len != 0.f && "Degenerate Polygon detected!"); if (d <= len) return edge.GetPoint(d / len); d -= len; } mathassert(false && "Polygon::PointOnEdge reached end of loop which shouldn't!"); return p[0]; }
/// x mod y static double Modulo (double x, double y) { return y*Frac(x/y); }