Skip to content

refactor shapes.c, round_corners: introduce mid_x

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

round_corners() function holds the record for the number of tokens:

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 needs to be simplified for the sake of readability and maintainability.

Old expression AF[1].x + (AF[0].x - AF[1].x)/2 is optimized for integer arithmetic to avoid overflow. It is not relevant for floating point arithmetic.

Furthermore, this expression is copy-pasted many times.

To eliminate a lot of duplicated code and simplifying the round_corners() function introduce mid_x() function and use it just once for the beginning to simplify code review.

Proof of correctness: AF[1].x + (AF[0].x - AF[1].x)/2 -> AF[1].x/2 + AF[0].x/2 -> mid_x(AF)

Merge request reports