From 449f3cf6eb77df67cf4e1db0231fba1b786c7b1e Mon Sep 17 00:00:00 2001 From: pleroy Date: Mon, 13 Apr 2020 10:20:14 +0200 Subject: [PATCH 1/4] Typos, formatting, locking. --- ksp_plugin/pile_up.cpp | 3 ++- ksp_plugin/plugin.cpp | 4 ++-- ksp_plugin_adapter/ksp_plugin_adapter.cs | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ksp_plugin/pile_up.cpp b/ksp_plugin/pile_up.cpp index d54837312b..a01ba7c714 100644 --- a/ksp_plugin/pile_up.cpp +++ b/ksp_plugin/pile_up.cpp @@ -111,6 +111,7 @@ Status PileUp::DeformAndAdvanceTime(Instant const& t) { } void PileUp::RecomputeFromParts() { + absl::MutexLock l(lock_.get()); mass_ = Mass(); intrinsic_force_ = Vector(); intrinsic_torque_ = Bivector(); @@ -432,7 +433,7 @@ void PileUp::DeformPileUpIfNeeded(Instant const& t) { // In the |EquivalentRigidPileUp| reference frame, a rigid body with the same // inertia and angular momentum as the pile up would be immobile. We use this // intermediate frame to apply a rigid rotational correction to the motions of - // the part coming from the game (the apparent motions) so as to enforce the + // the parts coming from the game (the apparent motions) so as to enforce the // conservation of the angular momentum (|angular_momentum_| is // authoritative). using EquivalentRigidPileUp = Frame; diff --git a/ksp_plugin/plugin.cpp b/ksp_plugin/plugin.cpp index 28e3a2d3b4..3dde2081e7 100644 --- a/ksp_plugin/plugin.cpp +++ b/ksp_plugin/plugin.cpp @@ -461,8 +461,8 @@ void Plugin::InsertOrKeepLoadedPart( main_body_frame.ToThisFrameAtTime(previous_time).orthogonal_map() * Δplanetarium_rotation.Inverse() * renderer_->WorldToBarycentric(PlanetariumRotation())}, - (renderer_->BarycentricToWorld(PlanetariumRotation()) * - Δplanetarium_rotation)(-angular_velocity_of_world_), + (renderer_->BarycentricToWorld(PlanetariumRotation()) * + Δplanetarium_rotation)(-angular_velocity_of_world_), main_body_degrees_of_freedom.velocity()}; RigidMotion const world_to_barycentric_motion = main_body_frame.FromThisFrameAtTime(previous_time) * diff --git a/ksp_plugin_adapter/ksp_plugin_adapter.cs b/ksp_plugin_adapter/ksp_plugin_adapter.cs index 6e37f723e3..3c4c2f9134 100644 --- a/ksp_plugin_adapter/ksp_plugin_adapter.cs +++ b/ksp_plugin_adapter/ksp_plugin_adapter.cs @@ -1522,11 +1522,11 @@ private void JaiFailliAttendre() { physical_parent, new Part.ForceHolder { force = -part.dragVectorDir * part.dragScalar, - pos = (physical_parent != part && - PhysicsGlobals.ApplyDragToNonPhysicsPartsAtParentCoM) + pos = (physical_parent != part && PhysicsGlobals. + ApplyDragToNonPhysicsPartsAtParentCoM) ? physical_parent.rb.worldCenterOfMass : part.partTransform.TransformPoint( - part.CoPOffset)}); + part.CoPOffset)}); } } } From 3839c87d308bd32ba5fe0fd98976af288d0bee56 Mon Sep 17 00:00:00 2001 From: pleroy Date: Mon, 13 Apr 2020 12:10:46 +0200 Subject: [PATCH 2/4] Correct name for an interface method. --- ksp_plugin/interface_part.cpp | 4 ++-- ksp_plugin_adapter/ksp_plugin_adapter.cs | 4 ++-- serialization/journal.proto | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ksp_plugin/interface_part.cpp b/ksp_plugin/interface_part.cpp index 7c2f0b9c32..2e407388d8 100644 --- a/ksp_plugin/interface_part.cpp +++ b/ksp_plugin/interface_part.cpp @@ -71,11 +71,11 @@ void __cdecl principia__PartApplyIntrinsicTorque( return m.Return(); } -QPRW __cdecl principia__PartGetActualDegreesOfFreedom( +QPRW __cdecl principia__PartGetActualRigidMotion( Plugin const* const plugin, PartId const part_id, Origin const origin) { - journal::Method m( + journal::Method m( {plugin, part_id, origin}); CHECK_NOTNULL(plugin); RigidMotion const part_motion = plugin->GetPartActualMotion( diff --git a/ksp_plugin_adapter/ksp_plugin_adapter.cs b/ksp_plugin_adapter/ksp_plugin_adapter.cs index 3c4c2f9134..407e84c2ac 100644 --- a/ksp_plugin_adapter/ksp_plugin_adapter.cs +++ b/ksp_plugin_adapter/ksp_plugin_adapter.cs @@ -436,7 +436,7 @@ private void UpdateVessel(Vessel vessel, double universal_time) { // TODO(egg): check that the vessel is moved *after* this. Shouldn't // we be calling vessel.orbitDriver.updateFromParameters() after // setting the orbit anyway? - QPRW part_actual_motion = plugin_.PartGetActualDegreesOfFreedom( + QPRW part_actual_motion = plugin_.PartGetActualRigidMotion( part.flightID, new Origin{ reference_part_is_at_origin = true, @@ -1275,7 +1275,7 @@ private System.Collections.IEnumerator WaitedForFixedUpdate() { continue; } QPRW part_actual_motion = - plugin_.PartGetActualDegreesOfFreedom( + plugin_.PartGetActualRigidMotion( part.flightID, new Origin{ reference_part_is_at_origin = diff --git a/serialization/journal.proto b/serialization/journal.proto index 3025266c8d..4a582b4074 100644 --- a/serialization/journal.proto +++ b/serialization/journal.proto @@ -1559,9 +1559,9 @@ message PartApplyIntrinsicTorque { optional In in = 1; } -message PartGetActualDegreesOfFreedom { +message PartGetActualRigidMotion { extend Method { - optional PartGetActualDegreesOfFreedom extension = 5116; + optional PartGetActualRigidMotion extension = 5116; } message In { required fixed64 plugin = 1 [(pointer_to) = "Plugin const", From 838ab31bf976aa60f7278bad8e3dc10b0282f385 Mon Sep 17 00:00:00 2001 From: pleroy Date: Mon, 13 Apr 2020 18:25:10 +0200 Subject: [PATCH 3/4] Mathematica improvements. --- mathematica/mathematica.hpp | 8 ++++++++ mathematica/mathematica_body.hpp | 13 ++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/mathematica/mathematica.hpp b/mathematica/mathematica.hpp index 4299a61501..4b400e6613 100644 --- a/mathematica/mathematica.hpp +++ b/mathematica/mathematica.hpp @@ -8,6 +8,7 @@ #include "astronomy/orbital_elements.hpp" #include "geometry/grassmann.hpp" #include "geometry/point.hpp" +#include "geometry/quaternion.hpp" #include "geometry/r3_element.hpp" #include "numerics/fixed_arrays.hpp" #include "physics/degrees_of_freedom.hpp" @@ -18,7 +19,9 @@ namespace principia { namespace mathematica { namespace internal_mathematica { +using geometry::Bivector; using geometry::Point; +using geometry::Quaternion; using geometry::R3Element; using geometry::Vector; using numerics::FixedVector; @@ -55,9 +58,14 @@ std::string ToMathematica(FixedVector const& fixed_vector); template std::string ToMathematica(R3Element const& r3_element); +std::string ToMathematica(Quaternion const& quaternion); + template std::string ToMathematica(Quantity const& quantity); +template +std::string ToMathematica(Bivector const& bivector); + template std::string ToMathematica(Vector const& vector); diff --git a/mathematica/mathematica_body.hpp b/mathematica/mathematica_body.hpp index 087aad5d00..65d94e379a 100644 --- a/mathematica/mathematica_body.hpp +++ b/mathematica/mathematica_body.hpp @@ -49,8 +49,9 @@ inline std::string Apply( result += "["; for (int i = 0; i < arguments.size(); ++i) { result += arguments[i]; - result += (i + 1 == arguments.size() ? "]" : ","); + result += (i < arguments.size() - 1 ? "," : ""); } + result += "]"; return result; } @@ -105,6 +106,11 @@ inline std::string ToMathematica(double const& real) { } } +inline std::string ToMathematica(Quaternion const& quaternion) { + return ToMathematica>( + {quaternion.real_part(), quaternion.imaginary_part()}); +} + template std::string ToMathematica(FixedVector const & fixed_vector) { std::vector expressions; @@ -137,6 +143,11 @@ std::string ToMathematica(Quantity const& quantity) { {Apply("Quantity", {number, units}), "$MachinePrecision"}); } +template +std::string ToMathematica(Bivector const& bivector) { + return ToMathematica(bivector.coordinates()); +} + template std::string ToMathematica(Vector const & vector) { return ToMathematica(vector.coordinates()); From add6a85c3818adb9296b9a0254c0836a6bc990d7 Mon Sep 17 00:00:00 2001 From: pleroy Date: Wed, 22 Apr 2020 20:25:30 +0200 Subject: [PATCH 4/4] After egg's review. --- mathematica/mathematica_body.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mathematica/mathematica_body.hpp b/mathematica/mathematica_body.hpp index 65d94e379a..67247221fc 100644 --- a/mathematica/mathematica_body.hpp +++ b/mathematica/mathematica_body.hpp @@ -49,7 +49,7 @@ inline std::string Apply( result += "["; for (int i = 0; i < arguments.size(); ++i) { result += arguments[i]; - result += (i < arguments.size() - 1 ? "," : ""); + result += (i + 1 < arguments.size() ? "," : ""); } result += "]"; return result;