These are the six most complex functions in PerfectTIN, which will hopefully go into production in a few weeks:
32 32 testptin.cpp(319): testmatrix
36 39 tincanvas.cpp(90): TinCanvas::tick
53 53 mainwindow.cpp(126): MainWindow::tick
56 60 perfecttin.cpp(185): main
58 58 fileio.cpp(457): readPtin
62 62 pointlist.cpp(61): pointlist::checkTinConsistency
Where the two numbers are different, it's because of switch
statements.
testmatrix
consists of several order-2 and order-1 for-loops in a row and is not hard to understand. The thing that puzzled me, looking at it years after I wrote it in Bezitopo, is why it mods something by 83.
The two tick
methods are run 20 times a second and check several conditions. I've had a bit of trouble with the complexity, but the bugs are nothing worse than menu items being grayed out when they shouldn't, or the TIN display looking wonky.
The TIN is stored as a variant winged-edge structure consisting of points, edges, and triangles all pointing to each other. checkTinConsistency
has to be as complex as it is because the structure is complex and there are several ways it could be wrong.
The hardest bugs to find in PerfectTIN have been concurrency bugs, not cyclomatic bugs.
The most complex functions in Bezitopo (I started PerfectTIN by copying code from Bezitopo):
49 49 tin.cpp(537): pointlist::tryStartPoint
50 50 ptin.cpp(237): readPtin
51 51 convertgeoid.cpp(596): main
54 54 pointlist.cpp(117): pointlist::checkTinConsistency
73 80 bezier.cpp(1070): triangle::subdivide
92 92 bezitest.cpp(7963): main
main
in bezitest
is just a long sequence of if-statements: If I should test triangles, then run testtriangle
. If I should test measuring units, then run testmeasure
. And so on.
The complexity in subdivide
is partly because roundoff errors very rarely produce some wrong-looking conditions that the function has to check for.
What is now tryStartPoint
used to be part of maketin
(which now has a complexity of only 11) with even more complexity. I broke out the inside of the loop into a separate function because I had to call it from the GUI and update the screen in between.