mirror of
https://github.com/space-wizards/space-station-14.git
synced 2026-02-14 19:29:53 +01:00
Make some HeatContainerHelpers methods byref (#42197)
* make some HeatContainerHelpers methods byref * all of them
This commit is contained in:
@@ -26,7 +26,7 @@ public static partial class HeatContainerHelpers
|
||||
/// integration steps with adaptive step size.
|
||||
/// </remarks>
|
||||
[PublicAPI]
|
||||
public static float ConductHeat(this HeatContainer c, float temp, float deltaTime, float g)
|
||||
public static float ConductHeat(this ref HeatContainer c, float temp, float deltaTime, float g)
|
||||
{
|
||||
var dQ = c.ConductHeatQuery(temp, deltaTime, g);
|
||||
c.AddHeat(dQ);
|
||||
@@ -55,9 +55,9 @@ public static partial class HeatContainerHelpers
|
||||
/// integration steps with adaptive step size.
|
||||
/// </remarks>
|
||||
[PublicAPI]
|
||||
public static float ConductHeat(this HeatContainer cA, HeatContainer cB, float deltaTime, float g)
|
||||
public static float ConductHeat(this ref HeatContainer cA, ref HeatContainer cB, float deltaTime, float g)
|
||||
{
|
||||
var dQ = ConductHeatQuery(cA, cB.Temperature, deltaTime, g);
|
||||
var dQ = ConductHeatQuery(ref cA, cB.Temperature, deltaTime, g);
|
||||
cA.AddHeat(dQ);
|
||||
cB.AddHeat(-dQ);
|
||||
return dQ;
|
||||
@@ -85,10 +85,10 @@ public static partial class HeatContainerHelpers
|
||||
/// integration steps with adaptive step size.
|
||||
/// </remarks>
|
||||
[PublicAPI]
|
||||
public static float ConductHeatQuery(this HeatContainer c, float temp, float deltaTime, float g)
|
||||
public static float ConductHeatQuery(this ref HeatContainer c, float temp, float deltaTime, float g)
|
||||
{
|
||||
var dQ = g * (temp - c.Temperature) * deltaTime;
|
||||
var dQMax = Math.Abs(ConductHeatToTempQuery(c, temp));
|
||||
var dQMax = Math.Abs(ConductHeatToTempQuery(ref c, temp));
|
||||
|
||||
// Clamp the transferred heat amount in case we are overshooting the equilibrium temperature because our time step was too large.
|
||||
return Math.Clamp(dQ, -dQMax, dQMax);
|
||||
@@ -116,9 +116,9 @@ public static partial class HeatContainerHelpers
|
||||
/// integration steps with adaptive step size.
|
||||
/// </remarks>
|
||||
[PublicAPI]
|
||||
public static float ConductHeatQuery(this HeatContainer c1, HeatContainer c2, float deltaTime, float g)
|
||||
public static float ConductHeatQuery(this ref HeatContainer c1, ref HeatContainer c2, float deltaTime, float g)
|
||||
{
|
||||
return ConductHeatQuery(c1, c2.Temperature, deltaTime, g);
|
||||
return ConductHeatQuery(ref c1, c2.Temperature, deltaTime, g);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -131,9 +131,9 @@ public static partial class HeatContainerHelpers
|
||||
/// to reach the target temperature.</returns>
|
||||
/// <example>A positive value indicates heat must be added to the container to reach the target temperature.</example>
|
||||
[PublicAPI]
|
||||
public static float ConductHeatToTemp(this HeatContainer c, float targetTemp)
|
||||
public static float ConductHeatToTemp(this ref HeatContainer c, float targetTemp)
|
||||
{
|
||||
var dQ = ConductHeatToTempQuery(c, targetTemp);
|
||||
var dQ = ConductHeatToTempQuery(ref c, targetTemp);
|
||||
c.Temperature = targetTemp;
|
||||
return dQ;
|
||||
}
|
||||
@@ -148,7 +148,7 @@ public static partial class HeatContainerHelpers
|
||||
/// to reach the target temperature.</returns>
|
||||
/// <example>A positive value indicates heat must be added to the container to reach the target temperature.</example>
|
||||
[PublicAPI]
|
||||
public static float ConductHeatToTempQuery(this HeatContainer c, float targetTemp)
|
||||
public static float ConductHeatToTempQuery(this ref HeatContainer c, float targetTemp)
|
||||
{
|
||||
return (targetTemp - c.Temperature) * c.HeatCapacity;
|
||||
}
|
||||
|
||||
@@ -38,8 +38,7 @@ public static partial class HeatContainerHelpers
|
||||
[PublicAPI]
|
||||
public static HeatContainer[] Divide(this HeatContainer c, uint num)
|
||||
{
|
||||
if (num == 0)
|
||||
throw new ArgumentException("Cannot divide by zero.", nameof(num));
|
||||
ArgumentOutOfRangeException.ThrowIfZero(num);
|
||||
|
||||
var fraction = 1f / num;
|
||||
var cFrac = c.Split(fraction);
|
||||
|
||||
@@ -17,7 +17,7 @@ public static partial class HeatContainerHelpers
|
||||
/// to bring the containers to thermal equilibrium.</returns>
|
||||
/// <example>A positive value indicates heat transfer from a hot cA to a cold cB.</example>
|
||||
[PublicAPI]
|
||||
public static float EquilibriumHeatQuery(this HeatContainer cA, HeatContainer cB)
|
||||
public static float EquilibriumHeatQuery(this ref HeatContainer cA, ref HeatContainer cB)
|
||||
{
|
||||
/*
|
||||
The solution is derived from the following facts:
|
||||
@@ -43,7 +43,7 @@ public static partial class HeatContainerHelpers
|
||||
/// <param name="cB">The second <see cref="HeatContainer"/> to exchange heat with.</param>
|
||||
/// <returns>The resulting equilibrium temperature both containers will be at.</returns>
|
||||
[PublicAPI]
|
||||
public static float EquilibriumTemperatureQuery(this HeatContainer cA, HeatContainer cB)
|
||||
public static float EquilibriumTemperatureQuery(this ref HeatContainer cA, ref HeatContainer cB)
|
||||
{
|
||||
// Insert the above solution for Q into T_A_final = T_A_initial - Q / C_A and rearrange the result.
|
||||
return (cA.HeatCapacity * cA.Temperature - cB.HeatCapacity * cB.Temperature) / (cA.HeatCapacity + cB.HeatCapacity);
|
||||
@@ -55,9 +55,9 @@ public static partial class HeatContainerHelpers
|
||||
/// <param name="cA">The first <see cref="HeatContainer"/> to exchange heat.</param>
|
||||
/// <param name="cB">The second <see cref="HeatContainer"/> to exchange heat with.</param>
|
||||
[PublicAPI]
|
||||
public static void Equilibrate(this HeatContainer cA, HeatContainer cB)
|
||||
public static void Equilibrate(this ref HeatContainer cA, ref HeatContainer cB)
|
||||
{
|
||||
var tFinal = EquilibriumTemperatureQuery(cA, cB);
|
||||
var tFinal = EquilibriumTemperatureQuery(ref cA, ref cB);
|
||||
cA.Temperature = tFinal;
|
||||
cB.Temperature = tFinal;
|
||||
}
|
||||
@@ -69,10 +69,10 @@ public static partial class HeatContainerHelpers
|
||||
/// <param name="cB">The second <see cref="HeatContainer"/> to exchange heat with.</param>
|
||||
/// <param name="dQ">The amount of heat in joules that was transferred from container A to B.</param>
|
||||
[PublicAPI]
|
||||
public static void Equilibrate(this HeatContainer cA, HeatContainer cB, out float dQ)
|
||||
public static void Equilibrate(this ref HeatContainer cA, ref HeatContainer cB, out float dQ)
|
||||
{
|
||||
var tInitialA = cA.Temperature;
|
||||
var tFinal = EquilibriumTemperatureQuery(cA, cB);
|
||||
var tFinal = EquilibriumTemperatureQuery(ref cA, ref cB);
|
||||
cA.Temperature = tFinal;
|
||||
cB.Temperature = tFinal;
|
||||
dQ = (tInitialA - tFinal) / cA.HeatCapacity;
|
||||
@@ -103,7 +103,7 @@ public static partial class HeatContainerHelpers
|
||||
/// <param name="cA">The first <see cref="HeatContainer"/> to bring into thermal equilibrium.</param>
|
||||
/// <param name="cN">The array of <see cref="HeatContainer"/>s to bring into thermal equilibrium.</param>
|
||||
[PublicAPI]
|
||||
public static void Equilibrate(this HeatContainer cA, HeatContainer[] cN)
|
||||
public static void Equilibrate(this ref HeatContainer cA, HeatContainer[] cN)
|
||||
{
|
||||
var tF = cA.EquilibriumTemperatureQuery(cN);
|
||||
|
||||
@@ -201,7 +201,7 @@ public static partial class HeatContainerHelpers
|
||||
/// <param name="cN">The array of <see cref="HeatContainer"/>s to bring into thermal equilibrium.</param>
|
||||
/// <returns>The temperature of all <see cref="HeatContainer"/>s involved after reaching thermal equilibrium.</returns>
|
||||
[PublicAPI]
|
||||
public static float EquilibriumTemperatureQuery(this HeatContainer cA, HeatContainer[] cN)
|
||||
public static float EquilibriumTemperatureQuery(this ref HeatContainer cA, HeatContainer[] cN)
|
||||
{
|
||||
var cAll = new HeatContainer[cN.Length + 1];
|
||||
cAll[0] = cA;
|
||||
|
||||
@@ -16,7 +16,7 @@ public static partial class HeatContainerHelpers
|
||||
/// <param name="c">The <see cref="HeatContainer"/> to add or remove energy.</param>
|
||||
/// <param name="dQ">The energy in joules to add or remove.</param>
|
||||
[PublicAPI]
|
||||
public static void AddHeat(this HeatContainer c, float dQ)
|
||||
public static void AddHeat(this ref HeatContainer c, float dQ)
|
||||
{
|
||||
c.Temperature = c.AddHeatQuery(dQ);
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public static partial class HeatContainerHelpers
|
||||
/// <param name="dQ">The energy in joules to add or remove.</param>
|
||||
/// <returns>The resulting temperature in kelvin after the heat change.</returns>
|
||||
[PublicAPI]
|
||||
public static float AddHeatQuery(this HeatContainer c, float dQ)
|
||||
public static float AddHeatQuery(this ref HeatContainer c, float dQ)
|
||||
{
|
||||
// Don't allow the temperature to go below the absolute minimum.
|
||||
return Math.Max(0f, c.Temperature + dQ / c.HeatCapacity);
|
||||
@@ -43,7 +43,7 @@ public static partial class HeatContainerHelpers
|
||||
/// <param name="c">The <see cref="HeatContainer"/> to modify.</param>
|
||||
/// <param name="newHeatCapacity">The new heat capacity to set.</param>
|
||||
[PublicAPI]
|
||||
public static void SetHeatCapacity(this HeatContainer c, float newHeatCapacity)
|
||||
public static void SetHeatCapacity(this ref HeatContainer c, float newHeatCapacity)
|
||||
{
|
||||
var currentEnergy = c.InternalEnergy;
|
||||
c.HeatCapacity = newHeatCapacity;
|
||||
|
||||
Reference in New Issue
Block a user