current in Wire cannot be null (0 instead)

This commit is contained in:
Patrick Haßel 2025-01-31 14:49:03 +01:00
parent 6ae15ea149
commit a119ebf0d2
2 changed files with 5 additions and 2 deletions

View File

@ -64,7 +64,6 @@ export class Junction {
return this.wires return this.wires
.filter(wire => wire.traverse(this) !== plus) .filter(wire => wire.traverse(this) !== plus)
.map(wire => wire.current) .map(wire => wire.current)
.filter(current => current !== null)
.reduce((a, b) => a + b, 0); .reduce((a, b) => a + b, 0);
} }

View File

@ -3,7 +3,7 @@ import {RESISTANCE_MIN} from '../circuit/Circuit';
export class Wire { export class Wire {
current: number | null = null; current: number = 0;
constructor( constructor(
readonly start: Junction, readonly start: Junction,
@ -18,6 +18,10 @@ export class Wire {
} }
} }
get absCurrent(): number {
return Math.abs(this.current);
}
toString() { toString() {
if (this.start.part === this.end.part && this.name !== null) { if (this.start.part === this.end.part && this.name !== null) {
return `'${this.start.part}' "${this.name}"`; return `'${this.start.part}' "${this.name}"`;