Merge with git+ssh://sgc@fondialog1.hum.uva.nl/fro/git/sgc.git
[sgc.git] / frompraat.c
blob0651c2bdf64d9e3d87b6111f1c55e4a6e6d7b4ff
1 #include "sgc.h"
3 void Sampled_drawInside_cairo (I, cairo_t *cr, double xmin, double xmax, double ymin, double ymax, long ilevel, int unit)
5 iam (Sampled);
6 long ixmin, ixmax, ix, startOfDefinedStretch = -1;
7 float *xarray = NULL, *yarray = NULL;
8 double previousValue = NUMundefined;
9 Function_unidirectionalAutowindow (me, & xmin, & xmax);
10 Sampled_getWindowSamples (me, xmin, xmax, & ixmin, & ixmax);
11 if (ClassFunction_isUnitLogarithmic (my methods, ilevel, unit)) {
12 ymin = ClassFunction_convertStandardToSpecialUnit (my methods, ymin, ilevel, unit);
13 ymax = ClassFunction_convertStandardToSpecialUnit (my methods, ymax, ilevel, unit);
15 if (ymax <= ymin) return;
17 xarray = NUMfvector (ixmin - 1, ixmax + 1); cherror
18 yarray = NUMfvector (ixmin - 1, ixmax + 1); cherror
19 previousValue = Sampled_getValueAtSample (me, ixmin - 1, ilevel, unit);
20 if (NUMdefined (previousValue)) {
21 startOfDefinedStretch = ixmin - 1;
22 xarray [ixmin - 1] = Sampled_indexToX (me, ixmin - 1);
23 yarray [ixmin - 1] = previousValue;
25 for (ix = ixmin; ix <= ixmax; ix ++) {
26 double x = Sampled_indexToX (me, ix), value = Sampled_getValueAtSample (me, ix, ilevel, unit);
27 if (NUMdefined (value)) {
28 if (NUMdefined (previousValue)) {
29 xarray [ix] = x;
30 yarray [ix] = value;
31 } else {
32 startOfDefinedStretch = ix - 1;
33 xarray [ix - 1] = x - 0.5 * my dx;
34 yarray [ix - 1] = value;
35 xarray [ix] = x;
36 yarray [ix] = value;
38 } else if (NUMdefined (previousValue)) {
39 Melder_assert (startOfDefinedStretch >= ixmin - 1);
40 if (ix > ixmin) {
41 xarray [ix] = x - 0.5 * my dx;
42 yarray [ix] = previousValue;
43 if (xarray [startOfDefinedStretch] < xmin) {
44 double phase = (xmin - xarray [startOfDefinedStretch]) / my dx;
45 xarray [startOfDefinedStretch] = xmin;
46 yarray [startOfDefinedStretch] = phase * yarray [startOfDefinedStretch + 1] + (1.0 - phase) * yarray [startOfDefinedStretch];
48 Graphics_polyline (g, ix + 1 - startOfDefinedStretch, & xarray [startOfDefinedStretch], & yarray [startOfDefinedStretch]);
51 startOfDefinedStretch = -1;
53 previousValue = value;
55 if (startOfDefinedStretch > -1) {
56 double x = Sampled_indexToX (me, ixmax + 1), value = Sampled_getValueAtSample (me, ixmax + 1, ilevel, unit);
57 Melder_assert (NUMdefined (previousValue));
58 if (NUMdefined (value)) {
59 xarray [ixmax + 1] = x;
60 yarray [ixmax + 1] = value;
61 } else {
62 xarray [ixmax + 1] = x - 0.5 * my dx;
63 yarray [ixmax + 1] = previousValue;
65 if (xarray [startOfDefinedStretch] < xmin) {
66 double phase = (xmin - xarray [startOfDefinedStretch]) / my dx;
67 xarray [startOfDefinedStretch] = xmin;
68 yarray [startOfDefinedStretch] = phase * yarray [startOfDefinedStretch + 1] + (1.0 - phase) * yarray [startOfDefinedStretch];
70 if (xarray [ixmax + 1] > xmax) {
71 double phase = (xarray [ixmax + 1] - xmax) / my dx;
72 xarray [ixmax + 1] = xmax;
73 yarray [ixmax + 1] = phase * yarray [ixmax] + (1.0 - phase) * yarray [ixmax + 1];
75 Graphics_polyline (g, ixmax + 2 - startOfDefinedStretch, & xarray [startOfDefinedStretch], & yarray [startOfDefinedStretch]);
77 end:
78 NUMfvector_free (xarray, ixmin - 1);
79 NUMfvector_free (yarray, ixmin - 1);
80 Melder_clearError ();