Skip to content

Commit

Permalink
Calendars plugin fixes
Browse files Browse the repository at this point in the history
- const references
- obvious fix in TibetanLeapYear
  • Loading branch information
gzotti committed Aug 28, 2024
1 parent eb47095 commit 96ff16a
Show file tree
Hide file tree
Showing 76 changed files with 185 additions and 185 deletions.
4 changes: 2 additions & 2 deletions plugins/Calendars/src/ArmenianCalendar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ QString ArmenianCalendar::getFormattedDateString() const
// set date from a vector of calendar date elements sorted from the largest to the smallest.
// Year-Month[1...12]-Day[1...31]
// Time is not changed!
void ArmenianCalendar::setDate(QVector<int> parts)
void ArmenianCalendar::setDate(const QVector<int> &parts)
{
this->parts=parts;

Expand All @@ -104,7 +104,7 @@ void ArmenianCalendar::setDate(QVector<int> parts)
}

// actually implementation of alt-fixed-from-egyptian
int ArmenianCalendar::fixedFromArmenian(QVector<int> armenian)
int ArmenianCalendar::fixedFromArmenian(const QVector<int> &armenian)
{
return armenianEpoch + fixedFromEgyptian(armenian)-EgyptianCalendar::egyptianEpoch;
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/Calendars/src/ArmenianCalendar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public slots:

//! set date from a vector of calendar date elements sorted from the largest to the smallest.
//! Year-Month[1...12]-Day[1...31]
void setDate(QVector<int> parts) override;
void setDate(const QVector<int> &parts) override;

//! get a stringlist of calendar date elements sorted from the largest to the smallest.
//! Year, Month, MonthName, Day, DayName
Expand All @@ -51,7 +51,7 @@ public slots:
QString getFormattedDateString() const override;

//! find RD number for date in the Armenian calendar (may be used in other calendars!)
static int fixedFromArmenian(QVector<int> julian);
static int fixedFromArmenian(const QVector<int> &armenian);
//! find date in the Armenian calendar from RD number (may be used in other calendars!)
static QVector<int> armenianFromFixed(int rd);

Expand Down
2 changes: 1 addition & 1 deletion plugins/Calendars/src/AstroHinduLunarCalendar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void AstroHinduLunarCalendar::setJD(double JD)
// set date from a vector of calendar date elements sorted from the largest to the smallest.
// {Year, Month[1...12], leapMonth[0|1], Day[1...30], leapDay}
// Time is not changed!
void AstroHinduLunarCalendar::setDate(QVector<int> parts)
void AstroHinduLunarCalendar::setDate(const QVector<int> &parts)
{
this->parts=parts;
double rd=fixedFromAstroHinduLunar(parts);
Expand Down
2 changes: 1 addition & 1 deletion plugins/Calendars/src/AstroHinduLunarCalendar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public slots:

//! set RD date from a vector of calendar date elements sorted from the largest to the smallest.
//! parts = {Year, Month[1...12], leapMonth[0|1], Day[1...30], leapDay[0|1] }
void setDate(QVector<int> parts) override;
void setDate(const QVector<int> &parts) override;

//! get a stringlist of calendar date elements sorted from the largest to the smallest.
//! @return {Year, Month, MonthName, leap[0|1], Day, DayName}
Expand Down
2 changes: 1 addition & 1 deletion plugins/Calendars/src/AstroHinduSolarCalendar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void AstroHinduSolarCalendar::setJD(double JD)
// set date from a vector of calendar date elements sorted from the largest to the smallest.
// {Year, Month[1...12], leapMonth[0|1], Day[1...30], leapDay}
// Time is not changed!
void AstroHinduSolarCalendar::setDate(QVector<int> parts)
void AstroHinduSolarCalendar::setDate(const QVector<int> &parts)
{
this->parts=parts;
double rd=fixedFromAstroHinduSolar(parts);
Expand Down
2 changes: 1 addition & 1 deletion plugins/Calendars/src/AstroHinduSolarCalendar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public slots:

//! set RD date from a vector of calendar date elements sorted from the largest to the smallest.
//! parts = {Year, Month[1...12], leapMonth[0|1], Day[1...30], leapDay[0|1] }
void setDate(QVector<int> parts) override;
void setDate(const QVector<int> &parts) override;

//! get a stringlist of calendar date elements for the Hindu Astro Solar calendar sorted from the largest to the smallest.
//! {Year, Month, MonthName, Day, WeekDayName}
Expand Down
2 changes: 1 addition & 1 deletion plugins/Calendars/src/AztecTonalpohualliCalendar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ QStringList AztecTonalpohualliCalendar::getDateStrings() const
// set date from a vector of calendar date elements sorted from the largest to the smallest.
// month-day
// We face a problem as the year is not unique. We can only find the date before current JD which matches the parts.
void AztecTonalpohualliCalendar::setDate(QVector<int> parts)
void AztecTonalpohualliCalendar::setDate(const QVector<int> &parts)
{
this->parts=parts;

Expand Down
4 changes: 2 additions & 2 deletions plugins/Calendars/src/AztecTonalpohualliCalendar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public slots:
//! set date from a vector of calendar date elements sorted from the largest to the smallest.
//! dayNumber[1..13]-nameIndex[1..20]
//! We face a problem as the date is not unique. We can only find the date before current JD which matches the parts.
void setDate(QVector<int> parts) override;
void setDate(const QVector<int> &parts) override;

//! get a stringlist of calendar date elements sorted from the largest to the smallest.
//! dayNumber[1..13]-name
QStringList getDateStrings() const override;

//! Return ordinal in Tonalpohualli cycle.
//! @arg tonalpohualli is a QVector<int> of {number, name} (typo in book...)
inline static int aztecTonalpohualliOrdinal(QVector<int> tonalpohualli) {return StelUtils::imod((tonalpohualli.at(0) - 1 + 39*(tonalpohualli.at(0)-tonalpohualli.at(1))), 260);}
inline static int aztecTonalpohualliOrdinal(const QVector<int> &tonalpohualli) {return StelUtils::imod((tonalpohualli.at(0) - 1 + 39*(tonalpohualli.at(0)-tonalpohualli.at(1))), 260);}

//! get 2-part vector of Tonalpohualli date from RD
static QVector<int> aztecTonalpohualliFromFixed(int rd);
Expand Down
6 changes: 3 additions & 3 deletions plugins/Calendars/src/AztecXihuitlCalendar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ QString AztecXihuitlCalendar::getFormattedDateString() const
// set date from a vector of calendar date elements sorted from the largest to the smallest.
// month-day
// We face a problem as the year is not unique. We can only find the date before current JD which matches the parts.
void AztecXihuitlCalendar::setDate(QVector<int> parts)
void AztecXihuitlCalendar::setDate(const QVector<int> &parts)
{
this->parts=parts;

Expand All @@ -119,13 +119,13 @@ QVector<int> AztecXihuitlCalendar::aztecXihuitlFromFixed(int rd)
return {month, day};
}

int AztecXihuitlCalendar::aztecXihuitlOnOrBefore(QVector<int> xihuitl, int rd)
int AztecXihuitlCalendar::aztecXihuitlOnOrBefore(const QVector<int> &xihuitl, int rd)
{
return modInterval(aztecXihuitlCorrelation+aztecXihuitlOrdinal(xihuitl), rd, rd-365);
}

// get RD of a combined date
int AztecXihuitlCalendar::aztecXihuitlTonalpohualliOnOrBefore(QVector<int>xihuitl, QVector<int>tonalpohualli, int rd)
int AztecXihuitlCalendar::aztecXihuitlTonalpohualliOnOrBefore(const QVector<int> &xihuitl, const QVector<int> &tonalpohualli, int rd)
{
const int xihuitlCount=aztecXihuitlOrdinal(xihuitl)+aztecXihuitlCorrelation;
const int tonalpohualliCount=AztecTonalpohualliCalendar::aztecTonalpohualliOrdinal(tonalpohualli)+AztecTonalpohualliCalendar::aztecTonalpohualliCorrelation;
Expand Down
8 changes: 4 additions & 4 deletions plugins/Calendars/src/AztecXihuitlCalendar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public slots:
//! set date from a vector of calendar date elements sorted from the largest to the smallest.
//! month[1..19]-day[1..20]
//! We face a problem as the year is not counted. We can only find the date before current JD which matches the parts.
void setDate(QVector<int> parts) override;
void setDate(const QVector<int> &parts) override;

//! get a stringlist of calendar date elements sorted from the largest to the smallest.
//! monthName-day[1..20]
Expand All @@ -54,16 +54,16 @@ public slots:
QString getFormattedDateString() const override;

//! find number in sequence from a xihuitl date of {month[1...19], day[1...20]}
inline static int aztecXihuitlOrdinal(QVector<int> xihuitl) {return (xihuitl.at(0)-1)*20+xihuitl.at(1)-1;}
inline static int aztecXihuitlOrdinal(const QVector<int> &xihuitl) {return (xihuitl.at(0)-1)*20+xihuitl.at(1)-1;}

//! get 2-part vector of xihuitl date from RD
static QVector<int> aztecXihuitlFromFixed(int rd);

//! find RD number of a Xihuitl date on or before rd.
static int aztecXihuitlOnOrBefore(QVector<int> xihuitl, int rd);
static int aztecXihuitlOnOrBefore(const QVector<int> &xihuitl, int rd);

//! get RD of a combined date on or before rd. They repeat every 18980 days.
static int aztecXihuitlTonalpohualliOnOrBefore(QVector<int>xihuitl, QVector<int>tonalpohualli, int rd);
static int aztecXihuitlTonalpohualliOnOrBefore(const QVector<int>&xihuitl, const QVector<int>&tonalpohualli, int rd);

public:
//! Aztec date of fall of Tenochtitlan
Expand Down
4 changes: 2 additions & 2 deletions plugins/Calendars/src/BahaiArithmeticCalendar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void BahaiArithmeticCalendar::setJD(double JD)

// set date from a vector of calendar date elements sorted from the largest to the smallest.
// Major-Cycle-Year-Month[0...19]-Day[1...19]
void BahaiArithmeticCalendar::setDate(QVector<int> parts)
void BahaiArithmeticCalendar::setDate(const QVector<int> &parts)
{
//qDebug() << "BahaiArithmeticCalendar::setDate:" << parts;
this->parts=parts;
Expand Down Expand Up @@ -158,7 +158,7 @@ QString BahaiArithmeticCalendar::getFormattedDateString() const
* Functions from CC.UE ch16.2
*/

int BahaiArithmeticCalendar::fixedFromBahaiArithmetic(QVector<int> bahai5)
int BahaiArithmeticCalendar::fixedFromBahaiArithmetic(const QVector<int> &bahai5)
{
const int major=bahai5.value(0);
const int cycle=bahai5.value(1);
Expand Down
4 changes: 2 additions & 2 deletions plugins/Calendars/src/BahaiArithmeticCalendar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public slots:

//! set date from a vector of calendar date elements sorted from the largest to the smallest.
//! Year-Month[1...12]-Day[1...31]
void setDate(QVector<int> parts) override;
void setDate(const QVector<int> &parts) override;

//! get a stringlist of calendar date elements sorted from the largest to the smallest.
//! Year, Month, MonthName, Day, DayName
Expand All @@ -55,7 +55,7 @@ public slots:
QString getFormattedDateString() const override;

//! Return R.D. of date given in the Bahai Arithmetic calendar. (CC:UE 16.3)
static int fixedFromBahaiArithmetic(QVector<int> bahai5);
static int fixedFromBahaiArithmetic(const QVector<int> &bahai5);

//! Return R.D. of date given in the Bahai Arithmetic calendar. (CC:UE 16.4)
//! return major-cycle-year-month-day for RD date
Expand Down
4 changes: 2 additions & 2 deletions plugins/Calendars/src/BahaiAstronomicalCalendar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void BahaiAstronomicalCalendar::setJD(double JD)

// set date from a vector of calendar date elements sorted from the largest to the smallest.
// Major-Cycle-Year-Month[0...19]-Day[1...19]
void BahaiAstronomicalCalendar::setDate(QVector<int> parts)
void BahaiAstronomicalCalendar::setDate(const QVector<int> &parts)
{
//qDebug() << "BahaiAstronomicalCalendar::setDate:" << parts;
this->parts=parts;
Expand Down Expand Up @@ -102,7 +102,7 @@ int BahaiAstronomicalCalendar::astroBahaiNewYearOnOrBefore(int rd)
}

// Return R.D. of date given in the Bahai Astronomical calendar. (CC:UE 16.8)
int BahaiAstronomicalCalendar::fixedFromBahaiAstronomical(QVector<int> bahai5)
int BahaiAstronomicalCalendar::fixedFromBahaiAstronomical(const QVector<int> &bahai5)
{
const int major=bahai5.value(0);
const int cycle=bahai5.value(1);
Expand Down
4 changes: 2 additions & 2 deletions plugins/Calendars/src/BahaiAstronomicalCalendar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public slots:

//! set date from a vector of calendar date elements sorted from the largest to the smallest.
//! Year-Month[1...12]-Day[1...31]
void setDate(QVector<int> parts) override;
void setDate(const QVector<int> &parts) override;

//! get a stringlist of calendar date elements sorted from the largest to the smallest.
//! Year, Month, MonthName, Day, DayName
Expand All @@ -61,7 +61,7 @@ public slots:
static int astroBahaiNewYearOnOrBefore(int rd);

//! Return R.D. of date given in the Bahai Astronomical calendar. (CC:UE 16.8)
static int fixedFromBahaiAstronomical(QVector<int> bahai5);
static int fixedFromBahaiAstronomical(const QVector<int> &bahai5);

//! Return R.D. of date given in the Bahai Astronomical calendar. (CC:UE 16.9)
//! return major-cycle-year-month-day for RD date
Expand Down
4 changes: 2 additions & 2 deletions plugins/Calendars/src/BalinesePawukonCalendar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void BalinesePawukonCalendar::setJD(double JD)

// set date from a vector of calendar date elements in canonical order.
// Given that we cannot set a date directly, this sets the date of these elements on or before the current JD
void BalinesePawukonCalendar::setDate(QVector<int> parts)
void BalinesePawukonCalendar::setDate(const QVector<int> &parts)
{
// Problem: This sets time to midnight. We need to keep and reset the fractional day.
//const double dayFraction=JD-std::floor(JD-.5);
Expand Down Expand Up @@ -170,7 +170,7 @@ int BalinesePawukonCalendar::baliCaturwaraFromFixed(const int rd)
return StelUtils::amod(baliAsatawaraFromFixed(rd), 4);
}

int BalinesePawukonCalendar::baliOnOrBefore(const QVector<int>baliDate, const int rd)
int BalinesePawukonCalendar::baliOnOrBefore(const QVector<int> &baliDate, const int rd)
{
const int a5=baliDate.value(4)-1;
const int a6=baliDate.value(5)-1;
Expand Down
4 changes: 2 additions & 2 deletions plugins/Calendars/src/BalinesePawukonCalendar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public slots:
//! This triggers the jdChanged() signal
//! Note that this must not change the time of day! You must retrieve the time from the current JD before recomputing a new JD.
//! This actually sets bali-on-or-before()
void setDate(QVector<int> parts) override;
void setDate(const QVector<int> &parts) override;

//! get a stringlist of calendar date elements sorted from the largest to the smallest.
//! The order depends on the actual calendar
Expand All @@ -69,7 +69,7 @@ public slots:
static int baliAsatawaraFromFixed(const int rd);
static int baliCaturwaraFromFixed(const int rd);

static int baliOnOrBefore(const QVector<int>baliDate, const int rd);
static int baliOnOrBefore(const QVector<int>&baliDate, const int rd);
public:
static const int baliEpoch;

Expand Down
8 changes: 4 additions & 4 deletions plugins/Calendars/src/Calendar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "StelLocationMgr.hpp"


QString Calendar::getFormattedDateString(QVector<int> date, QString sep)
QString Calendar::getFormattedDateString(const QVector<int> &date, QString sep)
{
QString res;
QVector<int>::const_iterator it;
Expand Down Expand Up @@ -82,7 +82,7 @@ double Calendar::jdFromMoment(double rd, bool respectUTCoffset)
}

// Reingold-Dershowitz CC.UE 1.48
int Calendar::rdCorrSum(QVector<int>parts, QVector<int>factors, int corr)
int Calendar::rdCorrSum(const QVector<int> &parts, const QVector<int> &factors, int corr)
{
Q_ASSERT(parts.length()==factors.length());

Expand All @@ -93,7 +93,7 @@ int Calendar::rdCorrSum(QVector<int>parts, QVector<int>factors, int corr)
}

// Split integer to mixed-radix vector. Reingold-Dershowitz CC.UE 1.42
QVector<int> Calendar::toRadix(int num, QVector<int>radix)
QVector<int> Calendar::toRadix(int num, const QVector<int>&radix)
{
int div=1;
int rest=num;
Expand All @@ -114,7 +114,7 @@ QVector<int> Calendar::toRadix(int num, QVector<int>radix)

// Intersect a collection of candidates against a range of values.
// return a new QVector<int> with all elements from candidates which lie in range
QVector<int> Calendar::intersectWithRange(QVector<int>cand, QVector<int>range)
QVector<int> Calendar::intersectWithRange(const QVector<int>&cand, const QVector<int>&range)
{
QVector<int>res;
for (int i=0; i<cand.length(); i++)
Expand Down
10 changes: 5 additions & 5 deletions plugins/Calendars/src/Calendar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public slots:
//! GregorianCalendar.setDate([2023, 3, 4]); // This changes the date in the program!
//! MayaLongCountCalendar.setDate([13, 0, 0, 0, 1]); // This changes the date in the program!
//! @note No check is made for the number of elements, which depends on the actual calendar.
virtual void setDate(QVector<int> parts){Q_UNUSED(parts)}
virtual void setDate(const QVector<int> &parts){Q_UNUSED(parts)}

//! get a vector of calendar date elements sorted from the largest to the smallest.
//! The order depends on the actual calendar
Expand All @@ -107,7 +107,7 @@ public slots:
virtual QString getFormattedDateString() const;

//! get a formatted complete string for a date. This implementation just converts and concatenates all ints with sep in between.
static QString getFormattedDateString(QVector<int> date, QString sep=" ");
static QString getFormattedDateString(const QVector<int> &date, QString sep=" ");

public:
//constexpr static const double J2000=2451545.0;
Expand Down Expand Up @@ -167,15 +167,15 @@ public slots:
static int modInterval(int x, int a, int b);

//! Reingold-Dershowitz CC.UE 1.48.
static int rdCorrSum(QVector<int>parts, QVector<int>factors, int corr);
static int rdCorrSum(const QVector<int>&parts, const QVector<int>&factors, int corr);
int rdCorrSum(QVector<int>factors, int corr){return rdCorrSum(parts, factors, corr);}

//! Split integer to mixed-radix vector. Reingold-Dershowitz CC.UE 1.42
static QVector<int> toRadix(int num, QVector<int>radix);
static QVector<int> toRadix(int num, const QVector<int> &radix);

//! Intersect a collection of candidates against a range of values.
//! @return a new QVector<int> with all elements from candidates which lie in range
static QVector<int> intersectWithRange(QVector<int>cand, QVector<int>range);
static QVector<int> intersectWithRange(const QVector<int>&cand, const QVector<int>&range);

// ASTRONOMICAL FUNCTIONS AND DEFINITIONS FROM CH.14
public:
Expand Down
10 changes: 5 additions & 5 deletions plugins/Calendars/src/ChineseCalendar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ QString ChineseCalendar::getFormattedSolarTermsString() const
// set date from a vector of calendar date elements sorted from the largest to the smallest.
// {cycle, year, month, leap-month, day}
// Time is not changed!
void ChineseCalendar::setDate(QVector<int> parts)
void ChineseCalendar::setDate(const QVector<int> &parts)
{
this->parts=parts;

Expand All @@ -203,7 +203,7 @@ void ChineseCalendar::setDate(QVector<int> parts)
}

//! @arg parts5={cycle, year, month, leapMonth, day}
int ChineseCalendar::fixedFromChinese(QVector<int> parts5)
int ChineseCalendar::fixedFromChinese(const QVector<int> &parts5)
{
const int cycle = parts5.value(0);
const int year = parts5.value(1);
Expand Down Expand Up @@ -388,7 +388,7 @@ QPair<QString, QString> ChineseCalendar::sexagesimalNames(int n)
}

// Retrieve year difference between name pairs. [1..60]. (CC:UE 19.19)
int ChineseCalendar::chineseNameDifference(QPair<int,int>stemBranch1, QPair<int,int>stemBranch2)
int ChineseCalendar::chineseNameDifference(const QPair<int, int> &stemBranch1, const QPair<int, int> &stemBranch2)
{
const int stem1=stemBranch1.first;
const int branch1=stemBranch1.second;
Expand Down Expand Up @@ -431,7 +431,7 @@ QPair<QString, QString> ChineseCalendar::dayName(int rd)
}

// Retrieve RD of day number (1...60) on or before rd. (after CC:UE 19.25)
int ChineseCalendar::dayNumberOnOrBefore(QPair<int,int>stemBranch, int rd)
int ChineseCalendar::dayNumberOnOrBefore(const QPair<int, int> &stemBranch, int rd)
{
return StelUtils::amod(chineseNameDifference(dayNumbers(0), stemBranch), rd, rd-60);
}
Expand Down Expand Up @@ -459,7 +459,7 @@ int ChineseCalendar::qingMing(int gYear)

// Return age of someone born on birthdate on date rd as expressed by Chinese (CC:UE 19.29)
// Returns bogus on error
int ChineseCalendar::chineseAge(QVector<int>birthdate, int rd)
int ChineseCalendar::chineseAge(const QVector<int> &birthdate, int rd)
{
const QVector<int>today=chineseFromFixed(rd);
const int todayCycle=today.at(0);
Expand Down
Loading

0 comments on commit 96ff16a

Please sign in to comment.