coord.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include "grap.h"
  13. #include "y.tab.h"
  14. char *dflt_coord = "gg";
  15. char *curr_coord = "gg";
  16. int ncoord = 0; /* number of explicit coord's given */
  17. Point xcoord;
  18. Point ycoord;
  19. int xcflag = 0; /* 1 if xcoord set */
  20. int ycflag = 0;
  21. int logcoord = 0;
  22. void coord_x(Point pt) /* remember x coord */
  23. {
  24. xcoord = pt;
  25. xcflag = 1;
  26. margin = 0; /* no extra space around picture if explicit coords */
  27. }
  28. void coord_y(Point pt)
  29. {
  30. ycoord = pt;
  31. ycflag = 1;
  32. margin = 0; /* no extra space if explicit coords */
  33. }
  34. void coordlog(int n) /* remember log scaling */
  35. {
  36. logcoord = n;
  37. }
  38. void coord(Obj *p) /* set coord range */
  39. {
  40. static char buf[10];
  41. ncoord++;
  42. if (ncoord > 1 && strcmp(p->name, dflt_coord) == 0) {
  43. /* resetting default coordinate by implication */
  44. sprintf(buf, "gg%d", ncoord);
  45. dflt_coord = buf;
  46. p = lookup(dflt_coord, 1);
  47. }
  48. if (xcflag) {
  49. p->coord |= XFLAG;
  50. p->pt.x = min(xcoord.x,xcoord.y); /* "xcoord" is xmin, xmax */
  51. p->pt1.x = max(xcoord.x,xcoord.y);
  52. if ((logcoord&XFLAG) && p->pt.x <= 0.0)
  53. ERROR "can't have log of x coord %g,%g", p->pt.x, p->pt1.x FATAL;
  54. xcflag = 0;
  55. }
  56. if (ycflag) {
  57. p->coord |= YFLAG;
  58. p->pt.y = min(ycoord.x,ycoord.y); /* "ycoord" is ymin, ymax */
  59. p->pt1.y = max(ycoord.x,ycoord.y);
  60. if ((logcoord&YFLAG) && p->pt.y <= 0.0)
  61. ERROR "can't have log of y coord %g,%g", p->pt.y, p->pt1.y FATAL;
  62. ycflag = 0;
  63. }
  64. p->log = logcoord;
  65. logcoord = 0;
  66. auto_x = 0;
  67. }
  68. void resetcoord(Obj *p) /* reset current coordinate */
  69. {
  70. curr_coord = p->name;
  71. }