IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30606


Ignore:
Timestamp:
Feb 13, 2011, 11:15:38 AM (15 years ago)
Author:
eugene
Message:

some graphing fixes; protect status box lines from overflow

Location:
trunk/Ohana/src/kapa2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/kapa2/include/prototypes.h

    r29938 r30606  
    175175void          DrawBitmap          PROTO((Graphic *graphic, int x, int y, int dx, int dy, char *bitmap, int mode));
    176176void          CrossHairs          PROTO((Graphic *graphic, Picture *image));
    177 void          hh_hms              PROTO((char *line, double ra, double dec, char sep));
     177void          hh_hms              PROTO((char *line, double ra, double dec, char sep, int Nchar));
    178178
    179179int           SetColormap         PROTO((char *name));
  • trunk/Ohana/src/kapa2/src/PSObjects.c

    r27530 r30606  
    164164  float *x, *y;
    165165  double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by;
    166   double sx0, sy0, sx1, sy1, sxa;
     166  double sx0, sy0, sx1, sy1, sxa, sya, sxo, syo;
    167167  double X0, X1, Y0, Y1;
    168168
     
    189189  for (i = 0; (i < object[0].Npts) && !(finite(x[i]) && finite(y[i])); i++);
    190190  if (i >= object[0].Npts) return;
     191
     192  /* first valid data point */
     193  sx0 = x[i]*mxi + y[i]*mxj + bx;
     194  sy0 = x[i]*myi + y[i]*myj + by;
     195  sx0 = MIN (MAX (sx0, X0), X1);
     196  sy0 = MAX (MIN (sy0, Y0), Y1);
     197 
     198  /* find the second valid datapoint */
     199  for (i++; (i < object[0].Npts) && !(finite(x[i]) && finite(y[i])); i++);
     200  if (i >= object[0].Npts) return;
     201
     202  /* second valid data point */
     203  sx1 = x[i]*mxi + y[i]*mxj + bx;
     204  sy1 = x[i]*myi + y[i]*myj + by;
     205  sx1 = MIN (MAX (sx1, X0), X1);
     206  sy1 = MAX (MIN (sy1, Y0), Y1);
     207 
     208  /* connect first point to second point */
     209  sxa = sx0 - 0.5*(sx1 - sx0);
     210  sya = MAX (sy0, Y0);
     211  DrawLine (sx0, sy0, sxa, sy0);
     212  DrawLine (sxa, sy0, sxa, sya);
     213 
     214  /* draw segment equal distance behind first point and down to x-axis */
     215  sxa = 0.5*(sx0 + sx1);
     216  DrawLine (sx0, sy0, sxa, sy0);
     217  DrawLine (sxa, sy0, sxa, sy1);
     218  DrawLine (sxa, sy1, sx1, sy1);
     219  sx0 = sx1;
     220  sy0 = sy1;
     221 
     222  /* continue with rest of points */
     223  sxo = syo = 0;
     224  for (i++; i < object[0].Npts; i++) {
     225    if (!(finite(x[i]) && finite(y[i]))) continue;
     226    sx1 = x[i]*mxi + y[i]*mxj + bx;
     227    sy1 = x[i]*myi + y[i]*myj + by;
     228    sx1 = MIN (MAX (sx1, X0), X1);
     229    sy1 = MAX (MIN (sy1, Y0), Y1);
     230    sxa = 0.5*(sx0 + sx1);
     231    DrawLine (sx0, sy0, sxa, sy0);
     232    DrawLine (sxa, sy0, sxa, sy1);
     233    DrawLine (sxa, sy1, sx1, sy1);
     234    sxo = sx0; syo = sy0;
     235    sx0 = sx1; sy0 = sy1;
     236  }
     237 
     238  /* draw segment equal distance after last point and down to x-axis */
     239  sxa = sx1 + 0.5*(sx1 - sxo);
     240  sya = MAX (sy1, Y0);
     241  DrawLine (sx1, sy1, sxa, sy1);
     242  DrawLine (sxa, sy1, sxa, sya);
     243
     244# if (0)
    191245  sx0 = x[i]*mxi + y[i]*mxj + bx;
    192246  sy0 = x[i]*myi + y[i]*myj + by;
     
    207261    sx0 = sx1; sy0 = sy1;
    208262  }
     263# endif
    209264}
    210265
  • trunk/Ohana/src/kapa2/src/UpdateStatusBox.c

    r29539 r30606  
    2020 
    2121    bzero (line, 100);
    22     sprintf (line, "(%d x %d) @ %d                                         ",
     22    snprintf (line, 100, "(%d x %d) @ %d                                         ",
    2323             image[0].picture.dx, image[0].picture.dy, image[0].picture.expand);
    2424    XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc,
     
    2626   
    2727    bzero (line, 100);
    28     sprintf (line, "%-25s", image[0].image[0].file);
     28    snprintf (line, 100, "%-25s", image[0].image[0].file);
    2929    XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc,
    3030                 image[0].text_x + PAD1, image[0].text_y + 5*textpad + 5*PAD1, line, strlen(line));
    3131   
    3232    bzero (line, 100);
    33     sprintf (line, "(%s)                                          ", image[0].image[0].name);
     33    snprintf (line, 100, "(%s)                                          ", image[0].image[0].name);
    3434    XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc,
    3535                 image[0].text_x + PAD1, image[0].text_y + 6*textpad + 6*PAD1, line, 25);
     
    4545
    4646  if (image[0].HexValue) {
    47     sprintf (line, "%04x", (int) z);
     47      snprintf (line, 100, "%04x", (int) z);
    4848  } else {
    49     sprintf (line, "%22.3f", z);
     49      snprintf (line, 100, "%22.3f", z);
    5050  }
    5151  XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc,
     
    5353 
    5454  bzero (line, 100);
    55   sprintf (line, "%10.2f %10.2f", x, y);
     55  snprintf (line, 100, "%10.2f %10.2f", x, y);
    5656  XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc,
    5757               image[0].text_x + PAD1, image[0].text_y + 2*textpad + 2*PAD1, line, strlen(line));
     
    5959  bzero (line, 100);
    6060  if (image[0].DecimalDegrees) {
    61     sprintf (line, "%10.6f %10.6f", ra, dec);
     61    snprintf (line, 100, "%10.6f %10.6f", ra, dec);
    6262  } else {
    63     hh_hms (line, ra, dec, ':');
     63    hh_hms (line, ra, dec, ':', 100);
    6464  }
     65
    6566  XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc,
    6667               image[0].text_x + PAD1, image[0].text_y + 3*textpad + 3*PAD1, line, strlen(line));
  • trunk/Ohana/src/kapa2/src/bDrawObjects.c

    r29938 r30606  
    154154  float *x, *y;
    155155  double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by;
    156   double sx0, sy0, sx1, sy1, sxa;
     156  double sx0, sy0, sx1, sy1, sxa, sya, sxo, syo;
    157157  double X0, X1, Y0, Y1;
    158158
     
    179179  for (i = 0; (i < object[0].Npts) && !(finite(x[i]) && finite(y[i])); i++);
    180180  if (i >= object[0].Npts) return;
     181
     182  /* first valid data point */
     183  sx0 = x[i]*mxi + y[i]*mxj + bx;
     184  sy0 = x[i]*myi + y[i]*myj + by;
     185  sx0 = MIN (MAX (sx0, X0), X1);
     186  sy0 = MAX (MIN (sy0, Y0), Y1);
     187 
     188  /* find the second valid datapoint */
     189  for (i++; (i < object[0].Npts) && !(finite(x[i]) && finite(y[i])); i++);
     190  if (i >= object[0].Npts) return;
     191
     192  /* second valid data point */
     193  sx1 = x[i]*mxi + y[i]*mxj + bx;
     194  sy1 = x[i]*myi + y[i]*myj + by;
     195  sx1 = MIN (MAX (sx1, X0), X1);
     196  sy1 = MAX (MIN (sy1, Y0), Y1);
     197 
     198  /* connect first point to second point */
     199  sxa = sx0 - 0.5*(sx1 - sx0);
     200  sya = MAX (sy0, Y0);
     201  DrawLine (buffer, sx0, sy0, sxa, sy0);
     202  DrawLine (buffer, sxa, sy0, sxa, sya);
     203 
     204  /* draw segment equal distance behind first point and down to x-axis */
     205  sxa = 0.5*(sx0 + sx1);
     206  DrawLine (buffer, sx0, sy0, sxa, sy0);
     207  DrawLine (buffer, sxa, sy0, sxa, sy1);
     208  DrawLine (buffer, sxa, sy1, sx1, sy1);
     209  sx0 = sx1;
     210  sy0 = sy1;
     211 
     212  /* continue with rest of points */
     213  sxo = syo = 0;
     214  for (i++; i < object[0].Npts; i++) {
     215    if (!(finite(x[i]) && finite(y[i]))) continue;
     216    sx1 = x[i]*mxi + y[i]*mxj + bx;
     217    sy1 = x[i]*myi + y[i]*myj + by;
     218    sx1 = MIN (MAX (sx1, X0), X1);
     219    sy1 = MAX (MIN (sy1, Y0), Y1);
     220    sxa = 0.5*(sx0 + sx1);
     221    DrawLine (buffer, sx0, sy0, sxa, sy0);
     222    DrawLine (buffer, sxa, sy0, sxa, sy1);
     223    DrawLine (buffer, sxa, sy1, sx1, sy1);
     224    sxo = sx0; syo = sy0;
     225    sx0 = sx1; sy0 = sy1;
     226  }
     227 
     228  /* draw segment equal distance after last point and down to x-axis */
     229  sxa = sx1 + 0.5*(sx1 - sxo);
     230  sya = MAX (sy1, Y0);
     231  DrawLine (buffer, sx1, sy1, sxa, sy1);
     232  DrawLine (buffer, sxa, sy1, sxa, sya);
     233
     234# if (0)
    181235  sx0 = x[i]*mxi + y[i]*mxj + bx;
    182236  sy0 = x[i]*myi + y[i]*myj + by;
     
    197251    sx0 = sx1; sy0 = sy1;
    198252  }
     253# endif
    199254}
    200255
  • trunk/Ohana/src/kapa2/src/hh_hms.c

    r13320 r30606  
    11# include "Ximage.h"
    22
    3 void hh_hms (char *line, double ra, double dec, char sep) {
     3void hh_hms (char *line, double ra, double dec, char sep, int Nchar) {
    44
    55  int h, m, flag;
     
    1313  s = 3600*(ra - h - m / 60.0);
    1414  if (flag > 0)
    15     sprintf (line, " %02d%c%02d%c%04.1f  ", h, sep, m, sep, s);
     15    snprintf (line, Nchar, " %02d%c%02d%c%04.1f  ", h, sep, m, sep, s);
    1616  else
    17     sprintf (line, "-%02d%c%02d%c%04.1f  ", h, sep, m, sep, s);
     17    snprintf (line, Nchar, "-%02d%c%02d%c%04.1f  ", h, sep, m, sep, s);
    1818 
    1919  flag = SIGN(dec);
     
    2323  s = 3600*(dec - h - m / 60.0);
    2424  if (flag > 0)
    25     sprintf (&line[13], " %02d%c%02d%c%04.1f", h, sep, m, sep, s);
     25    snprintf (&line[13], Nchar, " %02d%c%02d%c%04.1f", h, sep, m, sep, s);
    2626  else
    27     sprintf (&line[13], "-%02d%c%02d%c%04.1f", h, sep, m, sep, s);
     27    snprintf (&line[13], Nchar, "-%02d%c%02d%c%04.1f", h, sep, m, sep, s);
    2828}
Note: See TracChangeset for help on using the changeset viewer.