@@ -199,16 +199,19 @@ <h2 id="returns">Returns</h2>
199199
200200 # Special handling for child positions if unitSize > 1
201201 if unitSize > 1 and connectors is not None:
202- # Left child: fill chars positioned to the right of where / appears
203- # The connector / is centered, so it appears at position unitSize // 2
204- # We want fill chars after it
205- leftFill = " " * (unitSize // 2 + 1) + connectorFillChar * (unitSize - unitSize // 2 - 1)
202+ # Find where the connector characters appear when centered
203+ leftConnectorCentered = center(connectors[0], unitSize=unitSize, fillChar=" ")
204+ rightConnectorCentered = center(connectors[1], unitSize=unitSize, fillChar=" ")
205+
206+ leftConnectorPos = leftConnectorCentered.index(connectors[0])
207+ rightConnectorPos = rightConnectorCentered.index(connectors[1])
208+
209+ # Left child: spaces up to and including connector position, then fill chars
210+ leftFill = " " * (leftConnectorPos + 1) + connectorFillChar * (unitSize - leftConnectorPos - 1)
206211 mat[level][leftChildCol] = leftFill
207212
208- # Right child: fill chars positioned to the left of where \ appears
209- # The connector \ is centered, so it appears at position unitSize // 2
210- # We want fill chars before it
211- rightFill = connectorFillChar * (unitSize // 2) + " " * (unitSize - unitSize // 2)
213+ # Right child: fill chars up to connector position, then spaces
214+ rightFill = connectorFillChar * rightConnectorPos + " " * (unitSize - rightConnectorPos)
212215 mat[level][rightChildCol] = rightFill
213216
214217 prevValueIndexes = valueIndexes
0 commit comments