+
+ if (p1 == p2 && p3 == p4) {
+ /* No information about the neighbors,
+ * calculate y1 and y2 to get a straight line
+ */
+ y1 = y0 + dy / 3.0;
+ y2 = y0 + dy * 2.0 / 3.0;
+
+ } else if (p1 == p2 && p3 != p4) {
+
+ /* only the right neighbor is available. Make the tangent at the
+ * right endpoint parallel to the line between the left endpoint
+ * and the right neighbor. Then point the tangent at the left towards
+ * the control handle of the right tangent, to ensure that the curve
+ * does not have an inflection point.
+ */
+ slope = (_points[p4].y - y0) / (_points[p4].x - x0);
+
+ y2 = y3 - slope * dx / 3.0;
+ y1 = y0 + (y2 - y0) / 2.0;
+
+ } else if (p1 != p2 && p3 == p4) {
+
+ /* see previous case */
+ slope = (y3 - _points[p1].y) / (x3 - _points[p1].x);
+
+ y1 = y0 + slope * dx / 3.0;
+ y2 = y3 + (y1 - y3) / 2.0;
+
+
+ } else /* (p1 != p2 && p3 != p4) */ {
+
+ /* Both neighbors are available. Make the tangents at the endpoints
+ * parallel to the line between the opposite endpoint and the adjacent
+ * neighbor.
+ */
+
+ slope = (y3 - _points[p1].y) / (x3 - _points[p1].x);
+
+ y1 = y0 + slope * dx / 3.0;
+
+ slope = (_points[p4].y - y0) / (_points[p4].x - x0);
+
+ y2 = y3 - slope * dx / 3.0;
+ }
+
+ /*
+ * finally calculate the y(t) values for the given bezier values. We can
+ * use homogenously distributed values for t, since x(t) increases linearily.
+ */
+
+ dx = dx / xextent;
+
+ int limit = round (dx * (n_samples - 1));
+ const int idx_offset = round (((x0 - xfront)/xextent) * (n_samples - 1));
+
+ for (i = 0; i <= limit; i++) {
+ double y, t;
+ Points::size_type index;
+
+ t = i / dx / (n_samples - 1);