-void
-AutomationLine::determine_visible_control_points (ALPoints& points)
-{
- uint32_t view_index, pi, n;
- AutomationList::iterator model;
- uint32_t npoints;
- double last_control_point_x = 0.0;
- double last_control_point_y = 0.0;
- uint32_t this_rx = 0;
- uint32_t prev_rx = 0;
- uint32_t this_ry = 0;
- uint32_t prev_ry = 0;
- double* slope;
- uint32_t box_size;
- uint32_t cpsize;
-
- /* hide all existing points, and the line */
-
- cpsize = 0;
-
- for (vector<ControlPoint*>::iterator i = control_points.begin(); i != control_points.end(); ++i) {
- (*i)->hide();
- ++cpsize;
- }
-
- line->hide ();
-
- if (points.empty()) {
- return;
- }
-
- npoints = points.size();
-
- /* compute derivative/slope for the entire line */
-
- slope = new double[npoints];
-
- for (n = 0; n < npoints - 1; ++n) {
- double xdelta = points[n+1].x - points[n].x;
- double ydelta = points[n+1].y - points[n].y;
- slope[n] = ydelta/xdelta;
- }
-
- box_size = (uint32_t) control_point_box_size ();
-
- /* read all points and decide which ones to show as control points */
-
- view_index = 0;
-
- for (model = alist->begin(), pi = 0; pi < npoints; ++model, ++pi) {
-
- double tx = points[pi].x;
- double ty = points[pi].y;
-
- if (isnan (tx) || isnan (ty)) {
- warning << string_compose (_("Ignoring illegal points on AutomationLine \"%1\""),
- _name) << endmsg;
- continue;
- }
-
- /* now ensure that the control_points vector reflects the current curve
- state, but don't plot control points too close together. also, don't
- plot a series of points all with the same value.
-
- always plot the first and last points, of course.
- */
-
- if (invalid_point (points, pi)) {
- /* for some reason, we are supposed to ignore this point,
- but still keep track of the model index.
- */
- continue;
- }
-
- if (pi > 0 && pi < npoints - 1) {
- if (slope[pi] == slope[pi-1]) {
-
- /* no reason to display this point */
-
- continue;
- }
- }
-
- /* need to round here. the ultimate coordinates are integer
- pixels, so tiny deltas in the coords will be eliminated
- and we end up with "colinear" line segments. since the
- line rendering code in libart doesn't like this very
- much, we eliminate them here. don't do this for the first and last
- points.
- */
-
- this_rx = (uint32_t) rint (tx);
- this_ry = (uint32_t) rint (ty);
-
- if (view_index && pi != npoints && /* not the first, not the last */
- (((this_rx == prev_rx) && (this_ry == prev_ry)) || /* same point */
- (((this_rx - prev_rx) < (box_size + 2)) && /* not identical, but still too close horizontally */
- (abs ((int)(this_ry - prev_ry)) < (int) (box_size + 2))))) { /* too close vertically */
- continue;
- }
-
- /* ok, we should display this point */
-
- if (view_index >= cpsize) {
-
- /* make sure we have enough control points */
-
- ControlPoint* ncp = new ControlPoint (*this);
-
- ncp->set_size (box_size);
-
- control_points.push_back (ncp);
- ++cpsize;
- }
-
- ControlPoint::ShapeType shape;
-
- if (!terminal_points_can_slide) {
- if (pi == 0) {
- control_points[view_index]->set_can_slide(false);
- if (tx == 0) {
- shape = ControlPoint::Start;
- } else {
- shape = ControlPoint::Full;
- }
- } else if (pi == npoints - 1) {
- control_points[view_index]->set_can_slide(false);
- shape = ControlPoint::End;
- } else {
- control_points[view_index]->set_can_slide(true);
- shape = ControlPoint::Full;
- }
- } else {
- control_points[view_index]->set_can_slide(true);
- shape = ControlPoint::Full;
- }
-
- last_control_point_x = tx;
- last_control_point_y = ty;
-
- control_points[view_index]->reset (tx, ty, model, view_index, shape);
-
- prev_rx = this_rx;
- prev_ry = this_ry;
-
- /* finally, control visibility */
-
- if (_visible && points_visible) {
- control_points[view_index]->show ();
- control_points[view_index]->set_visible (true);
- } else {
- if (!points_visible) {
- control_points[view_index]->set_visible (false);
- }
- }
-
- view_index++;
- }
-
- /* discard extra CP's to avoid confusing ourselves */
-
- while (control_points.size() > view_index) {
- ControlPoint* cp = control_points.back();
- control_points.pop_back ();
- delete cp;
- }
-
- if (!terminal_points_can_slide) {
- control_points.back()->set_can_slide(false);