123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- #include "sys-defines.h"
- #include "extern.h"
- int
- _API_fline (R___(Plotter *_plotter) double x0, double y0, double x1, double y1)
- {
- if (!_plotter->data->open)
- {
- _plotter->error (R___(_plotter)
- "fline: invalid operation");
- return -1;
- }
- if (_plotter->drawstate->path != (plPath *)NULL
- && (_plotter->drawstate->path->type != PATH_SEGMENT_LIST
- ||
- (_plotter->drawstate->path->type == PATH_SEGMENT_LIST
- && _plotter->drawstate->path->primitive)))
-
- _API_endpath (S___(_plotter));
-
- if (x0 != _plotter->drawstate->pos.x
- || y0 != _plotter->drawstate->pos.y)
- {
- if (_plotter->drawstate->path)
- _API_endpath (S___(_plotter));
- _plotter->drawstate->pos.x = x0;
- _plotter->drawstate->pos.y = y0;
- }
- return _API_fcont (R___(_plotter) x1, y1);
- }
- int
- _API_fcont (R___(Plotter *_plotter) double x, double y)
- {
- int prev_num_segments;
- plPoint p0, p1;
- if (!_plotter->data->open)
- {
- _plotter->error (R___(_plotter)
- "fcont: invalid operation");
- return -1;
- }
- if (_plotter->drawstate->path != (plPath *)NULL
- && (_plotter->drawstate->path->type != PATH_SEGMENT_LIST
- ||
- (_plotter->drawstate->path->type == PATH_SEGMENT_LIST
- && _plotter->drawstate->path->primitive)))
-
- _API_endpath (S___(_plotter));
- p0 = _plotter->drawstate->pos;
- p1.x = x; p1.y = y;
- if (_plotter->drawstate->path == (plPath *)NULL)
-
- {
- _plotter->drawstate->path = _new_plPath ();
- prev_num_segments = 0;
- _add_moveto (_plotter->drawstate->path, p0);
- }
- else
- prev_num_segments = _plotter->drawstate->path->num_segments;
-
- if (_plotter->data->have_mixed_paths == false
- && _plotter->drawstate->path->num_segments == 2)
- {
- _pl_g_maybe_replace_arc (S___(_plotter));
- if (_plotter->drawstate->path->num_segments > 2)
- prev_num_segments = 0;
- }
-
- _add_line (_plotter->drawstate->path, p1);
-
- _plotter->drawstate->pos = p1;
-
- _plotter->maybe_prepaint_segments (R___(_plotter) prev_num_segments);
-
- if ((_plotter->drawstate->path->num_segments
- >= _plotter->data->max_unfilled_path_length)
- && (_plotter->drawstate->fill_type == 0)
- && _plotter->path_is_flushable (S___(_plotter)))
- _API_endpath (S___(_plotter));
-
- return 0;
- }
- void
- _pl_g_maybe_replace_arc (S___(Plotter *_plotter))
- {
-
- if (!(_plotter->data->have_mixed_paths == false
- && _plotter->drawstate->path->num_segments == 2))
- return;
- switch (_plotter->drawstate->path->segments[1].type)
- {
- plPoint pc, pd, p1;
-
- case S_ARC:
-
- pc = _plotter->drawstate->path->segments[1].pc;
- p1 = _plotter->drawstate->path->segments[1].p;
- _plotter->drawstate->path->num_segments = 1;
-
- _add_arc_as_lines (_plotter->drawstate->path, pc, p1);
- break;
-
- case S_ELLARC:
-
- pc = _plotter->drawstate->path->segments[1].pc;
- p1 = _plotter->drawstate->path->segments[1].p;
- _plotter->drawstate->path->num_segments = 1;
-
- _add_ellarc_as_lines (_plotter->drawstate->path, pc, p1);
- break;
- case S_QUAD:
-
- pc = _plotter->drawstate->path->segments[1].pc;
- p1 = _plotter->drawstate->path->segments[1].p;
- _plotter->drawstate->path->num_segments = 1;
-
- _add_bezier2_as_lines (_plotter->drawstate->path, pc, p1);
- break;
- case S_CUBIC:
-
- pc = _plotter->drawstate->path->segments[1].pc;
- pd = _plotter->drawstate->path->segments[1].pd;
- p1 = _plotter->drawstate->path->segments[1].p;
- _plotter->drawstate->path->num_segments = 1;
-
- _add_bezier3_as_lines (_plotter->drawstate->path, pc, pd, p1);
- break;
- default:
-
- break;
- }
- }
|