I'm reading the code for GraphicsGem's implementation for fitting cubic bezier curves here. I understand most of the code but I'm having trouble understanding the function called "Generate Bezier", which from my current knowledge, takes the points on which we are fitting the curve, their parameterizations and tangent vectors at both ends of the curve and spits out a cubic bezier curve. However, how the function itself works I have no clue. Any help is appreciated.
I know it has something to do with the least-squares method from the comment but still.