Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 389f1fe48094
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: bab74a4e2b4c
Choose a head ref
  • 3 commits
  • 9 files changed
  • 2 contributors

Commits on Aug 24, 2019

  1. fix the mac build

    eggrobin committed Aug 24, 2019
    Copy the full SHA
    4fcead2 View commit details
  2. si

    eggrobin committed Aug 24, 2019
    Copy the full SHA
    32f8aa9 View commit details

Commits on Aug 25, 2019

  1. Merge pull request #2301 from eggrobin/fix-the-mac-build

    Fix the mac build
    pleroy authored Aug 25, 2019
    Copy the full SHA
    bab74a4 View commit details
30 changes: 3 additions & 27 deletions astronomy/orbital_elements_test.cpp
Original file line number Diff line number Diff line change
@@ -21,35 +21,9 @@
#include "testing_utilities/numerics_matchers.hpp"

namespace principia {

using astronomy::J2000;
using quantities::si::Metre;
using quantities::si::Radian;
using quantities::si::Second;
using testing_utilities::IsNear;
using testing_utilities::RelativeError;
using testing_utilities::operator""_⑴;

namespace mathematica {
namespace internal_mathematica {

std::string ToMathematica(
astronomy::OrbitalElements::EquinoctialElements const& elements) {
return ToMathematica(std::make_tuple((elements.t - J2000) / Second,
elements.a / Metre,
elements.h,
elements.k,
elements.λ / Radian,
elements.p,
elements.q,
elements.pʹ,
elements.qʹ));
}
} // namespace internal_mathematica
} // namespace mathematica

namespace astronomy {

using astronomy::J2000;
using base::make_not_null_unique;
using base::not_null;
using base::OFStream;
@@ -94,6 +68,8 @@ using testing_utilities::AlmostEquals;
using testing_utilities::DifferenceFrom;
using testing_utilities::IsNear;
using testing_utilities::IsOk;
using testing_utilities::RelativeError;
using testing_utilities::operator""_⑴;
using ::testing::Lt;

class OrbitalElementsTest : public ::testing::Test {
4 changes: 2 additions & 2 deletions ksp_plugin/interface.cpp
Original file line number Diff line number Diff line change
@@ -164,12 +164,12 @@ serialization::OblateBody::Geopotential MakeGeopotential(
int const order = std::stoi(element.order);
column.set_order(order);
if (element.j != nullptr) {
CHECK_EQ(element.cos, nullptr);
CHECK(element.cos == nullptr);
double const j = ParseQuantity<double>(element.j);
column.set_j(j);
}
if (element.cos != nullptr) {
CHECK_EQ(element.j, nullptr);
CHECK(element.j == nullptr);
double const cos = ParseQuantity<double>(element.cos);
column.set_cos(cos);
}
4 changes: 4 additions & 0 deletions mathematica/mathematica.hpp
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
#include <tuple>
#include <vector>

#include "astronomy/orbital_elements.hpp"
#include "geometry/grassmann.hpp"
#include "geometry/point.hpp"
#include "geometry/r3_element.hpp"
@@ -59,6 +60,9 @@ std::string ToMathematica(Point<V> const& point);
template<typename... Types>
std::string ToMathematica(std::tuple<Types...> const& tuple);

std::string ToMathematica(
astronomy::OrbitalElements::EquinoctialElements const& elements);

// Returns its argument.
std::string ToMathematica(std::string const& str);

18 changes: 18 additions & 0 deletions mathematica/mathematica_body.hpp
Original file line number Diff line number Diff line change
@@ -9,16 +9,21 @@
#include <vector>

#include "base/not_constructible.hpp"
#include "quantities/si.hpp"

namespace principia {
namespace mathematica {
namespace internal_mathematica {

using astronomy::J2000;
using base::not_constructible;
using base::not_null;
using quantities::DebugString;
using quantities::IsFinite;
using quantities::SIUnit;
using quantities::si::Metre;
using quantities::si::Radian;
using quantities::si::Second;

// A helper struct to scan the elements of a tuple and stringify them.
template<int index, typename... Types>
@@ -142,6 +147,19 @@ std::string ToMathematica(std::tuple<Types...> const& tuple) {
return Apply("List", expressions);
}

inline std::string ToMathematica(
astronomy::OrbitalElements::EquinoctialElements const& elements) {
return ToMathematica(std::make_tuple((elements.t - J2000) / Second,
elements.a / Metre,
elements.h,
elements.k,
elements.λ / Radian,
elements.p,
elements.q,
elements.pʹ,
elements.qʹ));
}

inline std::string ToMathematica(std::string const& str) {
return str;
}
4 changes: 4 additions & 0 deletions quantities/quantities.hpp
Original file line number Diff line number Diff line change
@@ -145,6 +145,9 @@ constexpr bool IsFinite(Q const& x);
template<typename Q>
constexpr Q NaN();

template<typename D>
std::string Format();

std::string DebugString(
double number,
int precision = std::numeric_limits<double>::max_digits10);
@@ -162,6 +165,7 @@ using internal_quantities::Amount;
using internal_quantities::Angle;
using internal_quantities::Current;
using internal_quantities::DebugString;
using internal_quantities::Format;
using internal_quantities::Infinity;
using internal_quantities::IsFinite;
using internal_quantities::Length;
31 changes: 30 additions & 1 deletion quantities/quantities_body.hpp
Original file line number Diff line number Diff line change
@@ -192,6 +192,35 @@ constexpr Q NaN() {
return SIUnit<Q>() * std::numeric_limits<double>::quiet_NaN();
}

template<typename D>
std::string Format() {
auto const format_unit = [](std::string const& name,
int const exponent) -> std::string {
switch (exponent) {
case 0:
return "";
break;
case 1:
return " " + name;
default:
return " " + name + "^" + std::to_string(exponent);
}
};

// This string has a leading space if it's not empty.
auto const format =
format_unit("m", D::Length) + format_unit("kg", D::Mass) +
format_unit("s", D::Time) + format_unit("A", D::Current) +
format_unit("K", D::Temperature) + format_unit("mol", D::Amount) +
format_unit("cd", D::LuminousIntensity) + format_unit("rad", D::Angle);

if (format.empty()) {
return format;
} else {
return format.substr(1, format.size() - 1);
}
}

inline std::string DebugString(double const number, int const precision) {
char result[50];
#if OS_WIN && PRINCIPIA_COMPILER_MSVC && (_MSC_VER < 1900)
@@ -212,7 +241,7 @@ inline std::string DebugString(double const number, int const precision) {
template<typename D>
std::string DebugString(Quantity<D> const& quantity, int const precision) {
return DebugString(quantity / SIUnit<Quantity<D>>(), precision) + " " +
si::Format<D>();
Format<D>();
}

template<typename D>
4 changes: 0 additions & 4 deletions quantities/si.hpp
Original file line number Diff line number Diff line change
@@ -15,10 +15,6 @@ namespace quantities {
// with the SI.
namespace si {

// Formatting
template<typename D>
std::string Format();

// Prefixes
template<typename D> constexpr Quantity<D> Yotta(Quantity<D>);
template<typename D> constexpr Quantity<D> Zetta(Quantity<D>);
29 changes: 0 additions & 29 deletions quantities/si_body.hpp
Original file line number Diff line number Diff line change
@@ -9,35 +9,6 @@ namespace principia {
namespace quantities {
namespace si {

template<typename D>
std::string Format() {
auto const format_unit = [](std::string const& name,
int const exponent) -> std::string {
switch (exponent) {
case 0:
return "";
break;
case 1:
return " " + name;
default:
return " " + name + "^" + std::to_string(exponent);
}
};

// This string has a leading space if it's not empty.
auto const format =
format_unit("m", D::Length) + format_unit("kg", D::Mass) +
format_unit("s", D::Time) + format_unit("A", D::Current) +
format_unit("K", D::Temperature) + format_unit("mol", D::Amount) +
format_unit("cd", D::LuminousIntensity) + format_unit("rad", D::Angle);

if (format.empty()) {
return format;
} else {
return format.substr(1, format.size() - 1);
}
}

template<typename D>
constexpr Quantity<D> Yotta(Quantity<D> base) {
return 1e24 * base;
6 changes: 3 additions & 3 deletions testing_utilities/approximate_quantity_body.hpp
Original file line number Diff line number Diff line change
@@ -13,8 +13,8 @@ namespace testing_utilities {
namespace internal_approximate_quantity {

using quantities::Abs;
using quantities::Format;
using quantities::SIUnit;
namespace si = quantities::si;

template<typename Dimensions>
Quantity<Dimensions> ApproximateQuantity<Quantity<Dimensions>>::min() const {
@@ -46,8 +46,8 @@ double ApproximateQuantity<Quantity<Dimensions>>::UlpDistance(
template<typename Dimensions>
std::string ApproximateQuantity<Quantity<Dimensions>>::DebugString() const {
if (has_trivial_unit()) {
return (negated_ ? "-" : "") + representation_ +
"(" + std::to_string(ulp_) + ") " + si::Format<Dimensions>();
return (negated_ ? "-" : "") + representation_ + "(" +
std::to_string(ulp_) + ") " + Format<Dimensions>();
} else {
return (negated_ ? "-" : "") + representation_ +
"(" + std::to_string(ulp_) + ") * " + quantities::DebugString(unit_);