@@ -180,16 +180,19 @@ def nodeToMat(node: BinaryNode, depth=-1, valueFillChar=None, connectorFillChar=
180180
181181 # Special handling for child positions if unitSize > 1
182182 if unitSize > 1 and connectors is not None :
183- # Left child: fill chars positioned to the right of where / appears
184- # The connector / is centered, so it appears at position unitSize // 2
185- # We want fill chars after it
186- leftFill = " " * (unitSize // 2 + 1 ) + connectorFillChar * (unitSize - unitSize // 2 - 1 )
183+ # Find where the connector characters appear when centered
184+ leftConnectorCentered = center (connectors [0 ], unitSize = unitSize , fillChar = " " )
185+ rightConnectorCentered = center (connectors [1 ], unitSize = unitSize , fillChar = " " )
186+
187+ leftConnectorPos = leftConnectorCentered .index (connectors [0 ])
188+ rightConnectorPos = rightConnectorCentered .index (connectors [1 ])
189+
190+ # Left child: spaces up to and including connector position, then fill chars
191+ leftFill = " " * (leftConnectorPos + 1 ) + connectorFillChar * (unitSize - leftConnectorPos - 1 )
187192 mat [level ][leftChildCol ] = leftFill
188193
189- # Right child: fill chars positioned to the left of where \ appears
190- # The connector \ is centered, so it appears at position unitSize // 2
191- # We want fill chars before it
192- rightFill = connectorFillChar * (unitSize // 2 ) + " " * (unitSize - unitSize // 2 )
194+ # Right child: fill chars up to connector position, then spaces
195+ rightFill = connectorFillChar * rightConnectorPos + " " * (unitSize - rightConnectorPos )
193196 mat [level ][rightChildCol ] = rightFill
194197
195198 prevValueIndexes = valueIndexes
0 commit comments