Skip to content

Commit

Permalink
Modifier upd.
Browse files Browse the repository at this point in the history
  • Loading branch information
Smoren committed May 29, 2024
1 parent 4e74066 commit 9216c2b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/lib/genetic/modifiers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { SummaryMatrixRowObject } from '../types/analysis';
import { convertArrayToStatSummary, convertStatSummaryToArray } from "@/lib/analysis/helpers";
import { arraySum } from '../math';
import { convertArrayToStatSummary, convertStatSummaryToArray } from '../analysis/helpers';

export class SummaryMatrixRowObjectModifier {
private readonly row: SummaryMatrixRowObject;
Expand All @@ -20,4 +21,17 @@ export class SummaryMatrixRowObjectModifier {
);
return this;
}

public mulTypeSpeed(type: number, value: number): SummaryMatrixRowObjectModifier {
const oldMeanSpeed = arraySum(this.row.atomTypeMeanSpeed) / this.row.atomTypeMeanSpeed.length;
this.row.atomTypeMeanSpeed[type] *= value;
const newMeanSpeed = arraySum(this.row.atomTypeMeanSpeed) / this.row.atomTypeMeanSpeed.length;

this.row.atomsMeanSpeed *= newMeanSpeed / oldMeanSpeed;
this.row.compoundSpeedSummary = convertArrayToStatSummary(
convertStatSummaryToArray(this.row.compoundSpeedSummary).map((x) => x * newMeanSpeed / oldMeanSpeed),
);

return this;
}
}

0 comments on commit 9216c2b

Please sign in to comment.