20 #include "allheaders.h" 30 #define QSPLINE_PRECISION 16 //no of steps to draw 49 for (index = 0; index < segments; index++) {
51 xcoords[index] = xstarts[index];
53 coeffs[index * 3 + 1],
54 coeffs[index * 3 + 2]);
57 xcoords[index] = xstarts[index];
71 int ypts[],
int pointcount,
83 memmove (xcoords, xstarts, (segcount + 1) *
sizeof (
inT32));
85 for (segment = 0, pointindex = 0; pointindex < pointcount; pointindex++) {
86 while (segment < segcount && xpts[pointindex] >= xstarts[segment]) {
89 ptcounts[segment] = ptcounts[segment - 1];
93 while (segment < segcount) {
96 ptcounts[segment] = ptcounts[segment - 1];
99 for (segment = 0; segment < segcount; segment++) {
102 pointindex = ptcounts[segment];
104 && xpts[pointindex] != xpts[pointindex - 1]
105 && xpts[pointindex] != xstarts[segment])
106 qlsq.
add (xstarts[segment],
108 + (ypts[pointindex] - ypts[pointindex - 1])
109 * (xstarts[segment] - xpts[pointindex - 1])
110 / (xpts[pointindex] - xpts[pointindex - 1]));
111 for (; pointindex < ptcounts[segment + 1]; pointindex++) {
112 qlsq.
add (xpts[pointindex], ypts[pointindex]);
114 if (pointindex > 0 && pointindex < pointcount
115 && xpts[pointindex] != xstarts[segment + 1])
116 qlsq.
add (xstarts[segment + 1],
118 + (ypts[pointindex] - ypts[pointindex - 1])
119 * (xstarts[segment + 1] - xpts[pointindex - 1])
120 / (xpts[pointindex] - xpts[pointindex - 1]));
122 quadratics[segment].
a = qlsq.
get_a ();
123 quadratics[segment].
b = qlsq.
get_b ();
124 quadratics[segment].
c = qlsq.
get_c ();
153 if (xcoords != NULL) {
157 if (quadratics != NULL) {
174 if (quadratics != NULL)
177 segments = source.segments;
180 memmove (xcoords, source.xcoords, (segments + 1) * sizeof (
inT32));
181 memmove (quadratics, source.quadratics, segments * sizeof (
QUAD_COEFFS));
198 index1 = spline_index (x1);
199 index2 = spline_index (x2);
201 while (index1 < index2) {
203 (double) quadratics[index1 + 1].
y ((
float) xcoords[index1 + 1]);
204 total -= (double) quadratics[index1].
y ((
float) xcoords[index1 + 1]);
222 index = spline_index (x);
223 return quadratics[index].
y (x);
233 inT32 QSPLINE::spline_index(
242 while (top - bottom > 1) {
243 index = (top + bottom) / 2;
244 if (x >= xcoords[index])
265 for (segment = 0; segment < segments; segment++) {
266 xcoords[segment] += x_shift;
267 quadratics[segment].
move (vec);
269 xcoords[segment] += x_shift;
287 leftlimit = xcoords[1];
288 rightlimit = xcoords[segments - 1];
290 if (spline2->segments < 3 || spline2->xcoords[1] > leftlimit + fraction * (rightlimit - leftlimit)
291 || spline2->xcoords[spline2->segments - 1] < rightlimit
292 - fraction * (rightlimit - leftlimit))
317 increment = xmin < xcoords[0] ? 1 : 0;
318 if (xmax > xcoords[segments])
322 xstarts = (
int *)
alloc_mem ((segments + 1 + increment) *
sizeof (int));
325 if (xmin < xcoords[0]) {
328 quads[0].
b = gradient;
329 quads[0].
c =
y (xcoords[0]) - quads[0].
b * xcoords[0];
334 for (segment = 0; segment < segments; segment++) {
335 xstarts[dest_segment] = xcoords[segment];
336 quads[dest_segment] = quadratics[segment];
339 xstarts[dest_segment] = xcoords[segment];
340 if (xmax > xcoords[segments]) {
341 quads[dest_segment].
a = 0;
342 quads[dest_segment].
b = gradient;
343 quads[dest_segment].
c =
y (xcoords[segments])
344 - quads[dest_segment].
b * xcoords[segments];
346 xstarts[dest_segment] = xmax + 1;
348 segments = dest_segment;
351 xcoords = (
inT32 *) xstarts;
362 #ifndef GRAPHICS_DISABLED 373 for (segment = 0; segment < segments; segment++) {
375 (double) (xcoords[segment + 1] -
377 x = xcoords[segment];
379 if (segment == 0 &&
step == 0)
380 window->
SetCursor(x, quadratics[segment].
y (x));
382 window->
DrawTo(x, quadratics[segment].
y (x));
398 double height =
static_cast<double>(pixGetHeight(pix));
400 const int kLineWidth = 5;
402 for (segment = 0; segment < segments; segment++) {
403 increment =
static_cast<double>((xcoords[segment + 1] -
405 x = xcoords[segment];
407 double y = height - quadratics[segment].
y(x);
408 ptaAddPt(points, x,
y);
413 switch (pixGetDepth(pix)) {
415 pixRenderPolyline(pix, points, kLineWidth, L_SET_PIXELS, 1);
418 pixRenderPolylineArb(pix, points, kLineWidth, 255, 0, 0, 1);
421 pixRenderPolyline(pix, points, kLineWidth, L_CLEAR_PIXELS, 1);
void DrawTo(int x, int y)
void extrapolate(double gradient, int left, int right)
void SetCursor(int x, int y)
void plot(ScrollView *window, ScrollView::Color colour) const
double step(double x1, double x2)
BOOL8 overlap(QSPLINE *spline2, double fraction)
#define QSPLINE_PRECISION
void add(double x, double y)
void * alloc_mem(inT32 count)
inT16 x() const
access function
QSPLINE & operator=(const QSPLINE &source)
void free_mem(void *oldchunk)