Skip to content

Commit

Permalink
Simplify or fix callers, and fix the definition
Browse files Browse the repository at this point in the history
  • Loading branch information
eggrobin committed Mar 28, 2024
1 parent deb3c07 commit b4c8333
Show file tree
Hide file tree
Showing 24 changed files with 67 additions and 91 deletions.
3 changes: 1 addition & 2 deletions benchmarks/discrete_trajectory_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ DiscreteTrajectory<World> MakeTrajectory(Timeline<World> const& timeline,
double const split = *it_split;
CHECK_LE(0, split);
CHECK_LE(split, 1);
t_split = Barycentre<Instant, double>({t_min, t_max},
{1 - split, split});
t_split = Barycentre({t_min, t_max}, {1 - split, split});
}
}
if (t >= t_split) {
Expand Down
2 changes: 1 addition & 1 deletion geometry/barycentre_calculator_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ std::conditional_t<additive_group<Point>, std::nullopt_t, Point> const
BarycentreCalculator<Point, Weight>::reference_;


template<typename Point, typename Weight, std::size_t size>
template<affine Point, typename Weight, std::size_t size>
requires(std::is_convertible_v<Weight, double> &&
real_vector_space<Difference<Point>>) ||
homogeneous_vector_space<Difference<Point>, Weight>
Expand Down
3 changes: 1 addition & 2 deletions geometry/perspective_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ Perspective<FromFrame, ToFrame>::SegmentBehindFocalPlane(
// λ determines where the segment intersects the focal plane.
double const λ = (focal_ - z2) / (z1 - z2);
auto const intercept =
Barycentre<Position<FromFrame>, double>(segment,
{λ, 1.0 - λ});
Barycentre({segment.first, segment.second}, {λ, 1.0 - λ});
if (first_is_visible) {
return std::make_optional<Segment<FromFrame>>(segment.first, intercept);
} else {
Expand Down
5 changes: 2 additions & 3 deletions geometry/point_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,8 @@ TEST_F(PointDeathTest, BarycentreError) {
TEST_F(PointTest, Barycentres) {
Instant const t1 = mjd0 + 1 * Day;
Instant const t2 = mjd0 - 3 * Day;
Instant const b1 = Barycentre<Instant, Volume>({t1, t2},
{3 * Litre, 1 * Litre});
Instant const b2 = Barycentre<Instant, double>({t2, t1}, {1, 1});
Instant const b1 = Barycentre({t1, t2}, {3 * Litre, 1 * Litre});
Instant const b2 = Barycentre({t2, t1}, {1, 1});
EXPECT_THAT(b1, AlmostEquals(mjd0, 1));
EXPECT_THAT(b2, Eq(mjd0 - 1 * Day));
}
Expand Down
2 changes: 1 addition & 1 deletion ksp_plugin/flight_plan_optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ FlightPlanOptimizer::EvaluateClosestPeriapsis(
// Try to nudge the desired final time. This may not succeed, in which case
// we give up.
auto const previous_actual_final_time = flight_plan_->actual_final_time();
auto const new_desired_final_time = Barycentre<Instant, double>(
auto const new_desired_final_time = Barycentre(
{flight_plan_->initial_time(), flight_plan_->desired_final_time()},
{1 - flight_plan_extension_factor, flight_plan_extension_factor});
flight_plan_->SetDesiredFinalTime(new_desired_final_time).IgnoreError();
Expand Down
Binary file modified ksp_plugin_adapter_stub/ksp_plugin_adapter_stub.dll
Binary file not shown.
Binary file modified ksp_plugin_adapter_stub/ksp_plugin_adapter_stub.pdb
Binary file not shown.
3 changes: 1 addition & 2 deletions ksp_plugin_test/flight_plan_optimizer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,7 @@ class MetricTest
EXPECT_OK(ephemeris_->Prolong(desired_final_time));
auto const earth_dof = solar_system_1950_.degrees_of_freedom("Earth");
auto const mars_dof = solar_system_1950_.degrees_of_freedom("Mars");
auto const midway = Barycentre<DegreesOfFreedom<Barycentric>, double>(
{earth_dof, mars_dof}, {1, 1});
auto const midway = Barycentre({earth_dof, mars_dof}, {1, 1});
EXPECT_OK(root_.Append(epoch_, midway));
flight_plan_ = std::make_unique<FlightPlan>(
/*initial_mass=*/1 * Kilogram,
Expand Down
15 changes: 5 additions & 10 deletions ksp_plugin_test/vessel_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ TEST_F(VesselTest, PrepareHistory) {
.Times(AnyNumber());
vessel_.CreateTrajectoryIfNeeded(t0_ + 1 * Second);

auto const expected_dof = Barycentre<DegreesOfFreedom<Barycentric>, Mass>(
{p1_dof_, p2_dof_}, {mass1_, mass2_});
auto const expected_dof = Barycentre({p1_dof_, p2_dof_}, {mass1_, mass2_});

EXPECT_EQ(1, vessel_.psychohistory()->size());
EXPECT_EQ(t0_ + 1 * Second,
Expand Down Expand Up @@ -253,8 +252,7 @@ TEST_F(VesselTest, AdvanceTime) {
vessel_.AdvanceTime();

auto const expected_vessel_psychohistory = NewLinearTrajectoryTimeline(
Barycentre<DegreesOfFreedom<Barycentric>, Mass>({p1_dof_, p2_dof_},
{mass1_, mass2_}),
Barycentre({p1_dof_, p2_dof_}, {mass1_, mass2_}),
/*Δt=*/0.5 * Second,
/*t1=*/t0_,
/*t2=*/t0_ + 1.1 * Second);
Expand Down Expand Up @@ -282,8 +280,7 @@ TEST_F(VesselTest, Prediction) {

// The call to fill the prognostication until t_max.
auto const expected_vessel_prediction = NewLinearTrajectoryTimeline(
Barycentre<DegreesOfFreedom<Barycentric>, Mass>({p1_dof_, p2_dof_},
{mass1_, mass2_}),
Barycentre({p1_dof_, p2_dof_}, {mass1_, mass2_}),
/*Δt=*/0.5 * Second,
/*t1=*/t0_,
/*t2=*/t0_ + 2 * Second);
Expand Down Expand Up @@ -332,8 +329,7 @@ TEST_F(VesselTest, PredictBeyondTheInfinite) {

// The call to fill the prognostication until t_max.
auto const expected_vessel_prediction1 = NewLinearTrajectoryTimeline(
Barycentre<DegreesOfFreedom<Barycentric>, Mass>({p1_dof_, p2_dof_},
{mass1_, mass2_}),
Barycentre({p1_dof_, p2_dof_}, {mass1_, mass2_}),
/*Δt=*/0.5 * Second,
/*t1=*/t0_,
/*t2=*/t0_ + 5.5 * Second);
Expand All @@ -346,8 +342,7 @@ TEST_F(VesselTest, PredictBeyondTheInfinite) {

// The call to extend the exphemeris by many points.
auto const expected_vessel_prediction2 = NewLinearTrajectoryTimeline(
Barycentre<DegreesOfFreedom<Barycentric>, Mass>({p1_dof_, p2_dof_},
{mass1_, mass2_}),
Barycentre({p1_dof_, p2_dof_}, {mass1_, mass2_}),
/*Δt=*/0.5 * Second,
/*t1=*/t0_ + 5.5 * Second,
/*t2=*/t0_ + FlightPlan::max_ephemeris_steps_per_frame * Second);
Expand Down
2 changes: 1 addition & 1 deletion mathematica/mathematica_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ std::string ToMathematicaBody(
OptionalExpressIn express_in) {
auto const& a = polynomial.lower_bound();
auto const& b = polynomial.upper_bound();
auto const midpoint = Barycentre(std::pair{a, b}, std::pair{0.5, 0.5});
auto const midpoint = Barycentre({a, b}, {0.5, 0.5});
std::string const argument = RawApply(
"Divide",
{RawApply("Subtract", {"#", ToMathematica(midpoint, express_in)}),
Expand Down
20 changes: 10 additions & 10 deletions numerics/apodization_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ PoissonSeries<double, 0, 0, Evaluator> Dirichlet(Instant const& t_min,
Instant const& t_max) {
using Result = PoissonSeries<double, 0, 0, Evaluator>;
using AperiodicPolynomial = typename Result::AperiodicPolynomial;
Instant const t_mid = Barycentre<Instant, double>({t_min, t_max}, {1, 1});
Instant const t_mid = Barycentre({t_min, t_max}, {1, 1});
return Result(AperiodicPolynomial({1}, t_mid), {});
}

Expand All @@ -40,7 +40,7 @@ PoissonSeries<double, 0, 0, Evaluator> Sine(Instant const& t_min,
using AperiodicPolynomial = typename Result::AperiodicPolynomial;
using PeriodicPolynomial = typename Result::PeriodicPolynomial;
AngularFrequency const ω = π * Radian / (t_max - t_min);
Instant const t_mid = Barycentre<Instant, double>({t_min, t_max}, {1, 1});
Instant const t_mid = Barycentre({t_min, t_max}, {1, 1});
return Result(AperiodicPolynomial({0}, t_mid),
{{ω,
{.sin = PeriodicPolynomial({0}, t_mid),
Expand All @@ -54,7 +54,7 @@ PoissonSeries<double, 0, 0, Evaluator> Hann(Instant const& t_min,
using AperiodicPolynomial = typename Result::AperiodicPolynomial;
using PeriodicPolynomial = typename Result::PeriodicPolynomial;
AngularFrequency const ω = 2 * π * Radian / (t_max - t_min);
Instant const t_mid = Barycentre<Instant, double>({t_min, t_max}, {1, 1});
Instant const t_mid = Barycentre({t_min, t_max}, {1, 1});
return Result(AperiodicPolynomial({0.5}, t_mid),
{{ω,
{.sin = PeriodicPolynomial({0}, t_mid),
Expand All @@ -68,7 +68,7 @@ PoissonSeries<double, 0, 0, Evaluator> Hamming(Instant const& t_min,
AngularFrequency const ω = 2 * π * Radian / (t_max - t_min);
using AperiodicPolynomial = typename Result::AperiodicPolynomial;
using PeriodicPolynomial = typename Result::PeriodicPolynomial;
Instant const t_mid = Barycentre<Instant, double>({t_min, t_max}, {1, 1});
Instant const t_mid = Barycentre({t_min, t_max}, {1, 1});
return Result(AperiodicPolynomial({25.0 / 46.0}, t_mid),
{{ω,
{.sin = PeriodicPolynomial({0}, t_mid),
Expand All @@ -82,7 +82,7 @@ PoissonSeries<double, 0, 0, Evaluator> Blackman(Instant const& t_min,
using AperiodicPolynomial = typename Result::AperiodicPolynomial;
using PeriodicPolynomial = typename Result::PeriodicPolynomial;
AngularFrequency const ω = 2 * π * Radian / (t_max - t_min);
Instant const t_mid = Barycentre<Instant, double>({t_min, t_max}, {1, 1});
Instant const t_mid = Barycentre({t_min, t_max}, {1, 1});
return Result(AperiodicPolynomial({0.42}, t_mid),
{{ω,
{.sin = PeriodicPolynomial({0}, t_mid),
Expand All @@ -99,7 +99,7 @@ PoissonSeries<double, 0, 0, Evaluator> ExactBlackman(Instant const& t_min,
using AperiodicPolynomial = typename Result::AperiodicPolynomial;
using PeriodicPolynomial = typename Result::PeriodicPolynomial;
AngularFrequency const ω = 2 * π * Radian / (t_max - t_min);
Instant const t_mid = Barycentre<Instant, double>({t_min, t_max}, {1, 1});
Instant const t_mid = Barycentre({t_min, t_max}, {1, 1});
return Result(AperiodicPolynomial({3969.0 / 9304.0}, t_mid),
{{ω,
{.sin = PeriodicPolynomial({0}, t_mid),
Expand All @@ -116,7 +116,7 @@ PoissonSeries<double, 0, 0, Evaluator> Nuttall(Instant const& t_min,
using AperiodicPolynomial = typename Result::AperiodicPolynomial;
using PeriodicPolynomial = typename Result::PeriodicPolynomial;
AngularFrequency const ω = 2 * π * Radian / (t_max - t_min);
Instant const t_mid = Barycentre<Instant, double>({t_min, t_max}, {1, 1});
Instant const t_mid = Barycentre({t_min, t_max}, {1, 1});
return Result(AperiodicPolynomial({0.355768}, t_mid),
{{ω,
{.sin = PeriodicPolynomial({0}, t_mid),
Expand All @@ -136,7 +136,7 @@ PoissonSeries<double, 0, 0, Evaluator> BlackmanNuttall(Instant const& t_min,
using AperiodicPolynomial = typename Result::AperiodicPolynomial;
using PeriodicPolynomial = typename Result::PeriodicPolynomial;
AngularFrequency const ω = 2 * π * Radian / (t_max - t_min);
Instant const t_mid = Barycentre<Instant, double>({t_min, t_max}, {1, 1});
Instant const t_mid = Barycentre({t_min, t_max}, {1, 1});
return Result(AperiodicPolynomial({0.3635819}, t_mid),
{{ω,
{.sin = PeriodicPolynomial({0}, t_mid),
Expand All @@ -156,7 +156,7 @@ PoissonSeries<double, 0, 0, Evaluator> BlackmanHarris(Instant const& t_min,
using AperiodicPolynomial = typename Result::AperiodicPolynomial;
using PeriodicPolynomial = typename Result::PeriodicPolynomial;
AngularFrequency const ω = 2 * π * Radian / (t_max - t_min);
Instant const t_mid = Barycentre<Instant, double>({t_min, t_max}, {1, 1});
Instant const t_mid = Barycentre({t_min, t_max}, {1, 1});
return Result(AperiodicPolynomial({0.35875}, t_mid),
{{ω,
{.sin = PeriodicPolynomial({0}, t_mid),
Expand All @@ -176,7 +176,7 @@ PoissonSeries<double, 0, 0, Evaluator> ISO18431_2(Instant const& t_min,
using AperiodicPolynomial = typename Result::AperiodicPolynomial;
using PeriodicPolynomial = typename Result::PeriodicPolynomial;
AngularFrequency const ω = 2 * π * Radian / (t_max - t_min);
Instant const t_mid = Barycentre<Instant, double>({t_min, t_max}, {1, 1});
Instant const t_mid = Barycentre({t_min, t_max}, {1, 1});
return Result(AperiodicPolynomial({1.0 / 4.63867187}, t_mid),
{{ω,
{.sin = PeriodicPolynomial({0}, t_mid),
Expand Down
2 changes: 1 addition & 1 deletion numerics/nearest_neighbour_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ PrincipalComponentPartitioningTree<Value_>::BuildTree(
// halfway between these points. Cost: 0.25 * N.
auto const mid_lower = std::max_element(begin, mid_upper, projection_less);

auto const anchor = Barycentre<Displacement, double>(
auto const anchor = Barycentre(
{displacements_[mid_lower->index], displacements_[mid_upper->index]},
{1, 1});

Expand Down
2 changes: 1 addition & 1 deletion numerics/newhall_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ NewhallApproximationInMonomialBasis(std::vector<Value> const& q,
qv[j + 1] = v[i] * duration_over_two;
}

Instant const t_mid = Barycentre<Instant, double>({t_min, t_max}, {1, 1});
Instant const t_mid = Barycentre({t_min, t_max}, {1, 1});
return origin +
Dehomogeneize<Difference<Value>, degree, Evaluator>(
NewhallMonomialApproximator<Difference<Value>, degree, Evaluator>::
Expand Down
4 changes: 2 additions & 2 deletions numerics/poisson_series_basis_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ std::array<Series, sizeof...(indices)> AperiodicSeriesGenerator<
degree, dimension,
std::index_sequence<indices...>>::BasisElements(Instant const& t_min,
Instant const& t_max) {
Instant const t_mid = Barycentre<Instant, double>({t_min, t_max}, {1, 1});
Instant const t_mid = Barycentre({t_min, t_max}, {1, 1});
return {(Series(
PolynomialGenerator<typename Series::AperiodicPolynomial,
dimension>::template UnitPolynomial<indices>(t_min,
Expand Down Expand Up @@ -221,7 +221,7 @@ std::array<Series, sizeof...(indices)> PeriodicSeriesGenerator<
std::index_sequence<indices...>>::BasisElements(AngularFrequency const& ω,
Instant const& t_min,
Instant const& t_max) {
Instant const t_mid = Barycentre<Instant, double>({t_min, t_max}, {1, 1});
Instant const t_mid = Barycentre({t_min, t_max}, {1, 1});
typename Series::AperiodicPolynomial const aperiodic_zero{{}, t_mid};
return {Series(
aperiodic_zero,
Expand Down
15 changes: 7 additions & 8 deletions numerics/root_finders_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ Argument Bisect(Function f,
Argument lower = lower_bound;
Argument upper = upper_bound;
for (;;) {
Argument const middle =
Barycentre<Argument, double>({lower, upper}, {1, 1});
Argument const middle = Barycentre({lower, upper}, {1, 1});
// The size of the interval has reached one ULP.
if (middle == lower || middle == upper) {
return middle;
Expand Down Expand Up @@ -170,12 +169,12 @@ Argument GoldenSectionSearch(Function f,
Argument lower = lower_bound;
Value f_lower = f(lower);

Argument lower_interior = Barycentre<Argument, double>(
{lower, upper}, {upper_interior_ratio, lower_interior_ratio});
Argument lower_interior =
Barycentre({lower, upper}, {upper_interior_ratio, lower_interior_ratio});
Value f_lower_interior = f(lower_interior);

Argument upper_interior = Barycentre<Argument, double>(
{lower, upper}, {lower_interior_ratio, upper_interior_ratio});
Argument upper_interior =
Barycentre({lower, upper}, {lower_interior_ratio, upper_interior_ratio});
Value f_upper_interior = f(upper_interior);

while (lower < lower_interior &&
Expand Down Expand Up @@ -206,7 +205,7 @@ Argument GoldenSectionSearch(Function f,
f_upper_interior = f(upper_interior);
}
}
return Barycentre<Argument, double>({lower, upper}, {1, 1});
return Barycentre({lower, upper}, {1, 1});
}

// The implementation is translated from the ALGOL 60 in [Bre73], chapter 5,
Expand Down Expand Up @@ -267,7 +266,7 @@ Argument Brent(Function f,
Difference<Argument> e{};
f_v = f_w = f_x = f(x);
for (;;) {
Argument const m = Barycentre<Argument, double>({a, b}, {1, 1});
Argument const m = Barycentre({a, b}, {1, 1});
Difference<Argument> const tol = eps * Abs(x - Argument{}) + t;
Difference<Argument> const t2 = 2 * tol;
// Check stopping criterion.
Expand Down
10 changes: 4 additions & 6 deletions physics/apsides_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,9 @@ void ComputeApsides(Trajectory<Frame> const& reference,
// Something went wrong when finding the extrema of
// |squared_distance_approximation|. Use a linear interpolation of
// |squared_distance_derivative| instead.
apsis_time = Barycentre<Instant, Variation<Square<Length>>>(
{time, *previous_time},
{*previous_squared_distance_derivative,
-squared_distance_derivative});
apsis_time = Barycentre({time, *previous_time},
{*previous_squared_distance_derivative,
-squared_distance_derivative});
}

// This can happen for instance if the square distance is stationary.
Expand Down Expand Up @@ -451,8 +450,7 @@ absl::Status ComputeNodes(
Sign(z_approximation.Evaluate(time))) {
// The Hermite approximation is poorly conditioned, let's use a linear
// approximation
node_time = Barycentre<Instant, Length>({*previous_time, time},
{z, -*previous_z});
node_time = Barycentre({*previous_time, time}, {z, -*previous_z});
} else {
// The normal case, find the intersection with z = 0 using Brent's
// method.
Expand Down
13 changes: 6 additions & 7 deletions physics/barycentric_rotating_reference_frame_body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@ BarycentricRotatingReferenceFrame<InertialFrame, ThisFrame>::MotionOfThisFrame(
orthonormal, 𝛛orthonormal, 𝛛²orthonormal);

Vector<Acceleration, InertialFrame> const acceleration_of_to_frame_origin =
Barycentre(std::pair{r̈₁, r̈₂},
std::pair{primary_gravitational_parameter_,
secondary_gravitational_parameter_});
Barycentre({r̈₁, r̈₂},
{primary_gravitational_parameter_,
secondary_gravitational_parameter_});
return AcceleratedRigidMotion<InertialFrame, ThisFrame>(
to_this_frame,
angular_acceleration_of_to_frame,
Expand Down Expand Up @@ -308,10 +308,9 @@ BarycentricRotatingReferenceFrame<InertialFrame, ThisFrame>::ToThisFrame(
angular_velocity);

DegreesOfFreedom<InertialFrame> const barycentre_degrees_of_freedom =
Barycentre(
std::pair{primary_degrees_of_freedom, secondary_degrees_of_freedom},
std::pair{primary_gravitational_parameter_,
secondary_gravitational_parameter_});
Barycentre({primary_degrees_of_freedom, secondary_degrees_of_freedom},
{primary_gravitational_parameter_,
secondary_gravitational_parameter_});
RigidTransformation<InertialFrame, ThisFrame> const rigid_transformation(
barycentre_degrees_of_freedom.position(),
ThisFrame::origin,
Expand Down
8 changes: 3 additions & 5 deletions physics/barycentric_rotating_reference_frame_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,9 @@ class BarycentricRotatingReferenceFrameTest : public ::testing::Test {
small_initial_state_(solar_system_.degrees_of_freedom(small)),
small_gravitational_parameter_(
solar_system_.gravitational_parameter(small)),
centre_of_mass_initial_state_(
Barycentre<DegreesOfFreedom<ICRS>, GravitationalParameter>(
{big_initial_state_, small_initial_state_},
{big_gravitational_parameter_,
small_gravitational_parameter_})) {
centre_of_mass_initial_state_(Barycentre(
{big_initial_state_, small_initial_state_},
{big_gravitational_parameter_, small_gravitational_parameter_})) {
EXPECT_OK(ephemeris_->Prolong(t0_ + 2 * period_));
big_small_frame_ = std::make_unique<
BarycentricRotatingReferenceFrame<ICRS, BigSmallFrame>>(
Expand Down
8 changes: 3 additions & 5 deletions physics/body_centred_body_direction_reference_frame_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,9 @@ TEST_F(BodyCentredBodyDirectionReferenceFrameTest, ConstructFromOneBody) {
ephemeris_->trajectory(big_)->EvaluateDegreesOfFreedom(t0_ + t);
auto const small_dof =
ephemeris_->trajectory(small_)->EvaluateDegreesOfFreedom(t0_ + t);
auto const barycentre =
Barycentre<DegreesOfFreedom<ICRS>, GravitationalParameter>(
{big_dof, small_dof},
{big_->gravitational_parameter(),
small_->gravitational_parameter()});
auto const barycentre = Barycentre(
{big_dof, small_dof},
{big_->gravitational_parameter(), small_->gravitational_parameter()});
EXPECT_THAT(barycentre.velocity().Norm(),
VanishesBefore(1 * Kilo(Metre) / Second, 0, 50));
EXPECT_OK(barycentre_trajectory.Append(t0_ + t, barycentre));
Expand Down
Loading

0 comments on commit b4c8333

Please sign in to comment.