File: h_circ.c

package info (click to toggle)
plotutils 2.0-2
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 5,964 kB
  • ctags: 2,522
  • sloc: ansic: 38,416; sh: 1,853; yacc: 856; makefile: 181; lex: 144
file content (78 lines) | stat: -rw-r--r-- 2,363 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* This file contains the circle method, which is a standard part of
   libplot.  It draws an object: a circle with center x,y and radius r. */

#include "sys-defines.h"
#include "plot.h"
#include "extern.h"

int
#ifdef _HAVE_PROTOS
_h_fcircle (double x, double y, double r)
#else
_h_fcircle (x, y, r)
     double x, y, r;
#endif
{
  double radius;

  /* if affine map from user frame to device frame is anisotropic, use
     generic class method to draw an inscribed polyline */
  if (!_plotter->drawstate->transform.uniform)
    return _g_fcircle (x, y, r);
  
  if (!_plotter->open)
    {
      _plotter->error ("fcircle: invalid operation");
      return -1;
    }

  /* otherwise use HP-GL's native circle-drawing facility, as follows */

  _plotter->endpath (); /* flush polyline if any */

  (_plotter->drawstate->pos).x = x; /* move to center (a libplot convention) */
  (_plotter->drawstate->pos).y = y;
  
  radius = sqrt(XDV(r,0)*XDV(r,0)+YDV(r,0)*YDV(r,0));
  
  /* sync pen position and line attributes, incl. pen width */
  _plotter->set_position();
  _plotter->set_attributes();
  
  if (_plotter->hpgl_version >= 1)
    /* have a polygon buffer, and will use it */
    {
      /* enter polygon mode, draw circle, exit polygon mode */
      if (_plotter->hpgl_version == 1)
	sprintf (_plotter->outbuf.current, "PM0;CI%d;PM2;", IROUND(radius));
      else			/* HP-GL/2, use small chord angle */
	sprintf (_plotter->outbuf.current, "PM0;CI%d,2;PM2;", IROUND(radius));
      _update_buffer (&_plotter->outbuf);
      /* lift pen */
      strcpy (_plotter->outbuf.current, "PU;");
      _update_buffer (&_plotter->outbuf);
      _plotter->pendown = false;
      if (_plotter->drawstate->fill_level)
	{
	  /* select appropriate pen and fill the circle */
	  _plotter->set_fill_color ();
	  strcpy (_plotter->outbuf.current, "FP;");
	  _update_buffer (&_plotter->outbuf);
	}
      /* select appropriate pen and edge the circle */
      _plotter->set_pen_color ();
      strcpy (_plotter->outbuf.current, "EP;");
      _update_buffer (&_plotter->outbuf);
    }
  else
    /* don't have a polygon buffer, won't do filling */
    {
      /* select appropriate pen */
      _plotter->set_pen_color ();
      /* draw circle */
      sprintf (_plotter->outbuf.current, "CI%d;", IROUND(radius));
      _update_buffer (&_plotter->outbuf);
    }
  
  return 0;
}