Skip to content

Commit

Permalink
Fix hms
Browse files Browse the repository at this point in the history
  • Loading branch information
levinli303 committed Aug 7, 2023
1 parent deeeaca commit 63a6c48
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 28 deletions.
57 changes: 43 additions & 14 deletions CelestiaComponent/CelestiaDMS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,71 @@ using namespace std;

namespace winrt::CelestiaComponent::implementation
{
CelestiaDMS::CelestiaDMS(int32_t degrees, int32_t minutes, double seconds) : CelestiaDMST<CelestiaDMS>(), degrees(degrees), minutes(minutes), seconds(seconds)
CelestiaDMS::CelestiaDMS(int32_t degrees, int32_t minutes, double seconds) : CelestiaDMST<CelestiaDMS>()
{
decimal = astro::degMinSecToDecimal(static_cast<int>(degrees), static_cast<int>(minutes), static_cast<double>(seconds));
}

CelestiaDMS::CelestiaDMS(double decimal) : CelestiaDMST<CelestiaDMS>()
CelestiaDMS::CelestiaDMS(double decimal) : CelestiaDMST<CelestiaDMS>(), decimal(decimal)
{
int degrees, minutes;
}

int32_t CelestiaDMS::Degrees()
{
int degrees;
int minutes;
double seconds;
astro::decimalToDegMinSec(decimal, degrees, minutes, seconds);
this->degrees = degrees;
this->minutes = minutes;
this->seconds = seconds;
return static_cast<int32_t>(degrees);
}

int32_t CelestiaDMS::Degrees()
int32_t CelestiaDMS::Minutes()
{
int degrees;
int minutes;
double seconds;
astro::decimalToDegMinSec(decimal, degrees, minutes, seconds);
return static_cast<int32_t>(minutes);
}

double CelestiaDMS::Seconds()
{
return degrees;
int degrees;
int minutes;
double seconds;
astro::decimalToDegMinSec(decimal, degrees, minutes, seconds);
return seconds;
}

int32_t CelestiaDMS::Hours()
int32_t CelestiaDMS::HMSHours()
{
return degrees;
int hours;
int minutes;
double seconds;
astro::decimalToHourMinSec(decimal, hours, minutes, seconds);
return static_cast<int32_t>(hours);
}

int32_t CelestiaDMS::Minutes()
int32_t CelestiaDMS::HMSMinutes()
{
return minutes;
int hours;
int minutes;
double seconds;
astro::decimalToHourMinSec(decimal, hours, minutes, seconds);
return static_cast<int32_t>(minutes);
}

double CelestiaDMS::Seconds()
double CelestiaDMS::HMSSeconds()
{
int hours;
int minutes;
double seconds;
astro::decimalToHourMinSec(decimal, hours, minutes, seconds);
return seconds;
}

double CelestiaDMS::Decimal()
{
return astro::degMinSecToDecimal(degrees, minutes, seconds);
return decimal;
}
}
10 changes: 5 additions & 5 deletions CelestiaComponent/CelestiaDMS.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ namespace winrt::CelestiaComponent::implementation
CelestiaDMS(double decimal);

int32_t Degrees();
int32_t Hours();
int32_t Minutes();
double Seconds();
int32_t HMSHours();
int32_t HMSMinutes();
double HMSSeconds();
double Decimal();

int32_t degrees;
int32_t minutes;
double seconds;
private:
int32_t decimal;
};
}

Expand Down
4 changes: 3 additions & 1 deletion CelestiaComponent/CelestiaDMS.idl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ namespace CelestiaComponent
CelestiaDMS(Double decimal);

Int32 Degrees{ get; };
Int32 Hours{ get; };
Int32 Minutes{ get; };
Double Seconds{ get; };
Int32 HMSHours{ get; };
Int32 HMSMinutes{ get; };
Double HMSSeconds{ get; };
Double Decimal{ get; };
}
}
16 changes: 8 additions & 8 deletions CelestiaComponent/CelestiaExtension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1195,12 +1195,12 @@ namespace winrt::CelestiaComponent::implementation
numberFormatter.IsGrouped(true);

CelestiaDMS hms{ sph.X() };
double seconds = std::round(hms.Seconds() * 100.0) / 100.0;
lines.push_back(fmt::sprintf(std::wstring(localizationProvider(L"RA: %sh %sm %ss")), std::wstring(numberFormatter.FormatInt(hms.Hours())), std::wstring(numberFormatter.FormatInt(hms.Minutes())), std::wstring(numberFormatter.FormatDouble(seconds))));
double seconds = std::round(hms.HMSSeconds() * 100.0) / 100.0;
lines.push_back(fmt::sprintf(std::wstring(localizationProvider(L"RA: %sh %sm %ss")), std::wstring(numberFormatter.FormatInt(hms.HMSHours())), std::wstring(numberFormatter.FormatInt(hms.HMSMinutes())), std::wstring(numberFormatter.FormatDouble(seconds))));

