Skip to content

Commit

Permalink
🚧 Remove non-null assertions
Browse files Browse the repository at this point in the history
Handle these cases better.
  • Loading branch information
victorlin committed Oct 8, 2024
1 parent 9415191 commit 38b94d4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/components/tree/phyloTree/regression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ export interface Regression {
* The regression is forced to pass through nodes[0].
*/
function calculateRegressionThroughRoot(nodes: PhyloNode[]): Regression {
if (!nodes[0]) {
throw new Error("`nodes` must contain at least one entry to calculate the regression through the root.");
}
const terminalNodes = nodes.filter((d) => !d.n.hasChildren && d.visibility === NODE_VISIBLE);
const nTips = terminalNodes.length;
if (nTips===0) {
return {slope: undefined, intercept: undefined, r2: undefined};
}
const offset = nodes[0]!.x;
const offset = nodes[0].x;
const XY = sum(
terminalNodes.map((d) => (d.y) * (d.x - offset))
) / nTips;
Expand Down

0 comments on commit 38b94d4

Please sign in to comment.