Skip to content

Commit a4f09e7

Browse files
authored
Merge pull request #4211 from pleroy/Stuff
A bunch of improvement that were made while looking at plotting
2 parents b12f915 + b094f1a commit a4f09e7

18 files changed

+218
-65
lines changed

base/traits.hpp

+23
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,29 @@ struct other_type<T2, T1, T2> {
5151
using type = T1;
5252
};
5353

54+
template<typename... Ts>
55+
struct tail;
56+
57+
template<typename T>
58+
struct tail<T> {
59+
using type = T;
60+
static constexpr T value(T t) {
61+
return t;
62+
}
63+
};
64+
65+
template<typename T, typename... Ts>
66+
struct tail<T, Ts...> {
67+
using type = typename tail<Ts...>::type;
68+
static constexpr type value(T, Ts... ts) {
69+
return tail<Ts...>::value(ts...);
70+
}
71+
};
72+
5473
} // namespace internal
5574

5675
using internal::all_different_v;
76+
using internal::tail;
5777

5878
// True if and only if U is an instance of T.
5979
template<template<typename...> typename T, typename U>
@@ -79,6 +99,9 @@ inline constexpr bool is_same_template_v =
7999
template<typename T, typename T1, typename T2>
80100
using other_type_t = typename internal::other_type<T, T1, T2>::type;
81101

102+
template<typename... Ts>
103+
using tail_t = typename internal::tail<Ts...>::type;
104+
82105
} // namespace _traits
83106
} // namespace base
84107
} // namespace principia

