Skip to content

Commit 854b5ec

Browse files
authored
Refactor: Use pressure-based calculations in GasPlanner and OxygenToxicityCalculator (#180)
`GasPlanner` and `OxygenToxicityCalculator` now use pressures directly. Meter-based helper functions on the `Gas` type have been replaced with pressure-based ones. Required for: #49
1 parent 80009a5 commit 854b5ec

31 files changed

Lines changed: 184 additions & 225 deletions

File tree

Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Loading
Loading
Loading
Loading

composeApp/src/commonMain/kotlin/org/neotech/app/abysner/presentation/component/GasPropertiesComponent.kt

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ import androidx.compose.ui.unit.dp
2525
import org.neotech.app.abysner.domain.core.model.Environment
2626
import org.neotech.app.abysner.domain.core.model.Gas
2727
import org.neotech.app.abysner.domain.core.model.Salinity
28+
import org.neotech.app.abysner.domain.core.model.UnitSystem
2829
import org.neotech.app.abysner.domain.core.physics.ATMOSPHERIC_PRESSURE_AT_SEA_LEVEL
30+
import org.neotech.app.abysner.domain.core.physics.Pressure
31+
import org.neotech.app.abysner.domain.utilities.floorTolerant
2932
import org.neotech.app.abysner.domain.utilities.format
3033
import org.neotech.app.abysner.presentation.theme.AbysnerTheme
34+
import org.neotech.app.abysner.presentation.utilities.formatDisplayDepth
3135
import kotlin.math.round
3236

3337
@Composable
@@ -87,9 +91,9 @@ fun GasPropertiesComponent(
8791
Row(modifier = Modifier.wrapContentHeight(),
8892
horizontalArrangement = Arrangement.spacedBy(12.dp)) {
8993

90-
val mod = gas?.let {
91-
"${it.oxygenModRounded(maxPPO2, environment)}m"
92-
} ?: EMPTY_PLACEHOLDER
94+
val mod = gas?.oxygenModAmbientPressureWithTolerance(maxPPO2)
95+
?.formatModDepth(UnitSystem.METRIC, environment)
96+
?: EMPTY_PLACEHOLDER
9397

9498
FlipCardComponent(
9599
modifier = Modifier.weight(0.3f),
@@ -115,9 +119,10 @@ fun GasPropertiesComponent(
115119

116120
if(showSecondaryPPO2) {
117121

118-
val modSecondary = gas?.let {
119-
"${it.oxygenModRounded(maxPPO2Secondary!!, environment)}m"
120-
} ?: EMPTY_PLACEHOLDER
122+
val modSecondary = gas
123+
?.oxygenModAmbientPressureWithTolerance(maxPPO2Secondary)
124+
?.formatModDepth(UnitSystem.METRIC, environment)
125+
?: EMPTY_PLACEHOLDER
121126

122127
FlipCardComponent(
123128
modifier = Modifier.weight(0.3f),
@@ -142,9 +147,10 @@ fun GasPropertiesComponent(
142147
)
143148
}
144149

145-
val densityMod = gas?.let {
146-
"${round(it.densityMod(maxAllowedDensity = maxDensity, environment = environment)).toInt()}m"
147-
} ?: EMPTY_PLACEHOLDER
150+
val densityMod = gas
151+
?.densityModAmbientPressure(maxDensity)
152+
?.formatModDepthRounded(UnitSystem.METRIC, environment)
153+
?: EMPTY_PLACEHOLDER
148154

149155
FlipCardComponent(
150156
modifier = Modifier.weight(0.3f),
@@ -195,6 +201,12 @@ fun GasPropertiesComponent(
195201
}
196202
}
197203

204+
private fun Pressure.formatModDepth(unitSystem: UnitSystem, environment: Environment): String =
205+
floorTolerant(unitSystem.ambientPressureToDepth(this, environment)).formatDisplayDepth(unitSystem)
206+
207+
private fun Pressure.formatModDepthRounded(unitSystem: UnitSystem, environment: Environment): String =
208+
unitSystem.ambientPressureToDepth(this, environment).formatDisplayDepth(unitSystem)
209+
198210
private const val EMPTY_PLACEHOLDER = ""
199211

200212
@Preview

0 commit comments

Comments
 (0)