20 #include "allheaders.h" 28 #include "config_auto.h" 31 #define QSPLINE_PRECISION 16 //no of steps to draw 47 xcoords =
new int32_t[
count + 1];
50 for (index = 0; index < segments; index++) {
52 xcoords[index] = xstarts[index];
54 coeffs[index * 3 + 1],
55 coeffs[index * 3 + 2]);
58 xcoords[index] = xstarts[index];
72 int ypts[],
int pointcount,
81 xcoords =
new int32_t[segcount + 1];
82 ptcounts =
new int32_t[segcount + 1];
84 memmove (xcoords, xstarts, (segcount + 1) *
sizeof (int32_t));
86 for (segment = 0, pointindex = 0; pointindex < pointcount; pointindex++) {
87 while (segment < segcount && xpts[pointindex] >= xstarts[segment]) {
90 ptcounts[segment] = ptcounts[segment - 1];
94 while (segment < segcount) {
97 ptcounts[segment] = ptcounts[segment - 1];
100 for (segment = 0; segment < segcount; segment++) {
103 pointindex = ptcounts[segment];
105 && xpts[pointindex] != xpts[pointindex - 1]
106 && xpts[pointindex] != xstarts[segment])
107 qlsq.
add (xstarts[segment],
109 + (ypts[pointindex] - ypts[pointindex - 1])
110 * (xstarts[segment] - xpts[pointindex - 1])
111 / (xpts[pointindex] - xpts[pointindex - 1]));
112 for (; pointindex < ptcounts[segment + 1]; pointindex++) {
113 qlsq.
add (xpts[pointindex], ypts[pointindex]);
115 if (pointindex > 0 && pointindex < pointcount
116 && xpts[pointindex] != xstarts[segment + 1])
117 qlsq.
add (xstarts[segment + 1],
119 + (ypts[pointindex] - ypts[pointindex - 1])
120 * (xstarts[segment + 1] - xpts[pointindex - 1])
121 / (xpts[pointindex] - xpts[pointindex - 1]));
123 quadratics[segment].
a = qlsq.
get_a ();
124 quadratics[segment].
b = qlsq.
get_b ();
125 quadratics[segment].
c = qlsq.
get_c ();
141 quadratics =
nullptr;
169 segments = source.segments;
170 xcoords =
new int32_t[segments + 1];
172 memmove (xcoords, source.xcoords, (segments + 1) * sizeof (int32_t));
173 memmove (quadratics, source.quadratics, segments * sizeof (
QUAD_COEFFS));
190 index1 = spline_index (x1);
191 index2 = spline_index (x2);
193 while (index1 < index2) {
195 (double) quadratics[index1 + 1].
y ((
float) xcoords[index1 + 1]);
196 total -= (double) quadratics[index1].
y ((
float) xcoords[index1 + 1]);
214 index = spline_index (x);
215 return quadratics[index].
y (x);
225 int32_t QSPLINE::spline_index(
234 while (top - bottom > 1) {
235 index = (top + bottom) / 2;
236 if (x >= xcoords[index])
255 int16_t x_shift = vec.
x ();
257 for (segment = 0; segment < segments; segment++) {
258 xcoords[segment] += x_shift;
259 quadratics[segment].
move (vec);
261 xcoords[segment] += x_shift;
276 int leftlimit = xcoords[1];
277 int rightlimit = xcoords[segments - 1];
279 return !(spline2->segments < 3 || spline2->xcoords[1] > leftlimit + fraction * (rightlimit - leftlimit) ||
280 spline2->xcoords[spline2->segments - 1] < rightlimit - fraction * (rightlimit - leftlimit));
302 increment = xmin < xcoords[0] ? 1 : 0;
303 if (xmax > xcoords[segments])
307 xstarts =
new int32_t[segments + 1 + increment];
309 if (xmin < xcoords[0]) {
312 quads[0].
b = gradient;
313 quads[0].
c =
y (xcoords[0]) - quads[0].
b * xcoords[0];
318 for (segment = 0; segment < segments; segment++) {
319 xstarts[dest_segment] = xcoords[segment];
320 quads[dest_segment] = quadratics[segment];
323 xstarts[dest_segment] = xcoords[segment];
324 if (xmax > xcoords[segments]) {
325 quads[dest_segment].
a = 0;
326 quads[dest_segment].
b = gradient;
327 quads[dest_segment].
c =
y (xcoords[segments])
328 - quads[dest_segment].
b * xcoords[segments];
330 xstarts[dest_segment] = xmax + 1;
332 segments = dest_segment;
346 #ifndef GRAPHICS_DISABLED 357 for (segment = 0; segment < segments; segment++) {
359 (double) (xcoords[segment + 1] -
361 x = xcoords[segment];
363 if (segment == 0 &&
step == 0)
364 window->
SetCursor(x, quadratics[segment].
y (x));
366 window->
DrawTo(x, quadratics[segment].
y (x));
374 if (pix ==
nullptr) {
382 double height =
static_cast<double>(pixGetHeight(pix));
384 const int kLineWidth = 5;
386 for (segment = 0; segment < segments; segment++) {
387 increment =
static_cast<double>((xcoords[segment + 1] -
389 x = xcoords[segment];
391 double y = height - quadratics[segment].
y(x);
392 ptaAddPt(points, x,
y);
397 switch (pixGetDepth(pix)) {
399 pixRenderPolyline(pix, points, kLineWidth, L_SET_PIXELS, 1);
402 pixRenderPolylineArb(pix, points, kLineWidth, 255, 0, 0, 1);
405 pixRenderPolyline(pix, points, kLineWidth, L_CLEAR_PIXELS, 1);
void plot(ScrollView *window, ScrollView::Color colour) const
#define QSPLINE_PRECISION
void DrawTo(int x, int y)
void SetCursor(int x, int y)
void extrapolate(double gradient, int left, int right)
bool overlap(QSPLINE *spline2, double fraction)
void add(double x, double y)
QSPLINE & operator=(const QSPLINE &source)
double step(double x1, double x2)
int16_t x() const
access function