Skip to content

refactor round_corners() in shapes.c

Costa Shulyupin requested to merge makelinux/graphviz:mid into main

The function round_corners() holds the record for being the longest function based on token count.

lizard -w  -s token_count lib/ cmd 2> /dev/null | head -n 1
lib/common/shapes.c:586: warning: round_corners has 794 NLOC, 45 CCN, 13381 token, 5 PARAM, 1244 length

It is important to simplify it for readability and maintainability.

Eliminate a lot of duplicated code.

Tested with script:

i=0
echo graph { _rankdir=LR
p="none"
echo "$p [shape=$p]"
echo 'node [fontname=Helvetica style=filled fillcolor=lightgray fontcolor="#00000044"]'
for s in box polygon ellipse oval circle point egg triangle plaintext plain \
        diamond trapezium parallelogram house pentagon hexagon \
        septagon octagon doublecircle doubleoctagon tripleoctagon \
        invtriangle invtrapezium invhouse Mdiamond Msquare Mcircle rect \
        square star underline cylinder note tab folder box3d \
        component promoter cds terminator utr primersite \
        restrictionsite fivepoverhang threepoverhang noverhang \
        assembly signature insulator ribosite rnastab proteasesite \
        proteinstab rpromoter rarrow larrow lpromoter; do
        n=$s
        echo "$n [xlabel=\"$t $s\" shape=$s]"
        let i+=1
        if ((i % 5)); then
                echo "$p -- $n"
        fi
        p=$n
done
echo }

Results of the test:

a

Edited by Costa Shulyupin

Merge request reports