Ported the calcShapes method from AS to C++