CelestiaDMS dms{ sph.Y() };
seconds = std::round(dms.Seconds() * 100.0) / 100.0;
lines.push_back(fmt::sprintf(std::wstring(localizationProvider(L"DEC: %s\u00b0 %s\u2032 %s\u2033")), std::wstring(numberFormatter.FormatInt(dms.Hours())), std::wstring(numberFormatter.FormatInt(dms.Minutes())), std::wstring(numberFormatter.FormatDouble(seconds))));
lines.push_back(fmt::sprintf(std::wstring(localizationProvider(L"DEC: %s\u00b0 %s\u2032 %s\u2033")), std::wstring(numberFormatter.FormatInt(dms.Degrees())), std::wstring(numberFormatter.FormatInt(dms.Minutes())), std::wstring(numberFormatter.FormatDouble(seconds))));

return JoinLines(lines);
}
Expand All @@ -1221,23 +1221,23 @@ namespace winrt::CelestiaComponent::implementation
numberFormatter.IsGrouped(true);

CelestiaDMS hms{ sph.X() };
double seconds = std::round(hms.Seconds() * 100.0) / 100.0;
lines.push_back(fmt::sprintf(std::wstring(localizationProvider(L"RA: %sh %sm %ss")), std::wstring(numberFormatter.FormatInt(hms.Hours())), std::wstring(numberFormatter.FormatInt(hms.Minutes())), std::wstring(numberFormatter.FormatDouble(seconds))));
double seconds = std::round(hms.HMSSeconds() * 100.0) / 100.0;
lines.push_back(fmt::sprintf(std::wstring(localizationProvider(L"RA: %sh %sm %ss")), std::wstring(numberFormatter.FormatInt(hms.HMSHours())), std::wstring(numberFormatter.FormatInt(hms.HMSMinutes())), std::wstring(numberFormatter.FormatDouble(seconds))));

CelestiaDMS dms{ sph.Y() };
seconds = std::round(dms.Seconds() * 100.0) / 100.0;
lines.push_back(fmt::sprintf(std::wstring(localizationProvider(L"DEC: %s\u00b0 %s\u2032 %s\u2033")), std::wstring(numberFormatter.FormatInt(dms.Hours())), std::wstring(numberFormatter.FormatInt(dms.Minutes())), std::wstring(numberFormatter.FormatDouble(seconds))));
lines.push_back(fmt::sprintf(std::wstring(localizationProvider(L"DEC: %s\u00b0 %s\u2032 %s\u2033")), std::wstring(numberFormatter.FormatInt(dms.Degrees())), std::wstring(numberFormatter.FormatInt(dms.Minutes())), std::wstring(numberFormatter.FormatDouble(seconds))));

auto galPos = CelestiaHelper::EquatorialToGalactic(eqPos);
sph = CelestiaHelper::RectToSpherical(galPos);

dms = CelestiaDMS(sph.X());
seconds = std::round(dms.Seconds() * 100.0) / 100.0;
lines.push_back(fmt::sprintf(std::wstring(localizationProvider(L"L: %s\u00b0 %s\u2032 %s\u2033")), std::wstring(numberFormatter.FormatInt(dms.Hours())), std::wstring(numberFormatter.FormatInt(dms.Minutes())), std::wstring(numberFormatter.FormatDouble(seconds))));
lines.push_back(fmt::sprintf(std::wstring(localizationProvider(L"L: %s\u00b0 %s\u2032 %s\u2033")), std::wstring(numberFormatter.FormatInt(dms.Degrees())), std::wstring(numberFormatter.FormatInt(dms.Minutes())), std::wstring(numberFormatter.FormatDouble(seconds))));

dms = CelestiaDMS(sph.Y());
seconds = std::round(dms.Seconds() * 100.0) / 100.0;
lines.push_back(fmt::sprintf(std::wstring(localizationProvider(L"B: %s\u00b0 %s\u2032 %s\u2033")), std::wstring(numberFormatter.FormatInt(dms.Hours())), std::wstring(numberFormatter.FormatInt(dms.Minutes())), std::wstring(numberFormatter.FormatDouble(seconds))));
lines.push_back(fmt::sprintf(std::wstring(localizationProvider(L"B: %s\u00b0 %s\u2032 %s\u2033")), std::wstring(numberFormatter.FormatInt(dms.Degrees())), std::wstring(numberFormatter.FormatInt(dms.Minutes())), std::wstring(numberFormatter.FormatDouble(seconds))));

return JoinLines(lines);
}
Expand Down

0 comments on commit 63a6c48

Please sign in to comment.