Skip to content

Commit

Permalink
Oops fix swell energy
Browse files Browse the repository at this point in the history
  • Loading branch information
mpiannucci committed Jul 5, 2024
1 parent f34b103 commit 7f5609b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/tools/waves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ pub fn pt_mean(
}
}

let energy = if ip == 0 {
let energy = if ip > 0 {
Some(wave_energy(hs, peak_period))
} else {
None
Expand Down Expand Up @@ -515,9 +515,14 @@ pub fn pt_mean(
components.sort_by(|sl, sr| sr.energy.partial_cmp(&sl.energy).unwrap());

// Calculate the total energy by simply summing the energy of all swell components
let summary_energy = components.iter().fold(0.0, |acc, x| {
acc + &x.energy.as_ref().map(|x| x.get_value()).unwrap_or(0.0)
});
let mut summary_energy = 0.0;
for component in &components {
summary_energy += component
.energy
.as_ref()
.map(|x| x.get_value())
.unwrap_or(0.0);
}

summary.energy = Some(DimensionalData {
value: Some(summary_energy),
Expand Down

0 comments on commit 7f5609b

Please sign in to comment.