-/*
- This function calculates 2 center control points,
- based on lines through c_0 --> left disturbing
- and c_3--> right disturbing encompass points.
-
- See Documentation/fonts.tex
- */
-void
-Bezier_bow::calc_tangent_controls ()
-{
- Real b = curve_.control_[3][X_AXIS];
- Real h = curve_.control_[1][Y_AXIS];
-
-
- Drul_array<Offset> disturb;
- Drul_array<Real> maxtan;
- maxtan[LEFT] = maxtan[RIGHT] = h/(b/2);
- disturb[LEFT] = disturb[RIGHT] = Offset (b / 2, h);
-
- for (int i = 1; i < encompass_.size () -1; i++)
- {
- Real y= encompass_[i][Y_AXIS];
- if (y> 0)
- {
- Real x = encompass_[i][X_AXIS];
-
- Direction d = LEFT;
- do
- {
- // 1 if d == LEFT
- int k = (1 - d)/2;
- Real tan = y / ((1-k)* b - d * x);
-
- if (tan > maxtan[d])
- {
- maxtan[d] = tan;
- disturb[d] = Offset (x,y);
- }
- }
- while (flip (&d)!=LEFT);
- }
- }
-
- for (int i = 0; i < encompass_.size (); i++ )
- h = h >? encompass_[i][Y_AXIS];
-
- /*
- The curve will always be under line between curve_.control_0 -> curve_.control_1, so
- make it extra steep by slur_rc_factor
- */
-
-
- Drul_array<Real> angles;
- Direction d = LEFT;
- do
- {
- maxtan[d] *= -d * rc_factor_;
- angles[d] = atan (maxtan[d]);
- }
- while (flip(&d) != LEFT);
-
- Real rc3 = 0.0;
-
- /*
- if we have two disturbing points, have line through those...
- in order to get a sane line, make sure points are reasonably far apart
- X distance must be reasonably(!) big (division)
- */
- if (abs (disturb[LEFT][X_AXIS] - disturb[RIGHT][X_AXIS]) > FUDGE)
- rc3 = (disturb[RIGHT][Y_AXIS] - disturb[LEFT][Y_AXIS]) / (disturb[RIGHT][X_AXIS] - disturb[LEFT][X_AXIS]);
-
- else
- rc3 = tan ((angles[LEFT] - angles[RIGHT]) / 2);
-
-
- // ugh: be less steep
- rc3 /= 2*rc_factor_;
-
-
- Real c2 = -maxtan[RIGHT] * curve_.control_[3][X_AXIS];
-
- // use highest because rc3 is damped.
- Real maxy = disturb[LEFT][Y_AXIS] >? disturb[RIGHT][Y_AXIS];
- Real c3 = disturb[LEFT][Y_AXIS] > disturb[RIGHT][Y_AXIS] ?
- maxy - rc3 * disturb[LEFT][X_AXIS] :
- maxy - rc3 * disturb[RIGHT][X_AXIS];
-
- curve_.control_[1][X_AXIS] = c3 / (maxtan[LEFT] - rc3);
- curve_.control_[1][Y_AXIS] = maxtan[LEFT] * curve_.control_[1][X_AXIS];
-
- curve_.control_[2][X_AXIS] = (c3 - c2) / (maxtan[RIGHT] - rc3);
- curve_.control_[2][Y_AXIS] = maxtan[RIGHT] * curve_.control_[2][X_AXIS] + c2;
-
-
- curve_.check_sanity();
-}