G35/G36 defines filled regions. The duplication of the last point is probably just to make sure the contour is closed.
The second set (after G37) effectively draws the outline of the filled area,
I'm not sure what the purpose of that is.
The comment in the code says this \:
// Gerber format does not know filled polygons with thick outline
// Therefore, to plot a filled polygon with outline having a thickness,
// one should plot outline as thick segments
G36/G37 draw the region with a zero thickness line, so the outline is traced over again with the desired line thickness.