From f115b2830891f38c665ff32449b5744ed2ac892e Mon Sep 17 00:00:00 2001 From: leftler Date: Fri, 19 Dec 2014 23:34:10 -0600 Subject: [PATCH 1/5] Changed GetPositionFromGuid to return a nullabe Vector3d and modified the two places that currently call it to handle the null value instead of handling a exception. --- src/RemoteTech/NetworkManager.cs | 12 +++++------- src/RemoteTech/NetworkRenderer.cs | 10 +++++++++- .../RangeModel/RangeModelExtensions.cs | 16 ++++++++++------ 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/RemoteTech/NetworkManager.cs b/src/RemoteTech/NetworkManager.cs index 6032db30b..19f165fd5 100644 --- a/src/RemoteTech/NetworkManager.cs +++ b/src/RemoteTech/NetworkManager.cs @@ -208,15 +208,13 @@ IEnumerator IEnumerable.GetEnumerator() } /// Gets the position of a RemoteTech target from its id - /// The absolute position. + /// The absolute position or null if is neither + /// a satellite nor a celestial body. /// The id of the satellite or celestial body whose position is - /// desired. May be the active vessel Guid. - /// - /// Thrown if is neither - /// a satellite nor a celestial body. + /// desired. May be the active vessel Guid. /// /// The program state is unchanged in the event of an exception. - internal Vector3d GetPositionFromGuid(Guid targetable) + internal Vector3d? GetPositionFromGuid(Guid targetable) { ISatellite targetSat = this[targetable]; if (targetSat != null) { @@ -227,7 +225,7 @@ internal Vector3d GetPositionFromGuid(Guid targetable) return Planets[targetable].position; } - throw new ArgumentException("Guid is neither a satellite nor a celestial body: ", "targetable"); + return null; } } diff --git a/src/RemoteTech/NetworkRenderer.cs b/src/RemoteTech/NetworkRenderer.cs index 815221f9a..5d4364d11 100644 --- a/src/RemoteTech/NetworkRenderer.cs +++ b/src/RemoteTech/NetworkRenderer.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Collections.Generic; using UnityEngine; +using Debug = System.Diagnostics.Debug; namespace RemoteTech { @@ -111,9 +112,16 @@ private void UpdateNetworkCones() mCones[i].Material = MapView.fetch.orbitLinesMaterial; mCones[i].LineWidth = 2.0f; mCones[i].Antenna = antennas[i]; - mCones[i].Center = RTCore.Instance.Network.GetPositionFromGuid(antennas[i].Target); mCones[i].Color = Color.gray; mCones[i].Active = ShowCone; + + var center = RTCore.Instance.Network.GetPositionFromGuid(antennas[i].Target); + Debug.Assert(center != null, + "center != null", + String.Format("GetPositionFromGuid retuned a null value for the target {0}", + antennas[i].Target) + ); + mCones[i].Center = center.Value; } } diff --git a/src/RemoteTech/RangeModel/RangeModelExtensions.cs b/src/RemoteTech/RangeModel/RangeModelExtensions.cs index 4a60c33d9..00caf2651 100644 --- a/src/RemoteTech/RangeModel/RangeModelExtensions.cs +++ b/src/RemoteTech/RangeModel/RangeModelExtensions.cs @@ -46,17 +46,21 @@ public static bool IsInFieldOfView(this IAntenna dish, ISatellite target, ISatel return false; } - try { - Vector3d coneCenter = RTCore.Instance.Network.GetPositionFromGuid(dish.Target); + Vector3d? coneCenter = RTCore.Instance.Network.GetPositionFromGuid(dish.Target); - Vector3d dirToConeCenter = (coneCenter - antennaSat.Position); - Vector3d dirToTarget = (target.Position - antennaSat.Position); + if (coneCenter.HasValue) + { + Vector3d dirToConeCenter = (coneCenter.Value - antennaSat.Position); + Vector3d dirToTarget = (target.Position - antennaSat.Position); return (Vector3d.Dot(dirToConeCenter.normalized, dirToTarget.normalized) >= dish.CosAngle); - } catch (ArgumentException e) { - RTLog.Notify("Unexpected dish target: {0}", e); + } + else + { + RTLog.Notify("Unexpected dish target: {0}", dish.Target); return false; } + } /// Finds the distance between two ISatellites From a48609645c7f7414b33f12a6d627b7713f56c22e Mon Sep 17 00:00:00 2001 From: Dennis Date: Sun, 21 Dec 2014 10:36:55 +0100 Subject: [PATCH 2/5] Force travis to build as release mode --- build.remotetech.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.remotetech.sh b/build.remotetech.sh index 4dfd46602..4b3b2eae8 100755 --- a/build.remotetech.sh +++ b/build.remotetech.sh @@ -32,5 +32,5 @@ then rm -f dlls.zip fi -cd src/RemoteTech && xbuild +cd src/RemoteTech && xbuild /p:Configuration=Release From cd2a8b9f6a9a20dda071b87b6b6b4ccd89ba159c Mon Sep 17 00:00:00 2001 From: Dennis Date: Tue, 23 Dec 2014 16:46:54 +0100 Subject: [PATCH 3/5] Changed Statebuttons to buttons on AttitudeFragment Feature task resolves #212 --- src/RemoteTech/UI/AttitudeFragment.cs | 69 ++++++++++++--------------- 1 file changed, 31 insertions(+), 38 deletions(-) diff --git a/src/RemoteTech/UI/AttitudeFragment.cs b/src/RemoteTech/UI/AttitudeFragment.cs index 713a1514c..6d28d3a70 100644 --- a/src/RemoteTech/UI/AttitudeFragment.cs +++ b/src/RemoteTech/UI/AttitudeFragment.cs @@ -1,4 +1,6 @@ using System; +using System.Collections; +using System.Collections.Generic; using UnityEngine; namespace RemoteTech @@ -124,47 +126,34 @@ public void Draw() { GUILayout.BeginHorizontal(); { - RTUtil.StateButton(new GUIContent("KILL", "Kill rotation."), - (int)mMode, (int)ComputerMode.Kill, OnModeClick, GUILayout.Width(width3)); - RTUtil.StateButton(new GUIContent("NODE", "Prograde points in the direction of the first maneuver node."), - (int)mMode, (int)ComputerMode.Node, OnModeClick, GUILayout.Width(width3)); - RTUtil.StateButton(new GUIContent("RVEL", "Prograde relative to target velocity."), - (int)mMode, (int)ComputerMode.TargetVel, OnModeClick, GUILayout.Width(width3)); + RTUtil.Button(new GUIContent("KILL", "Kill rotation."), () => RTCore.Instance.StartCoroutine(OnModeClick(ComputerMode.Kill)), GUILayout.Width(width3)); + RTUtil.Button(new GUIContent("NODE", "Prograde points in the direction of the first maneuver node."), () => RTCore.Instance.StartCoroutine(OnModeClick(ComputerMode.Node)), GUILayout.Width(width3)); + RTUtil.Button(new GUIContent("RVEL", "Prograde relative to target velocity."), () => RTCore.Instance.StartCoroutine(OnModeClick(ComputerMode.TargetVel)), GUILayout.Width(width3)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { - RTUtil.StateButton(new GUIContent("ORB", "Prograde relative to orbital velocity."), - (int)mMode, (int)ComputerMode.Orbital, OnModeClick, GUILayout.Width(width3)); - RTUtil.StateButton(new GUIContent("SRF", "Prograde relative to surface velocity."), - (int)mMode, (int)ComputerMode.Surface, OnModeClick, GUILayout.Width(width3)); - RTUtil.StateButton(new GUIContent("TGT", "Prograde points directly at target."), - (int)mMode, (int)ComputerMode.TargetPos, OnModeClick, GUILayout.Width(width3)); + RTUtil.Button(new GUIContent("ORB", "Prograde relative to orbital velocity."), () => RTCore.Instance.StartCoroutine(OnModeClick(ComputerMode.Orbital)), GUILayout.Width(width3)); + RTUtil.Button(new GUIContent("SRF", "Prograde relative to surface velocity."), () => RTCore.Instance.StartCoroutine(OnModeClick(ComputerMode.Surface)), GUILayout.Width(width3)); + RTUtil.Button(new GUIContent("TGT", "Prograde points directly at target."), () => RTCore.Instance.StartCoroutine(OnModeClick(ComputerMode.TargetPos)), GUILayout.Width(width3)); } GUILayout.EndHorizontal(); - RTUtil.StateButton(new GUIContent("CUSTOM", "Prograde fixed as pitch, heading, roll relative to north pole."), - (int)mMode, (int)ComputerMode.Custom, OnModeClick, GUILayout.ExpandWidth(true)); + RTUtil.Button(new GUIContent("CUSTOM", "Prograde fixed as pitch, heading, roll relative to north pole."), () => RTCore.Instance.StartCoroutine(OnModeClick(ComputerMode.Custom)), GUILayout.ExpandWidth(true)); GUILayout.Space(5); GUILayout.BeginHorizontal(); { - RTUtil.StateButton(new GUIContent("GRD\n+", "Orient to Prograde."), - (int)mAttitude, (int)FlightAttitude.Prograde, OnAttitudeClick, GUILayout.Width(width3)); - RTUtil.StateButton(new GUIContent("RAD\n+", "Orient to Radial."), - (int)mAttitude, (int)FlightAttitude.RadialPlus, OnAttitudeClick, GUILayout.Width(width3)); - RTUtil.StateButton(new GUIContent("NRM\n+", "Orient to Normal."), - (int)mAttitude, (int)FlightAttitude.NormalPlus, OnAttitudeClick, GUILayout.Width(width3)); + RTUtil.Button(new GUIContent("GRD\n+", "Orient to Prograde."), () => RTCore.Instance.StartCoroutine(OnAttitudeClick(FlightAttitude.Prograde)), GUILayout.Width(width3)); + RTUtil.Button(new GUIContent("RAD\n+", "Orient to Radial."), () => RTCore.Instance.StartCoroutine(OnAttitudeClick(FlightAttitude.RadialPlus)), GUILayout.Width(width3)); + RTUtil.Button(new GUIContent("NRM\n+", "Orient to Normal."), () => RTCore.Instance.StartCoroutine(OnAttitudeClick(FlightAttitude.NormalPlus)), GUILayout.Width(width3)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { - RTUtil.StateButton(new GUIContent("GRD\n-", "Orient to Retrograde."), - (int)mAttitude, (int)FlightAttitude.Retrograde, OnAttitudeClick, GUILayout.Width(width3)); - RTUtil.StateButton(new GUIContent("RAD\n-", "Orient to Anti-radial."), - (int)mAttitude, (int)FlightAttitude.RadialMinus, OnAttitudeClick, GUILayout.Width(width3)); - RTUtil.StateButton(new GUIContent("NRM\n-", "Orient to Anti-normal."), - (int)mAttitude, (int)FlightAttitude.NormalMinus, OnAttitudeClick, GUILayout.Width(width3)); + RTUtil.Button(new GUIContent("GRD\n-", "Orient to Retrograde."), () => RTCore.Instance.StartCoroutine(OnAttitudeClick(FlightAttitude.Retrograde)), GUILayout.Width(width3)); + RTUtil.Button(new GUIContent("RAD\n-", "Orient to Anti-radial."), () => RTCore.Instance.StartCoroutine(OnAttitudeClick(FlightAttitude.RadialMinus)), GUILayout.Width(width3)); + RTUtil.Button(new GUIContent("NRM\n-", "Orient to Anti-normal."), () => RTCore.Instance.StartCoroutine(OnAttitudeClick(FlightAttitude.NormalMinus)), GUILayout.Width(width3)); } GUILayout.EndHorizontal(); GUILayout.Space(5); @@ -227,24 +216,28 @@ public void Draw() // Called by RTUtil.Button // General-purpose function has to represent enums as integers - private void OnModeClick(int state) + private IEnumerator OnModeClick(ComputerMode state) { - if (!mFlightComputer.InputAllowed) - return; - mMode = (state < 0) ? ComputerMode.Off : (ComputerMode)state; - Confirm(); + yield return null; + if (mFlightComputer.InputAllowed) + { + mMode = (state < 0) ? ComputerMode.Off : state; + Confirm(); + } } - private void OnAttitudeClick(int state) + private IEnumerator OnAttitudeClick(FlightAttitude state) { - if (!mFlightComputer.InputAllowed) - return; - mAttitude = (state < 0) ? FlightAttitude.Null : (FlightAttitude)state; - if (mMode == ComputerMode.Off || mMode == ComputerMode.Kill || mMode == ComputerMode.Node) + yield return null; + if (mFlightComputer.InputAllowed) { - mMode = ComputerMode.Orbital; + mAttitude = (state < 0) ? FlightAttitude.Null : state; + if (mMode == ComputerMode.Off || mMode == ComputerMode.Kill || mMode == ComputerMode.Node) + { + mMode = ComputerMode.Orbital; + } + Confirm(); } - Confirm(); } private void Confirm() From 35657d374e265d3f3ffb0ba4c0f63c1fa1b890ed Mon Sep 17 00:00:00 2001 From: Chris Woerz Date: Tue, 6 Jan 2015 22:58:24 -0700 Subject: [PATCH 4/5] we now have a debug build --- src/RemoteTech/Modules/ModuleSPU.cs | 3 +-- src/RemoteTech/NetworkManager.cs | 23 +++++++---------------- src/RemoteTech/RemoteTech.sln | 8 +++++--- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/RemoteTech/Modules/ModuleSPU.cs b/src/RemoteTech/Modules/ModuleSPU.cs index 938fe0dc4..b76bab9ec 100644 --- a/src/RemoteTech/Modules/ModuleSPU.cs +++ b/src/RemoteTech/Modules/ModuleSPU.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using UnityEngine; namespace RemoteTech @@ -26,7 +25,7 @@ public bool IsCommandStation } public FlightComputer FlightComputer { get; private set; } public Vessel Vessel { get { return vessel; } } - public bool IsMaster { get { return Satellite != null && Satellite.SignalProcessor == (ISignalProcessor) this; } } + public bool IsMaster { get { return Satellite != null && Satellite.SignalProcessor == this; } } private VesselSatellite Satellite { get { return RTCore.Instance.Satellites[mRegisteredId]; } } diff --git a/src/RemoteTech/NetworkManager.cs b/src/RemoteTech/NetworkManager.cs index 773ba6f30..7c69ea2b4 100644 --- a/src/RemoteTech/NetworkManager.cs +++ b/src/RemoteTech/NetworkManager.cs @@ -1,7 +1,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using UnityEngine; @@ -119,14 +118,7 @@ public IEnumerable> FindNeighbors(ISatellite s) private void UpdateGraph(ISatellite a) { - var result = new List>(); - - foreach (ISatellite b in this) - { - var link = GetLink(a, b); - if (link == null) continue; - result.Add(link); - } + var result = this.Select(b => GetLink(a, b)).Where(link => link != null).ToList(); // Send events for removed edges foreach (var link in Graph[a.Guid].Except(result)) @@ -152,11 +144,10 @@ public static NetworkLink GetLink(ISatellite sat_a, ISatellite sat_b switch (RTSettings.Instance.RangeModelType) { - default: - case RangeModel.Standard: // Stock range model - return RangeModelStandard.GetLink(sat_a, sat_b); case RangeModel.Additive: // NathanKell return RangeModelRoot.GetLink(sat_a, sat_b); + default: // Stock range model + return RangeModelStandard.GetLink(sat_a, sat_b); } } @@ -239,12 +230,12 @@ public sealed class MissionControlSatellite : ISatellite, IPersistenceLoad [Persistent] private double Height = 75.0f; [Persistent] private int Body = 1; [Persistent] private Color MarkColor = new Color(0.996078f, 0, 0, 1); - [Persistent(collectionIndex = "ANTENNA")] private MissionControlAntenna[] Antennas = new MissionControlAntenna[] { new MissionControlAntenna() }; + [Persistent(collectionIndex = "ANTENNA")] private MissionControlAntenna[] Antennas = { new MissionControlAntenna() }; bool ISatellite.Powered { get { return true; } } bool ISatellite.Visible { get { return true; } } String ISatellite.Name { get { return Name; } set { Name = value; } } - Guid ISatellite.Guid { get { return this.mGuid; } } + Guid ISatellite.Guid { get { return mGuid; } } Vector3d ISatellite.Position { get { return FlightGlobals.Bodies[Body].GetWorldSurfacePosition(Latitude, Longitude, Height); } } bool ISatellite.IsCommandStation { get { return true; } } bool ISatellite.HasLocalControl { get { return false; } } @@ -259,7 +250,7 @@ void ISatellite.OnConnectionRefresh(List> route) { } public MissionControlSatellite() { - this.mGuid = new Guid(this.Guid); + mGuid = new Guid(Guid); } void IPersistenceLoad.PersistenceLoad() @@ -268,7 +259,7 @@ void IPersistenceLoad.PersistenceLoad() { antenna.Parent = this; } - this.mGuid = new Guid(this.Guid); + mGuid = new Guid(Guid); } public override String ToString() diff --git a/src/RemoteTech/RemoteTech.sln b/src/RemoteTech/RemoteTech.sln index fb3127d58..747023474 100644 --- a/src/RemoteTech/RemoteTech.sln +++ b/src/RemoteTech/RemoteTech.sln @@ -1,6 +1,8 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RemoteTech", "RemoteTech.csproj", "{42155D82-1F25-4E59-9F65-64ABC583F420}" EndProject Global @@ -9,8 +11,8 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {42155D82-1F25-4E59-9F65-64ABC583F420}.Debug|Any CPU.ActiveCfg = Release|Any CPU - {42155D82-1F25-4E59-9F65-64ABC583F420}.Debug|Any CPU.Build.0 = Release|Any CPU + {42155D82-1F25-4E59-9F65-64ABC583F420}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {42155D82-1F25-4E59-9F65-64ABC583F420}.Debug|Any CPU.Build.0 = Debug|Any CPU {42155D82-1F25-4E59-9F65-64ABC583F420}.Release|Any CPU.ActiveCfg = Release|Any CPU {42155D82-1F25-4E59-9F65-64ABC583F420}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection From 6d980db42a49890277e67c15e9381596b2f98d31 Mon Sep 17 00:00:00 2001 From: Chris Woerz Date: Tue, 6 Jan 2015 23:04:40 -0700 Subject: [PATCH 5/5] minor cleanup --- src/RemoteTech/NetworkRenderer.cs | 22 +++++++++---------- .../RangeModel/RangeModelExtensions.cs | 19 +++++----------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/src/RemoteTech/NetworkRenderer.cs b/src/RemoteTech/NetworkRenderer.cs index 11c482bd7..375e08fe8 100644 --- a/src/RemoteTech/NetworkRenderer.cs +++ b/src/RemoteTech/NetworkRenderer.cs @@ -33,10 +33,10 @@ public MapFilter Filter { } } - private static Texture2D mTexMark; - private HashSet> mEdges = new HashSet>(); - private List mLines = new List(); - private List mCones = new List(); + private static readonly Texture2D mTexMark; + private readonly HashSet> mEdges = new HashSet>(); + private readonly List mLines = new List(); + private readonly List mCones = new List(); public bool ShowOmni { get { return (Filter & MapFilter.Omni) == MapFilter.Omni; } } public bool ShowDish { get { return (Filter & MapFilter.Dish) == MapFilter.Dish; } } @@ -83,13 +83,13 @@ public void OnGUI() var worldPos = ScaledSpace.LocalToScaledSpace(s.Position); if (MapView.MapCamera.transform.InverseTransformPoint(worldPos).z < 0f) continue; Vector3 pos = MapView.MapCamera.camera.WorldToScreenPoint(worldPos); - Rect screenRect = new Rect((pos.x - 8), (Screen.height - pos.y) - 8, 16, 16); + var screenRect = new Rect((pos.x - 8), (Screen.height - pos.y) - 8, 16, 16); if (s is MissionControlSatellite && RTSettings.Instance.HideGroundStationsBehindBody) { - CelestialBody Kerbin = FlightGlobals.Bodies.Find(body => body.name == "Kerbin"); + CelestialBody kerbin = FlightGlobals.Bodies.Find(body => body.name == "Kerbin"); // Hide the current ISatellite if it is behind its body - if (IsOccluded(s.Position, Kerbin)) + if (IsOccluded(s.Position, kerbin)) showOnMapview = false; } @@ -108,7 +108,7 @@ public void OnGUI() /// /// Checks whether the location is behind the body - /// Orginal code by regex from https://github.com/NathanKell/RealSolarSystem/blob/master/Source/KSCSwitcher.cs + /// Original code by regex from https://github.com/NathanKell/RealSolarSystem/blob/master/Source/KSCSwitcher.cs /// private bool IsOccluded(Vector3d loc, CelestialBody body) { @@ -148,7 +148,7 @@ private void UpdateNetworkCones() var center = RTCore.Instance.Network.GetPositionFromGuid(antennas[i].Target); Debug.Assert(center != null, "center != null", - String.Format("GetPositionFromGuid retuned a null value for the target {0}", + String.Format("GetPositionFromGuid returned a null value for the target {0}", antennas[i].Target) ); mCones[i].Center = center.Value; @@ -157,14 +157,14 @@ private void UpdateNetworkCones() private void UpdateNetworkEdges() { - var edges = mEdges.Where(e => CheckVisibility(e)).ToList(); + var edges = mEdges.Where(CheckVisibility).ToList(); int oldLength = mLines.Count; int newLength = edges.Count; // Free any unused lines for (int i = newLength; i < oldLength; i++) { - GameObject.Destroy(mLines[i]); + Destroy(mLines[i]); mLines[i] = null; } mLines.RemoveRange(Math.Min(oldLength, newLength), Math.Max(oldLength - newLength, 0)); diff --git a/src/RemoteTech/RangeModel/RangeModelExtensions.cs b/src/RemoteTech/RangeModel/RangeModelExtensions.cs index 00caf2651..cbdbc5967 100644 --- a/src/RemoteTech/RangeModel/RangeModelExtensions.cs +++ b/src/RemoteTech/RangeModel/RangeModelExtensions.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; namespace RemoteTech { @@ -55,12 +52,8 @@ public static bool IsInFieldOfView(this IAntenna dish, ISatellite target, ISatel return (Vector3d.Dot(dirToConeCenter.normalized, dirToTarget.normalized) >= dish.CosAngle); } - else - { - RTLog.Notify("Unexpected dish target: {0}", dish.Target); - return false; - } - + RTLog.Notify("Unexpected dish target: {0}", dish.Target); + return false; } /// Finds the distance between two ISatellites @@ -72,8 +65,8 @@ public static double DistanceTo(this ISatellite a, ISatellite b) /// Finds the distance between an ISatellite and the target of a connection /// The distance in meters. - /// The satellite from which the distance is to be measured. - /// The network node to whose destination the distance is to be measured. + /// The satellite from which the distance is to be measured. + /// The network node to whose destination the distance is to be measured. public static double DistanceTo(this ISatellite sat, NetworkLink link) { return Vector3d.Distance(sat.Position, link.Target.Position); @@ -84,7 +77,7 @@ public static double DistanceTo(this ISatellite sat, NetworkLink lin /// otherwise, false. public static bool HasLineOfSightWith(this ISatellite satA, ISatellite satB) { - const double minHeight = 5.0; + const double MIN_HEIGHT = 5.0; Vector3d satAPos = satA.Position; Vector3d satBPos = satB.Position; @@ -101,7 +94,7 @@ public static bool HasLineOfSightWith(this ISatellite satA, ISatellite satB) // Above conditions guarantee that Vector3d.Dot(bodyFromA, bFromANorm) * bFromANorm // lies between the origin and bFromA Vector3d lateralOffset = bodyFromA - Vector3d.Dot(bodyFromA, bFromANorm) * bFromANorm; - if (lateralOffset.magnitude < referenceBody.Radius - minHeight) return false; + if (lateralOffset.magnitude < referenceBody.Radius - MIN_HEIGHT) return false; } return true; }