private void FixF()
{
// TODO: Measure performance of comparing squared values instead of taking square root.
if((float)Math.Sqrt((_fx - _cx) * (_fx - _cx)) + ((_fy - _cy) * (_fy - _cy)) > _r) {
float dx = _fx - _cx;
float dy = _fy - _cy;
if(dx == 0)
_fy = (_fy > _cy) ? (_cy + _r) : (_cy - _r);
else {
float a, b;
a = dy / dx;
b = _fy - a * _fx;
double ta, tb, tc;
ta = 1 + a * a;
tb = 2 * (a * (b - _cy) - _cx);
tc = (_cx * _cx) + (b - _cy) * (b - _cy) - (_r * _r);
float delta = (float)((tb * tb) - 4 * ta * tc);
delta = (float)Math.Sqrt(delta);
float x1 = (float)((-tb + delta) / (2 * ta));
float y1 = (float)(a * x1 + b);
float x2 = (float)((-tb - delta) / (2 * ta));
float y2 = (float)(a * x2 + b);
if((_cx < x1) && (x1 < _fx)) {
_fx = x1 - 1;
_fy = y1;
} else {
_fx = x2 + 1;
_fy = y2;
}
}
}
}