benchmarks/planetarium_benchmark.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ void BM_PlanetariumPlotMethod3(
330330
satellites.goes_8_trajectory(),
331331
satellites.goes_8_trajectory().begin(),
332332
satellites.goes_8_trajectory().end(),
333-
now,
334333
/*t_max=*/InfiniteFuture,
335334
/*reverse=*/false,
336335
/*add_point=*/

geometry/conformal_map_body.hpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "geometry/homothecy.hpp"
66
#include "quantities/elementary_functions.hpp"
7+
#include "quantities/serialization.hpp"
78

89
namespace principia {
910
namespace geometry {
@@ -12,6 +13,7 @@ namespace internal {
1213

1314
using namespace principia::geometry::_homothecy;
1415
using namespace principia::quantities::_elementary_functions;
16+
using namespace principia::quantities::_serialization;
1517

1618
template<typename Scalar, typename FromFrame, typename ToFrame>
1719
Scalar ConformalMap<Scalar, FromFrame, ToFrame>::scale() const {
@@ -87,7 +89,8 @@ ConformalMap<Scalar, FromFrame, ToFrame>::ReadFromMessage(
8789
template<typename Scalar, typename FromFrame, typename ToFrame>
8890
void ConformalMap<Scalar, FromFrame, ToFrame>::WriteToMessage(
8991
not_null<serialization::ConformalMap*> const message) const {
90-
scale_.WriteToMessage(message->mutable_scale());
92+
DoubleOrQuantitySerializer<Scalar, serialization::ConformalMap>::
93+
WriteToMessage(scale_, message);
9194
quaternion_.WriteToMessage(message->mutable_quaternion());
9295
}
9396

@@ -96,8 +99,10 @@ ConformalMap<Scalar, FromFrame, ToFrame>
9699
ConformalMap<Scalar, FromFrame, ToFrame>::ReadFromMessage(
97100
serialization::ConformalMap const& message)
98101
requires serializable<FromFrame> && serializable<ToFrame> {
99-
return ConformalMap(Scalar::ReadFromMessage(message.scale()),
100-
Quaternion::ReadFromMessage(message.quaternion()));
102+
return ConformalMap(
103+
DoubleOrQuantitySerializer<Scalar, serialization::ConformalMap>::
104+
ReadFromMessage(message),
105+
Quaternion::ReadFromMessage(message.quaternion()));
101106
}
102107

103108
template<typename Scalar, typename FromFrame, typename ToFrame>

geometry/grassmann_body.hpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -337,21 +337,16 @@ Vector<Product<LScalar, RScalar>, Frame> operator*(
337337
Cross(left.coordinates(), right.coordinates()));
338338
}
339339

340-
// Implementation from [Kah06], §12 "Mangled Angles", p. 47.
341340
template<typename LScalar, typename RScalar, typename Frame>
342341
Angle AngleBetween(Vector<LScalar, Frame> const& v,
343342
Vector<RScalar, Frame> const& w) {
344-
auto const v_norm_w = v * w.Norm();
345-
auto const w_norm_v = w * v.Norm();
346-
return 2 * ArcTan((v_norm_w - w_norm_v).Norm(), (v_norm_w + w_norm_v).Norm());
343+
return AngleBetween(v.coordinates(), w.coordinates());
347344
}
348345

349346
template<typename LScalar, typename RScalar, typename Frame>
350347
Angle AngleBetween(Bivector<LScalar, Frame> const& v,
351348
Bivector<RScalar, Frame> const& w) {
352-
auto const v_norm_w = v * w.Norm();
353-
auto const w_norm_v = w * v.Norm();
354-
return 2 * ArcTan((v_norm_w - w_norm_v).Norm(), (v_norm_w + w_norm_v).Norm());
349+
return AngleBetween(v.coordinates(), w.coordinates());
355350
}
356351

357352
template<typename LScalar, typename RScalar, typename PScalar, typename Frame>

geometry/r3_element.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,18 @@ template<typename LScalar, typename RScalar>
210210
Product<LScalar, RScalar> Dot(R3Element<LScalar> const& left,
211211
R3Element<RScalar> const& right);
212212

213+
// The result is in [0, π]; the function is commutative.
214+
template<typename LScalar, typename RScalar>
215+
Angle AngleBetween(R3Element<LScalar> const& left,
216+
R3Element<RScalar> const& right);
217+
213218
// Returns the `i`th basis vector, whose `i`th coordinate is 1, and whose
214219
// other coordinates are 0. `i` must be in [0, 2].
215220
R3Element<double> BasisVector(int i);
216221

217222
} // namespace internal
218223

224+
using internal::AngleBetween;
219225
using internal::BasisVector;
220226
using internal::Cross;
221227
using internal::Dot;

geometry/r3_element_body.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,16 @@ Product<LScalar, RScalar> Dot(R3Element<LScalar> const& left,
486486
return left.x * right.x + left.y * right.y + left.z * right.z;
487487
}
488488

489+
// Implementation from [Kah06], §12 "Mangled Angles", p. 47.
490+
template<typename LScalar, typename RScalar>
491+
Angle AngleBetween(R3Element<LScalar> const& left,
492+
R3Element<RScalar> const& right) {
493+
auto const left_norm_right = left * right.Norm();
494+
auto const right_norm_left = right * left.Norm();
495+
return 2 * ArcTan((left_norm_right - right_norm_left).Norm(),
496+
(left_norm_right + right_norm_left).Norm());
497+
}
498+
489499
inline R3Element<double> BasisVector(int const i) {
490500
DCHECK_GE(i, 0) << i;
491501
DCHECK_LT(i, 3) << i;

geometry/space_transformations.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ using Similarity =
3030

3131
} // namespace internal
3232

33+
using internal::DoubleConformalMap;
3334
using internal::RigidTransformation;
3435
using internal::Similarity;
3536

ksp_plugin/interface_planetarium.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ void __cdecl principia__PlanetariumPlotFlightPlanSegment(
155155
*segment,
156156
segment->begin(),
157157
segment->end(),
158-
plugin->CurrentTime(),
159158
t_max == nullptr ? InfiniteFuture : FromGameTime(*plugin, *t_max),
160159
/*reverse=*/false,
161160
[vertices, vertex_count](ScaledSpacePoint const& vertex) {
@@ -188,7 +187,6 @@ void __cdecl principia__PlanetariumPlotPrediction(
188187
*prediction,
189188
prediction->begin(),
190189
prediction->end(),
191-
plugin->CurrentTime(),
192190
t_max == nullptr ? InfiniteFuture : FromGameTime(*plugin, *t_max),
193191
/*reverse=*/false,
194192
[vertices, vertex_count](ScaledSpacePoint const& vertex) {
@@ -245,7 +243,6 @@ void __cdecl principia__PlanetariumPlotPsychohistory(
245243
trajectory,
246244
trajectory.lower_bound(desired_first_time),
247245
psychohistory->end(),
248-
/*now=*/plugin->CurrentTime(),
249246
t_max == nullptr ? InfiniteFuture : FromGameTime(*plugin, *t_max),
250247
/*reverse=*/true,
251248
[vertices, vertex_count](ScaledSpacePoint const& vertex) {
@@ -303,7 +300,6 @@ void __cdecl principia__PlanetariumPlotCelestialPastTrajectory(
303300
celestial_trajectory,
304301
first_time,
305302
/*last_time=*/plugin->CurrentTime(),
306-
/*now=*/plugin->CurrentTime(),
307303
/*reverse=*/true,
308304
[vertices, vertex_count](ScaledSpacePoint const& vertex) {
309305
vertices[(*vertex_count)++] = vertex;
@@ -362,7 +358,6 @@ void __cdecl principia__PlanetariumPlotCelestialFutureTrajectory(
362358
celestial_trajectory,
363359
/*first_time=*/plugin->CurrentTime(),
364360
/*last_time=*/final_time,
365-
/*now=*/plugin->CurrentTime(),
366361
/*reverse=*/false,
367362
[vertices, vertex_count](ScaledSpacePoint const& vertex) {
368363
vertices[(*vertex_count)++] = vertex;
@@ -401,7 +396,6 @@ void __cdecl principia__PlanetariumPlotEquipotential(
401396
equipotential,
402397
equipotential.front().time,
403398
equipotential.back().time,
404-
plugin->CurrentTime(),
405399
/*reverse=*/false,
406400
[vertices, vertex_count](ScaledSpacePoint const& vertex) {
407401
vertices[(*vertex_count)++] = vertex;

ksp_plugin/planetarium.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,6 @@ void Planetarium::PlotMethod3(
269269
Trajectory<Barycentric> const& trajectory,
270270
DiscreteTrajectory<Barycentric>::iterator begin,
271271
DiscreteTrajectory<Barycentric>::iterator end,
272-
Instant const& now,
273272
Instant const& t_max,
274273
bool const reverse,
275274
std::function<void(ScaledSpacePoint const&)> const& add_point,
@@ -282,7 +281,7 @@ void Planetarium::PlotMethod3(
282281
auto const last_time =
283282
std::min({last->time, plotting_frame_->t_max(), t_max});
284283
PlotMethod3(
285-
trajectory, begin_time, last_time, now, reverse, add_point, max_points);
284+
trajectory, begin_time, last_time, reverse, add_point, max_points);
286285
}
287286

288287
std::vector<Sphere<Navigation>> Planetarium::ComputePlottableSpheres(

ksp_plugin/planetarium.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ class Planetarium {
130130
Trajectory<Barycentric> const& trajectory,
131131
DiscreteTrajectory<Barycentric>::iterator begin,
132132
DiscreteTrajectory<Barycentric>::iterator end,
133-
Instant const& now,
134133
Instant const& t_max,
135134
bool reverse,
136135
std::function<void(ScaledSpacePoint const&)> const& add_point,
@@ -143,7 +142,6 @@ class Planetarium {
143142
Trajectory<Frame> const& trajectory,
144143
Instant const& first_time,
145144
Instant const& last_time,
146-
Instant const& now,
147145
bool reverse,
148146
std::function<void(ScaledSpacePoint const&)> const& add_point,
149147
int max_points,

ksp_plugin/planetarium_body.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ void Planetarium::PlotMethod3(
5353
Trajectory<Frame> const& trajectory,
5454
Instant const& first_time,
5555
Instant const& last_time,
56-
Instant const& now,
5756
bool const reverse,
5857
std::function<void(ScaledSpacePoint const&)> const& add_point,
5958
int const max_points,

0 commit comments

Comments
 (0)