Orbiter 2022
Combinatorial Objects
mp_graphics.cpp
Go to the documentation of this file.
1// mp_graphics.cpp
2//
3// Anton Betten
4// March 6, 2003
5
6#include "foundations.h"
7
8
9using namespace std;
10
11
12namespace orbiter {
13namespace layer1_foundations {
14namespace graphics {
15
16
17static void projective_plane_make_affine_point(int q, int x1, int x2, int x3,
18 double &a, double &b);
19static int compute_dd(int dx);
20
21
23{
24 Draw_options = NULL;
25
26 //std::string fname_mp;
27 //std::string fname_log;
28 //std::string fname_tikz;
29 //std::ofstream fp_mp;
30 //std::ofstream fp_log;
31 //std::ofstream fp_tikz;
32
33
34 f_file_open = FALSE;
35 //int user[4]; // llx/lly/urx/ury
36 //int dev[4]; // llx/lly/urx/ury
37
38 x_min = INT_MAX;
39 x_max = INT_MIN;
40 y_min = INT_MAX;
41 y_max = INT_MIN;
42 f_min_max_set = FALSE;
43
44 txt_halign = 0;
45 txt_valign = 0;
46 txt_boxed = 0;
47 txt_overwrite = 0;
48 txt_rotate = 0;
49 line_beg_style = 0;
50 line_end_style = 0; // if 1, draw an arrow
51 line_dashing = 0; // between 0 and 100 sl_udsty
52 line_thickness = 100; // 100 is the old 1
53 line_color = 1;
54 fill_interior = 0;
55 fill_color = 0;
56 fill_shape = 1;
57 fill_outline = 0;
58 fill_nofill = 0;
59
60 cur_path = 1;
61
62}
63
64
66{
67 // cout << "mp_graphics::~mp_graphics()" < endl;
68 exit(cout, 1);
69}
70
72 std::string &file_name,
73 layered_graph_draw_options *Draw_options,
74 int verbose_level)
75{
76 int f_v = (verbose_level >= 1);
78
79 if (f_v) {
80 cout << "mp_graphics::init" << endl;
81 cout << "mp_graphics::init file_name=" << file_name << endl;
82 }
83 mp_graphics::Draw_options = Draw_options;
84
85 fname_mp.assign(file_name);
86 fname_log.assign(file_name);
87 fname_tikz.assign(file_name);
88
89 ST.replace_extension_with(fname_mp, ".mp");
90 ST.replace_extension_with(fname_log, ".commands");
91 ST.replace_extension_with(fname_tikz, ".tex");
92
93 fp_mp.open(fname_mp);
94 fp_log.open(fname_log);
95 fp_tikz.open(fname_tikz);
96 f_file_open = TRUE;
97
98 user[0] = 0; //xmin;
99 user[1] = 0; //ymin;
100 user[2] = Draw_options->xin; // xmax;
101 user[3] = Draw_options->yin; // ymax;
102
103 // the identity transformation:
104
105 dev[0] = 0; // xmin;
106 dev[1] = 0; // ymin;
107 dev[2] = Draw_options->xout; // xmax;
108 dev[3] = Draw_options->yout; // ymax;
109 if (f_v) {
110 cout << "mp_graphics::init done" << endl;
111 }
112}
113
114void mp_graphics::exit(ostream &ost, int verbose_level)
115{
116 int f_v = (verbose_level >= 1);
118
119 if (f_v) {
120 cout << "mp_graphics::exit" << endl;
121 }
122 if (f_file_open) {
123 fp_mp.close();
124 fp_log.close();
125 fp_tikz.close();
126 if (f_v) {
127 ost << "mp_graphics::exit "
128 "written file " << fname_mp
129 << " of size " << Fio.file_size(fname_mp) << endl;
130 ost << "written file " << fname_log
131 << " of size " << Fio.file_size(fname_log) << endl;
132 ost << "written file " << fname_tikz
133 << " of size " << Fio.file_size(fname_tikz) << endl;
134 }
135 f_file_open = FALSE;
136 }
137 else {
138 if (f_v) {
139 cout << "mp_graphics::exit f_file_open is FALSE" << endl;
140 }
141 }
142 if (f_v) {
143 cout << "mp_graphics::exit done" << endl;
144 }
145}
146
147void mp_graphics::frame(double move_out)
148{
149 int verbose_level = 0;
150 int f_v = (verbose_level >= 1);
151 int Px[30];
152 int Py[30];
153 int x, y, dx, dy, ox, oy, Ox, Oy;
154 int xmin, ymin, xmax, ymax;
155
156
157 if (f_v) {
158 cout << "mp_graphics::frame" << endl;
159 }
160
161
162 if (f_min_max_set) {
163
164 if (f_v) {
165 cout << "mp_graphics::frame f_min_max_set" << endl;
166 cout << "out_xmin()=" << out_xmin() << endl;
167 cout << "out_xmax()=" << out_xmax() << endl;
168 cout << "out_ymin()=" << out_ymin() << endl;
169 cout << "out_ymax()=" << out_ymax() << endl;
170 cout << "x_min=" << x_min << endl;
171 cout << "x_max=" << x_max << endl;
172 cout << "y_min=" << y_min << endl;
173 cout << "y_max=" << y_max << endl;
174 }
175 int xmin_d, xmax_d;
176 int ymin_d, ymax_d;
177
178 xmin_d = x_min;
179 xmax_d = x_max;
180 ymin_d = y_min;
181 ymax_d = y_max;
182 user2dev(xmin_d, ymin_d);
183 user2dev(xmax_d, ymax_d);
184 if (f_v) {
185 cout << "xmin_d=" << xmin_d << endl;
186 cout << "xmax_d=" << xmax_d << endl;
187 cout << "ymin_d=" << ymin_d << endl;
188 cout << "ymax_d=" << ymax_d << endl;
189 }
190
191 xmin = out_xmin();
192 xmax = out_xmax();
193 ymin = ymin_d;
194 ymax = ymax_d;
195
196 }
197 else {
198 xmin = out_xmin();
199 xmax = out_xmax();
200 ymin = out_ymin();
201 ymax = out_ymax();
202
203
204 }
205
206 dx = out_xmax() - out_xmin();
207 dy = out_ymax() - out_ymin();
208
209 ox = (int)(dx * .05);
210 oy = (int)(dy * .05);
211 Ox = (int)(dx * move_out);
212 Oy = (int)(dy * move_out);
213 xmin -= Ox;
214 xmax += Ox;
215 ymin -= Oy;
216 ymax += Oy;
217
218
219 x = xmin;
220 y = ymin;
221 dev2user(x, y);
222 Px[0] = x;
223 Py[0] = y;
224 //cout << "Px[0]=" << Px[0] << endl;
225 //cout << "Py[0]=" << Py[0] << endl;
226 x = xmin + ox;
227 y = ymin;
228 dev2user(x, y);
229 Px[1] = x;
230 Py[1] = y;
231 x = xmin;
232 y = ymin + oy;
233 dev2user(x, y);
234 Px[2] = x;
235 Py[2] = y;
236
237 x = xmax;
238 y = ymin;
239 dev2user(x, y);
240 Px[3] = x;
241 Py[3] = y;
242 x = xmax - ox;
243 y = ymin;
244 dev2user(x, y);
245 Px[4] = x;
246 Py[4] = y;
247 x = xmax;
248 y = ymin + oy;
249 dev2user(x, y);
250 Px[5] = x;
251 Py[5] = y;
252
253 x = xmax;
254 y = ymax;
255 dev2user(x, y);
256 Px[6] = x;
257 Py[6] = y;
258 //cout << "Px[6]=" << Px[6] << endl;
259 //cout << "Py[6]=" << Py[6] << endl;
260 x = xmax - ox;
261 y = ymax;
262 dev2user(x, y);
263 Px[7] = x;
264 Py[7] = y;
265 x = xmax;
266 y = ymax - oy;
267 dev2user(x, y);
268 Px[8] = x;
269 Py[8] = y;
270
271 x = xmin;
272 y = ymax;
273 dev2user(x, y);
274 Px[9] = x;
275 Py[9] = y;
276 x = xmin + ox;
277 y = ymax;
278 dev2user(x, y);
279 Px[10] = x;
280 Py[10] = y;
281 x = xmin;
282 y = ymax - oy;
283 dev2user(x, y);
284 Px[11] = x;
285 Py[11] = y;
286
287 if (f_v) {
288 for (int i = 0; i < 12; i++) {
289 cout << "Px[" << i << "]=" << Px[i] << " ";
290 cout << "Py[" << i << "]=" << Py[i] << " ";
291 cout << endl;
292 }
293 }
294
295 polygon3(Px, Py, 2, 0, 1);
296 polygon3(Px, Py, 4, 3, 5);
297 polygon3(Px, Py, 7, 6, 8);
298 polygon3(Px, Py, 11, 9, 10);
299}
300
302{
303 int Px[30];
304 int Py[30];
305 int x, y, dx, dy, ox, oy, Ox, Oy;
306 int xmin, ymin, xmax, ymax;
307
308 xmin = out_xmin();
309 xmax = out_xmax();
310 ymin = out_ymin();
311 ymax = out_ymax();
312
313 cout << "mp_graphics::frame_constant_aspect_ratio:" << endl;
314 cout << xmin << "," << xmax << "," << ymin << "," << ymax << endl;
315 dx = xmax - xmin;
316 dy = ymax - ymin;
317
318 int adjust_x = 0;
319 int adjust_y = 0;
320
321 if (dx > dy) {
322 adjust_y = (dx - dy) >> 1;
323 cout << "mp_graphics::frame_constant_aspect_ratio "
324 "adjust_y=" << adjust_y << endl;
325 }
326 else {
327 adjust_x = (dy - dx) >> 1;
328 cout << "mp_graphics::frame_constant_aspect_ratio "
329 "adjust_x=" << adjust_x << endl;
330 }
331 xmin -= adjust_x;
332 xmax += adjust_x;
333 ymin -= adjust_y;
334 ymax += adjust_y;
335 cout << "mp_graphics::frame_constant_aspect_ratio after "
336 "adjustment:" << endl;
337 cout << xmin << "," << xmax << "," << ymin << "," << ymax << endl;
338 dx = xmax - xmin;
339 dy = ymax - ymin;
340
341 ox = (int)(dx * .05);
342 oy = (int)(dy * .05);
343 Ox = (int)(dx * move_out);
344 Oy = (int)(dy * move_out);
345 xmin -= Ox;
346 xmax += Ox;
347 ymin -= Oy;
348 ymax += Oy;
349
350 x = xmin;
351 y = ymin;
352 dev2user(x, y);
353 Px[0] = x;
354 Py[0] = y;
355 //cout << "Px[0]=" << Px[0] << endl;
356 //cout << "Py[0]=" << Py[0] << endl;
357 x = xmin + ox;
358 y = ymin;
359 dev2user(x, y);
360 Px[1] = x;
361 Py[1] = y;
362 x = xmin;
363 y = ymin + oy;
364 dev2user(x, y);
365 Px[2] = x;
366 Py[2] = y;
367
368 x = xmax;
369 y = ymin;
370 dev2user(x, y);
371 Px[3] = x;
372 Py[3] = y;
373 x = xmax - ox;
374 y = ymin;
375 dev2user(x, y);
376 Px[4] = x;
377 Py[4] = y;
378 x = xmax;
379 y = ymin + oy;
380 dev2user(x, y);
381 Px[5] = x;
382 Py[5] = y;
383
384 x = xmax;
385 y = ymax;
386 dev2user(x, y);
387 Px[6] = x;
388 Py[6] = y;
389 //cout << "Px[6]=" << Px[6] << endl;
390 //cout << "Py[6]=" << Py[6] << endl;
391 x = xmax - ox;
392 y = ymax;
393 dev2user(x, y);
394 Px[7] = x;
395 Py[7] = y;
396 x = xmax;
397 y = ymax - oy;
398 dev2user(x, y);
399 Px[8] = x;
400 Py[8] = y;
401
402 x = xmin;
403 y = ymax;
404 dev2user(x, y);
405 Px[9] = x;
406 Py[9] = y;
407 x = xmin + ox;
408 y = ymax;
409 dev2user(x, y);
410 Px[10] = x;
411 Py[10] = y;
412 x = xmin;
413 y = ymax - oy;
414 dev2user(x, y);
415 Px[11] = x;
416 Py[11] = y;
417
418 polygon3(Px, Py, 2, 0, 1);
419 polygon3(Px, Py, 4, 3, 5);
420 polygon3(Px, Py, 7, 6, 8);
421 polygon3(Px, Py, 11, 9, 10);
422}
423
424void mp_graphics::finish(ostream &ost, int verbose_level)
425{
426 end_figure();
427 footer();
428 exit(cout, verbose_level - 1);
429}
430
432{
433 return user[0];
434}
435
437{
438 return user[1];
439}
440
442{
443 return user[2];
444}
445
447{
448 return user[3];
449}
450
452{
453 return dev[0];
454}
455
457{
458 return dev[1];
459}
460
462{
463 return dev[2];
464}
465
467{
468 return dev[3];
469}
470
471void mp_graphics::user2dev(int &x, int &y)
472{
473 numerics Num;
474
475 Num.transform_llur(user, dev, x, y);
476}
477
478void mp_graphics::dev2user(int &x, int &y)
479{
480 numerics Num;
481
482 Num.transform_llur(dev, user, x, y);
483}
484
486{
487 numerics Num;
488
489 Num.transform_dist_x(user, dev, x);
490}
491
493{
494 numerics Num;
495
496 Num.transform_dist_y(user, dev, y);
497}
498
500 int nb_circles, int nb_rays, double x_stretch)
501{
502 int N = 1000;
503 int number;
504 int i;
505 double dr;
506 int *Px;
507 int *Py;
508 double *Dx;
509 double *Dy;
510 double dx = 1.;
511 double dy = 1.;
512 numerics Num;
513
514 dr = r_max / nb_circles;
515
516 sl_thickness(100);
517 //G.sf_color(1);
518 //G.sf_interior(10);
519 Px = NEW_int(N);
520 Py = NEW_int(N);
521 Dx = new double[N];
522 Dy = new double[N];
523
524 sf_interior(0);
525 sf_color(0);
526 Px[0] = 0;
527 Py[0] = 0;
528 for (i = 1; i <= nb_circles; i++) {
529 circle(Px[0], Py[0], (int)dx * dr * i * x_stretch);
530 }
531
532 number = nb_rays;
533 for (i = 0; i < number; i++) {
534 Num.on_circle_double(Dx, Dy, i, i * 360 / number, r_max);
535 }
536 for (i = 0; i < number; i++) {
537 Px[i] = Dx[i] * dx * x_stretch;
538 Py[i] = Dy[i] * dy * x_stretch;
539 }
540 Px[number] = 0;
541 Py[number] = 0;
542 for (i = 0; i < number; i++) {
543 polygon2(Px, Py, number, i);
544 }
545
546}
547
550 double x_min, double x_max,
551 double y_min, double y_max,
552 double dx, double dy,
553 int f_x_axis_at_y_min, int f_y_axis_at_x_min,
554 int x_mod, int y_mod, int x_tick_mod, int y_tick_mod,
555 double x_labels_offset, double y_labels_offset,
556 double x_tick_half_width, double y_tick_half_width,
557 int f_v_lines, int subdivide_v, int f_h_lines, int subdivide_h,
558 int verbose_level)
559{
560 double *Dx, *Dy;
561 int *Px, *Py;
562 //double dx = x_stretch;//ONE_MILLION * 50 * x_stretch;
563 //double dy = y_stretch;//ONE_MILLION * 50 * y_stretch;
564 //double dx = ONE_MILLION * 50 * x_stretch;
565 //double dy = ONE_MILLION * 50 * y_stretch;
566 //double dx = O->xin * 0.5 / (double) (q + 1);
567 //double dy = O->yin * 0.5 / (double) (q + 1); // stretch factor
568 int N = 1000;
569 int n;
570 int i, j, h;
571 int f_v = (verbose_level >= 1);
572
573 if (f_v) {
574 cout << "mp_graphics::draw_axes_and_grid" << endl;
575 cout << "mp_graphics::draw_axes_and_grid dx=" << dx << " dy=" << dy << endl;
576 cout << "mp_graphics::draw_axes_and_grid x_min=" << x_min << " x_max=" << x_max << endl;
577 cout << "mp_graphics::draw_axes_and_grid y_min=" << y_min << " y_max=" << y_max << endl;
578 }
579
580
581
582 sl_thickness(100);
583 //sf_color(1);
584 //sf_interior(10);
585 Px = NEW_int(N);
586 Py = NEW_int(N);
587 Dx = new double[N];
588 Dy = new double[N];
589
590
591 double y0;
592 double x0;
593
594 if (f_x_axis_at_y_min) {
595 y0 = y_min;
596 }
597 else {
598 y0 = 0.;
599 }
600 if (f_y_axis_at_x_min) {
601 x0 = x_min;
602 }
603 else {
604 x0 = 0.;
605 }
606 // draw axes (with arrows):
607 Dx[0] = x_min;
608 Dy[0] = y0;
609 Dx[1] = x_max - y_labels_offset;
610 Dy[1] = y0;
611
612 Dx[2] = x0;
613 Dy[2] = y_min;
614 Dx[3] = x0;
615 Dy[3] = y_max - x_labels_offset;
616
617
618 for (i = 0; i < 4; i++) {
619 Px[i] = Dx[i] * dx;
620 if (f_v) {
621 cout << "mp_graphics::draw_axes_and_grid "
622 "Dx[i]=" << Dx[i] << " dx=" << dx << " Px[i]=" << Px[i] << endl;
623 }
624 Py[i] = Dy[i] * dy;
625 }
626
627 sl_ends(0 /* line_beg_style */, 1 /* line_end_style */);
628 polygon2(Px, Py, 0, 1);
629 polygon2(Px, Py, 2, 3);
630
631 sl_ends(0 /* line_beg_style */, 0 /* line_end_style */);
632
633 // draw x_ticks:
634 j = 0;
635 for (i = (int)x_min; i <= (int)x_max; i++) {
636 if ((i % x_tick_mod) && (i != (int)x_min) && (i != (int)x_max)) {
637 continue;
638 }
639 Dx[j] = i;
640 Dy[j] = y0 + (-1) * x_tick_half_width;
641 j++;
642 Dx[j] = i;
643 Dy[j] = y0 + 1 * x_tick_half_width;
644 j++;
645 }
646 n = j;
647 for (i = 0; i < n; i++) {
648 Px[i] = Dx[i] * dx;
649 Py[i] = Dy[i] * dy;
650 }
651 j = 0;
652 for (i = (int)x_min; i <= (int)x_max; i++) {
653 if ((i % x_tick_mod) && (i != (int)x_min) && (i != (int)x_max)) {
654 continue;
655 }
656 polygon2(Px, Py, j, j + 1);
657 j += 2;
658 }
659
660
661 // draw y_ticks:
662 j = 0;
663 for (i = (int)y_min; i <= (int)y_max; i++) {
664 if ((i % y_tick_mod) && (i != (int)y_min) && (i != (int)y_max)) {
665 continue;
666 }
667 Dx[j] = x0 + (-1) * y_tick_half_width;
668 Dy[j] = i;
669 j++;
670 Dx[j] = x0 + 1 * y_tick_half_width;
671 Dy[j] = i;
672 j++;
673 }
674 n = j;
675 for (i = 0; i < n; i++) {
676 Px[i] = Dx[i] * dx;
677 Py[i] = Dy[i] * dy;
678 }
679 j = 0;
680 for (i = (int)y_min; i <= (int)y_max; i++) {
681 if ((i % y_tick_mod) && (i != (int)y_min) && (i != (int)y_max)) {
682 continue;
683 }
684 polygon2(Px, Py, j, j + 1);
685 j += 2;
686 }
687
688 // draw x_labels:
689 j = 0;
690 for (i = (int)x_min; i <= (int)x_max; i++) {
691 if ((i % x_tick_mod) && (i != (int)x_min) && (i != (int)x_max)) {
692 continue;
693 }
694 Dx[j] = i;
695 Dy[j] = y_min + x_labels_offset;
696 j++;
697 }
698 n = j;
699 for (i = 0; i < n; i++) {
700 Px[i] = Dx[i] * dx;
701 Py[i] = Dy[i] * dy;
702 }
703 j = 0;
704 for (i = (int)x_min; i <= (int)x_max; i++) {
705 if ((i % x_tick_mod) && (i != (int)x_min) && (i != (int)x_max)) {
706 continue;
707 }
708 char str[1000];
709 sprintf(str, "%d", i);
710 //cout << "str='" << str << "'" << endl;
711 aligned_text_array(Px, Py, j, "", str);
712 j += 1;
713 }
714
715 // draw y_labels:
716 j = 0;
717 for (i = (int)y_min; i <= (int)y_max; i++) {
718 if ((i % y_tick_mod) && (i != (int)y_min) && (i != (int)y_max)) {
719 continue;
720 }
721 Dy[j] = i;
722 Dx[j] = x_min + y_labels_offset;
723 j++;
724 }
725 n = j;
726 for (i = 0; i < n; i++) {
727 Px[i] = Dx[i] * dx;
728 Py[i] = Dy[i] * dy;
729 }
730 j = 0;
731 for (i = (int)y_min; i <= (int)y_max; i++) {
732 if ((i % y_tick_mod) && (i != (int)y_min) && (i != (int)y_max)) {
733 continue;
734 }
735 char str[1000];
736 sprintf(str, "%d", i);
737 //cout << "str='" << str << "'" << endl;
738 aligned_text_array(Px, Py, j, "", str);
739 j += 1;
740 }
741
742
743 if (f_v_lines) {
744 // draw vertical lines:
745
746 double ddx = (double) 1 / subdivide_v;
747
748 sl_thickness(35);
749 h = 0;
750 for (i = (int)x_min; i <= (int)x_max; i++) {
751 if ((i % x_mod) && (i != (int)x_min) && (i != (int)x_max)) {
752 continue;
753 }
754 for (j = 0; j <= subdivide_v; j++) {
755 if (j && i == (int)x_max) {
756 continue;
757 }
758 Dx[h] = i + (double) j * ddx;
759 Dy[h] = y_min;
760 h++;
761 Dx[h] = i + (double) j * ddx;
762 Dy[h] = y_max;
763 h++;
764 }
765 }
766 n = h;
767 for (i = 0; i < n; i++) {
768 Px[i] = Dx[i] * dx;
769 Py[i] = Dy[i] * dy;
770 }
771 h = 0;
772 for (i = (int)x_min; i <= (int)x_max; i++) {
773 if ((i % x_mod) && (i != (int)x_min) && (i != (int)x_max)) {
774 continue;
775 }
776 for (j = 0; j <= subdivide_v; j++) {
777 if (j && i == (int)x_max) {
778 continue;
779 }
780 polygon2(Px, Py, h, h + 1);
781 h += 2;
782 }
783 }
784 }
785
786 if (f_h_lines) {
787 // draw horizontal lines:
788
789
790 double ddy = (double) 1 / subdivide_h;
791
792 sl_thickness(35);
793 h = 0;
794 for (i = (int)y_min; i <= (int)y_max; i++) {
795 if ((i % y_mod) && (i != (int)y_min) && (i != (int)y_max)) {
796 continue;
797 }
798 for (j = 0; j <= subdivide_h; j++) {
799 if (j && i == (int)y_max) {
800 continue;
801 }
802 Dy[h] = i + (double) j * ddy;
803 Dx[h] = x_min;
804 h++;
805 Dy[h] = i + (double) j * ddy;
806 Dx[h] = x_max;
807 h++;
808 }
809 }
810 n = h;
811 for (i = 0; i < n; i++) {
812 Px[i] = Dx[i] * dx;
813 Py[i] = Dy[i] * dy;
814 }
815 h = 0;
816 for (i = (int)y_min; i <= (int)y_max; i++) {
817 if ((i % y_mod) && (i != (int)y_min) && (i != (int)y_max)) {
818 continue;
819 }
820 for (j = 0; j <= subdivide_h; j++) {
821 if (j && i == (int)y_max) {
822 continue;
823 }
824 polygon2(Px, Py, h, h + 1);
825 h += 2;
826 }
827 }
828 }
829
830 sl_thickness(100);
831 FREE_int(Px);
832 FREE_int(Py);
833 delete [] Dx;
834 delete [] Dy;
835
836
837
838}
839
840void mp_graphics::plot_curve(int N, int *f_DNE,
841 double *Dx, double *Dy, double dx, double dy)
842{
843 int *Px;
844 int *Py;
845 int i, j;
846 //int Dx1, Dy1, Dx2, Dy2, L1, L2;
847
848 Px = NEW_int(N);
849 Py = NEW_int(N);
850 j = 0;
851 for (i = 0; i < N; i++) {
852 if (f_DNE[i] == FALSE) {
853 Px[j] = Dx[i] * dx;
854 Py[j] = Dy[i] * dy;
855 j++;
856 //cout << "i=" << i << " Px[i]=" << Px[i]
857 // << " Py[i]=" << Py[i] << endl;
858
859#if 0
860 if (i > 2 && f_DNE[i - 1] == FALSE && f_DNE[i - 2] == FALSE) {
861 Dx1 = Px[i - 1] - Px[i - 2];
862 Dy1 = Py[i - 1] - Py[i - 2];
863 L1 = Dx1 * Dx1 + Dy1 * Dy1;
864 Dx2 = Px[i] - Px[i - 1];
865 Dy2 = Py[i] - Py[i - 1];
866 L2 = Dx2 * Dx2 + Dy2 * Dy2;
867 if (L2 > 10 * L1) {
868 f_DNE[i] = TRUE;
869 }
870 }
871#endif
872 }
873 }
874 N = j;
875
876#if 0
877 for (i = 0; i < N; i += 5) {
878 for (j = 0; j < 6; j++) {
879 if (i + j == N || f_DNE[i + j]) {
880 break;
881 }
882 }
883
884 if (j == 6) {
885 polygon6(Px, Py, i + 0, i + 1, i + 2, i + 3, i + 4, i + 5);
886 }
887 else if (j == 5) {
888 polygon5(Px, Py, i + 0, i + 1, i + 2, i + 3, i + 4);
889 }
890 else if (j == 4) {
891 polygon4(Px, Py, i + 0, i + 1, i + 2, i + 3);
892 }
893 else if (j == 3) {
894 polygon3(Px, Py, i + 0, i + 1, i + 2);
895 }
896 else if (j == 2) {
897 polygon2(Px, Py, i + 0, i + 1);
898 }
899 }
900#else
901 for (i = 0; i < N - 1; i++) {
902#if 0
903 if (f_DNE[i] || f_DNE[i + 1]) {
904 }
905 else {
906 polygon2(Px, Py, i + 0, i + 1);
907 }
908#endif
909 polygon2(Px, Py, i + 0, i + 1);
910 }
911#endif
912 FREE_int(Px);
913 FREE_int(Py);
914}
915
916
917void mp_graphics::nice_circle(int x, int y, int rad)
918{
919 //fp_log << "NiceCircle " << x << " " << y << " " << rad << endl;
920
921 sf_interior(100);
922 //sf_color(0); // 1 = black, 0 = white
923 circle(x, y, rad);
924 sf_interior(0);
925 //sf_color(1); // 1 = black, 0 = white
926 circle(x, y, rad);
927}
928
930 int x0, int y0, int x1, int y1)
931{
932 int *Px, *Py, *Idx;
933 int i;
934
935 Px = NEW_int(2);
936 Py = NEW_int(2);
937 Idx = NEW_int(2);
938
939 for (i = 0; i < 2; i++) {
940 Idx[i] = i;
941 }
942 if (F->f_matrix_notation) {
943 Px[0] = (int)(F->origin_x + y0 * F->dx);
944 Py[0] = (int)(F->origin_y + (F->m - x0) * F->dy);
945 Px[1] = (int)(F->origin_x + y1 * F->dx);
946 Py[1] = (int)(F->origin_y + (F->m - x1) * F->dy);
947 }
948 else {
949 Px[0] = (int)(F->origin_x + x0 * F->dx);
950 Py[0] = (int)(F->origin_y + y0 * F->dy);
951 Px[1] = (int)(F->origin_x + x1 * F->dx);
952 Py[1] = (int)(F->origin_y + y1 * F->dy);
953 }
954 polygon_idx(Px, Py, Idx, 2);
955 FREE_int(Px);
956 FREE_int(Py);
957 FREE_int(Idx);
958}
959
961 int x0, int y0, int x1, int y1,
962 int x2, int y2, int x3, int y3)
963{
964 int *Px, *Py, *Idx;
965 int i;
966
967 Px = NEW_int(4);
968 Py = NEW_int(4);
969 Idx = NEW_int(4);
970
971 for (i = 0; i < 4; i++) {
972 Idx[i] = i;
973 }
974 if (F->f_matrix_notation) {
975 Px[0] = (int)(F->origin_x + y0 * F->dx);
976 Py[0] = (int)(F->origin_y + (F->m - x0) * F->dy);
977 Px[1] = (int)(F->origin_x + y1 * F->dx);
978 Py[1] = (int)(F->origin_y + (F->m - x1) * F->dy);
979 Px[2] = (int)(F->origin_x + y2 * F->dx);
980 Py[2] = (int)(F->origin_y + (F->m - x2) * F->dy);
981 Px[3] = (int)(F->origin_x + y3 * F->dx);
982 Py[3] = (int)(F->origin_y + (F->m - x3) * F->dy);
983 }
984 else {
985 Px[0] = (int)(F->origin_x + x0 * F->dx);
986 Py[0] = (int)(F->origin_y + y0 * F->dy);
987 Px[1] = (int)(F->origin_x + x1 * F->dx);
988 Py[1] = (int)(F->origin_y + y1 * F->dy);
989 Px[2] = (int)(F->origin_x + x2 * F->dx);
990 Py[2] = (int)(F->origin_y + y2 * F->dy);
991 Px[3] = (int)(F->origin_x + x3 * F->dx);
992 Py[3] = (int)(F->origin_y + y3 * F->dy);
993 }
994 polygon_idx(Px, Py, Idx, 4);
995 FREE_int(Px);
996 FREE_int(Py);
997 FREE_int(Idx);
998}
999
1001 int x0, int y0, int x1, int y1,
1002 int x2, int y2, int x3, int y3,
1003 int x4, int y4)
1004{
1005 int *Px, *Py, *Idx;
1006 int i;
1007
1008 Px = NEW_int(5);
1009 Py = NEW_int(5);
1010 Idx = NEW_int(5);
1011
1012 for (i = 0; i < 5; i++) {
1013 Idx[i] = i;
1014 }
1015 if (F->f_matrix_notation) {
1016 Px[0] = (int)(F->origin_x + y0 * F->dx);
1017 Py[0] = (int)(F->origin_y + (F->m - x0) * F->dy);
1018 Px[1] = (int)(F->origin_x + y1 * F->dx);
1019 Py[1] = (int)(F->origin_y + (F->m - x1) * F->dy);
1020 Px[2] = (int)(F->origin_x + y2 * F->dx);
1021 Py[2] = (int)(F->origin_y + (F->m - x2) * F->dy);
1022 Px[3] = (int)(F->origin_x + y3 * F->dx);
1023 Py[3] = (int)(F->origin_y + (F->m - x3) * F->dy);
1024 Px[4] = (int)(F->origin_x + y4 * F->dx);
1025 Py[4] = (int)(F->origin_y + (F->m - x4) * F->dy);
1026 }
1027 else {
1028 Px[0] = (int)(F->origin_x + x0 * F->dx);
1029 Py[0] = (int)(F->origin_y + y0 * F->dy);
1030 Px[1] = (int)(F->origin_x + x1 * F->dx);
1031 Py[1] = (int)(F->origin_y + y1 * F->dy);
1032 Px[2] = (int)(F->origin_x + x2 * F->dx);
1033 Py[2] = (int)(F->origin_y + y2 * F->dy);
1034 Px[3] = (int)(F->origin_x + x3 * F->dx);
1035 Py[3] = (int)(F->origin_y + y3 * F->dy);
1036 Px[4] = (int)(F->origin_x + x4 * F->dx);
1037 Py[4] = (int)(F->origin_y + y4 * F->dy);
1038 }
1039 polygon_idx(Px, Py, Idx, 5);
1040 FREE_int(Px);
1041 FREE_int(Py);
1042 FREE_int(Idx);
1043}
1044
1045void mp_graphics::polygon(int *Px, int *Py, int n)
1046{
1047 int *Idx = NEW_int(n);
1048 int i;
1049
1050 polygon_log(Px, Py, n);
1051 for (i = 0; i < n; i++) {
1052 Idx[i] = i;
1053 }
1054 polygon_idx(Px, Py, Idx, n);
1055 FREE_int(Idx);
1056}
1057
1058void mp_graphics::polygon2(int *Px, int *Py, int i1, int i2)
1059{
1060 int Idx[2];
1061 Idx[0] = i1;
1062 Idx[1] = i2;
1063 polygon_idx(Px, Py, Idx, 2);
1064}
1065
1066void mp_graphics::polygon3(int *Px, int *Py,
1067 int i1, int i2, int i3)
1068{
1069 int Idx[3];
1070 Idx[0] = i1;
1071 Idx[1] = i2;
1072 Idx[2] = i3;
1073 polygon_idx(Px, Py, Idx, 3);
1074}
1075
1076void mp_graphics::polygon4(int *Px, int *Py,
1077 int i1, int i2, int i3, int i4)
1078{
1079 int Idx[4];
1080 Idx[0] = i1;
1081 Idx[1] = i2;
1082 Idx[2] = i3;
1083 Idx[3] = i4;
1084 polygon_idx(Px, Py, Idx, 4);
1085}
1086
1087void mp_graphics::polygon5(int *Px, int *Py,
1088 int i1, int i2, int i3, int i4, int i5)
1089{
1090 int Idx[5];
1091 Idx[0] = i1;
1092 Idx[1] = i2;
1093 Idx[2] = i3;
1094 Idx[3] = i4;
1095 Idx[4] = i5;
1096
1097 polygon_idx(Px, Py, Idx, 5);
1098}
1099
1100void mp_graphics::polygon6(int *Px, int *Py,
1101 int i1, int i2, int i3, int i4, int i5, int i6)
1102{
1103 int Idx[10];
1104 Idx[0] = i1;
1105 Idx[1] = i2;
1106 Idx[2] = i3;
1107 Idx[3] = i4;
1108 Idx[4] = i5;
1109 Idx[5] = i6;
1110 polygon_idx(Px, Py, Idx, 6);
1111}
1112
1113void mp_graphics::polygon7(int *Px, int *Py,
1114 int i1, int i2, int i3, int i4, int i5, int i6,
1115 int i7)
1116{
1117 int Idx[10];
1118 Idx[0] = i1;
1119 Idx[1] = i2;
1120 Idx[2] = i3;
1121 Idx[3] = i4;
1122 Idx[4] = i5;
1123 Idx[5] = i6;
1124 Idx[6] = i7;
1125 polygon_idx(Px, Py, Idx, 7);
1126}
1127
1128void mp_graphics::polygon8(int *Px, int *Py,
1129 int i1, int i2, int i3, int i4, int i5, int i6,
1130 int i7, int i8)
1131{
1132 int Idx[10];
1133 Idx[0] = i1;
1134 Idx[1] = i2;
1135 Idx[2] = i3;
1136 Idx[3] = i4;
1137 Idx[4] = i5;
1138 Idx[5] = i6;
1139 Idx[6] = i7;
1140 Idx[7] = i8;
1141 polygon_idx(Px, Py, Idx, 8);
1142}
1143
1144void mp_graphics::polygon9(int *Px, int *Py,
1145 int i1, int i2, int i3, int i4, int i5, int i6,
1146 int i7, int i8, int i9)
1147{
1148 int Idx[10];
1149 Idx[0] = i1;
1150 Idx[1] = i2;
1151 Idx[2] = i3;
1152 Idx[3] = i4;
1153 Idx[4] = i5;
1154 Idx[5] = i6;
1155 Idx[6] = i7;
1156 Idx[7] = i8;
1157 Idx[8] = i9;
1158 polygon_idx(Px, Py, Idx, 9);
1159}
1160
1161void mp_graphics::polygon10(int *Px, int *Py,
1162 int i1, int i2, int i3, int i4, int i5, int i6,
1163 int i7, int i8, int i9, int i10)
1164{
1165 int Idx[20];
1166 Idx[0] = i1;
1167 Idx[1] = i2;
1168 Idx[2] = i3;
1169 Idx[3] = i4;
1170 Idx[4] = i5;
1171 Idx[5] = i6;
1172 Idx[6] = i7;
1173 Idx[7] = i8;
1174 Idx[8] = i9;
1175 Idx[9] = i10;
1176 polygon_idx(Px, Py, Idx, 10);
1177}
1178
1179void mp_graphics::polygon11(int *Px, int *Py,
1180 int i1, int i2, int i3, int i4, int i5, int i6,
1181 int i7, int i8, int i9, int i10, int i11)
1182{
1183 int Idx[20];
1184 Idx[0] = i1;
1185 Idx[1] = i2;
1186 Idx[2] = i3;
1187 Idx[3] = i4;
1188 Idx[4] = i5;
1189 Idx[5] = i6;
1190 Idx[6] = i7;
1191 Idx[7] = i8;
1192 Idx[8] = i9;
1193 Idx[9] = i10;
1194 Idx[10] = i11;
1195 polygon_idx(Px, Py, Idx, 11);
1196}
1197
1198void mp_graphics::polygon_idx(int *Px, int *Py, int *Idx, int n)
1199{
1200 polygon_idx_log(Px, Py, Idx, n);
1201 polygon_idx2(Px, Py, Idx, n, FALSE);
1202}
1203
1204void mp_graphics::bezier(int *Px, int *Py, int n)
1205{
1206 int *Idx = NEW_int(n);
1207 int i;
1208
1209 for (i = 0; i < n; i++) {
1210 Idx[i] = i;
1211 }
1212 bezier_idx(Px, Py, Idx, n);
1213 FREE_int(Idx);
1214}
1215
1216void mp_graphics::bezier2(int *Px, int *Py,
1217 int i1, int i2)
1218{
1219 int Idx[2];
1220 Idx[0] = i1;
1221 Idx[1] = i2;
1222 bezier_idx(Px, Py, Idx, 2);
1223}
1224
1225void mp_graphics::bezier3(int *Px, int *Py,
1226 int i1, int i2, int i3)
1227{
1228 int Idx[3];
1229 Idx[0] = i1;
1230 Idx[1] = i2;
1231 Idx[2] = i3;
1232 bezier_idx(Px, Py, Idx, 3);
1233}
1234
1235void mp_graphics::bezier4(int *Px, int *Py,
1236 int i1, int i2, int i3, int i4)
1237{
1238 int Idx[4];
1239 Idx[0] = i1;
1240 Idx[1] = i2;
1241 Idx[2] = i3;
1242 Idx[3] = i4;
1243 bezier_idx(Px, Py, Idx, 4);
1244}
1245
1246void mp_graphics::bezier5(int *Px, int *Py,
1247 int i1, int i2, int i3, int i4, int i5)
1248{
1249 int Idx[5];
1250 Idx[0] = i1;
1251 Idx[1] = i2;
1252 Idx[2] = i3;
1253 Idx[3] = i4;
1254 Idx[4] = i5;
1255 bezier_idx(Px, Py, Idx, 5);
1256}
1257
1258void mp_graphics::bezier6(int *Px, int *Py,
1259 int i1, int i2, int i3, int i4, int i5, int i6)
1260{
1261 int Idx[6];
1262 Idx[0] = i1;
1263 Idx[1] = i2;
1264 Idx[2] = i3;
1265 Idx[3] = i4;
1266 Idx[4] = i5;
1267 Idx[5] = i6;
1268 bezier_idx(Px, Py, Idx, 6);
1269}
1270
1271void mp_graphics::bezier7(int *Px, int *Py,
1272 int i1, int i2, int i3, int i4, int i5, int i6, int i7)
1273{
1274 int Idx[7];
1275 Idx[0] = i1;
1276 Idx[1] = i2;
1277 Idx[2] = i3;
1278 Idx[3] = i4;
1279 Idx[4] = i5;
1280 Idx[5] = i6;
1281 Idx[6] = i7;
1282 bezier_idx(Px, Py, Idx, 7);
1283}
1284
1285void mp_graphics::bezier_idx(int *Px, int *Py, int *Idx, int n)
1286{
1287 bezier_idx_log(Px, Py, Idx, n);
1288 bezier_idx2(Px, Py, Idx, n, FALSE);
1289}
1290
1292 int x0, int y0, int x1, int y1,
1293 int x2, int y2, int x3, int y3)
1294{
1295 int *Px, *Py, *Idx;
1296 int i;
1297
1298 Px = NEW_int(4);
1299 Py = NEW_int(4);
1300 Idx = NEW_int(4);
1301
1302 for (i = 0; i < 4; i++) {
1303 Idx[i] = i;
1304 }
1305 if (F->f_matrix_notation) {
1306 Px[0] = (int)(F->origin_x + y0 * F->dx);
1307 Py[0] = (int)(F->origin_y + (F->m - x0) * F->dy);
1308 Px[1] = (int)(F->origin_x + y1 * F->dx);
1309 Py[1] = (int)(F->origin_y + (F->m - x1) * F->dy);
1310 Px[2] = (int)(F->origin_x + y2 * F->dx);
1311 Py[2] = (int)(F->origin_y + (F->m - x2) * F->dy);
1312 Px[3] = (int)(F->origin_x + y3 * F->dx);
1313 Py[3] = (int)(F->origin_y + (F->m - x3) * F->dy);
1314 }
1315 else {
1316 Px[0] = (int)(F->origin_x + x0 * F->dx);
1317 Py[0] = (int)(F->origin_y + y0 * F->dy);
1318 Px[1] = (int)(F->origin_x + x1 * F->dx);
1319 Py[1] = (int)(F->origin_y + y1 * F->dy);
1320 Px[2] = (int)(F->origin_x + x2 * F->dx);
1321 Py[2] = (int)(F->origin_y + y2 * F->dy);
1322 Px[3] = (int)(F->origin_x + x3 * F->dx);
1323 Py[3] = (int)(F->origin_y + y3 * F->dy);
1324 }
1325 fill_idx(Px, Py, Idx, 4, "--", TRUE);
1326 FREE_int(Px);
1327 FREE_int(Py);
1328 FREE_int(Idx);
1329}
1330
1332 int x0, int y0, int x1, int y1, int x2, int y2,
1333 int x3, int y3, int x4, int y4)
1334{
1335 int *Px, *Py, *Idx;
1336 int i;
1337
1338 Px = NEW_int(5);
1339 Py = NEW_int(5);
1340 Idx = NEW_int(5);
1341
1342 for (i = 0; i < 5; i++) {
1343 Idx[i] = i;
1344 }
1345 if (F->f_matrix_notation) {
1346 Px[0] = (int)(F->origin_x + y0 * F->dx);
1347 Py[0] = (int)(F->origin_y + (F->m - x0) * F->dy);
1348 Px[1] = (int)(F->origin_x + y1 * F->dx);
1349 Py[1] = (int)(F->origin_y + (F->m - x1) * F->dy);
1350 Px[2] = (int)(F->origin_x + y2 * F->dx);
1351 Py[2] = (int)(F->origin_y + (F->m - x2) * F->dy);
1352 Px[3] = (int)(F->origin_x + y3 * F->dx);
1353 Py[3] = (int)(F->origin_y + (F->m - x3) * F->dy);
1354 Px[4] = (int)(F->origin_x + y4 * F->dx);
1355 Py[4] = (int)(F->origin_y + (F->m - x4) * F->dy);
1356 }
1357 else {
1358 Px[0] = (int)(F->origin_x + x0 * F->dx);
1359 Py[0] = (int)(F->origin_y + y0 * F->dy);
1360 Px[1] = (int)(F->origin_x + x1 * F->dx);
1361 Py[1] = (int)(F->origin_y + y1 * F->dy);
1362 Px[2] = (int)(F->origin_x + x2 * F->dx);
1363 Py[2] = (int)(F->origin_y + y2 * F->dy);
1364 Px[3] = (int)(F->origin_x + x3 * F->dx);
1365 Py[3] = (int)(F->origin_y + y3 * F->dy);
1366 Px[4] = (int)(F->origin_x + x4 * F->dx);
1367 Py[4] = (int)(F->origin_y + y4 * F->dy);
1368 }
1369 fill_idx(Px, Py, Idx, 5, "--", TRUE);
1370 FREE_int(Px);
1371 FREE_int(Py);
1372 FREE_int(Idx);
1373}
1374
1375void mp_graphics::fill_polygon3(int *Px, int *Py,
1376 int i1, int i2, int i3)
1377{
1378 int Idx[10];
1379 Idx[0] = i1;
1380 Idx[1] = i2;
1381 Idx[2] = i3;
1382 fill_idx(Px, Py, Idx, 3, "--", FALSE);
1383}
1384
1385void mp_graphics::fill_polygon4(int *Px, int *Py,
1386 int i1, int i2, int i3, int i4)
1387{
1388 int Idx[10];
1389 Idx[0] = i1;
1390 Idx[1] = i2;
1391 Idx[2] = i3;
1392 Idx[3] = i4;
1393 fill_idx(Px, Py, Idx, 4, "--", FALSE);
1394}
1395
1396void mp_graphics::fill_polygon5(int *Px, int *Py,
1397 int i1, int i2, int i3, int i4, int i5)
1398{
1399 int Idx[10];
1400 Idx[0] = i1;
1401 Idx[1] = i2;
1402 Idx[2] = i3;
1403 Idx[3] = i4;
1404 Idx[4] = i5;
1405 fill_idx(Px, Py, Idx, 5, "--", FALSE);
1406}
1407
1408void mp_graphics::fill_polygon6(int *Px, int *Py,
1409 int i1, int i2, int i3, int i4, int i5, int i6)
1410{
1411 int Idx[10];
1412 Idx[0] = i1;
1413 Idx[1] = i2;
1414 Idx[2] = i3;
1415 Idx[3] = i4;
1416 Idx[4] = i5;
1417 Idx[5] = i6;
1418 fill_idx(Px, Py, Idx, 6, "--", FALSE);
1419}
1420
1421void mp_graphics::fill_polygon7(int *Px, int *Py,
1422 int i1, int i2, int i3, int i4, int i5, int i6,
1423 int i7)
1424{
1425 int Idx[10];
1426 Idx[0] = i1;
1427 Idx[1] = i2;
1428 Idx[2] = i3;
1429 Idx[3] = i4;
1430 Idx[4] = i5;
1431 Idx[5] = i6;
1432 Idx[6] = i7;
1433 fill_idx(Px, Py, Idx, 7, "--", FALSE);
1434}
1435
1436void mp_graphics::fill_polygon8(int *Px, int *Py,
1437 int i1, int i2, int i3, int i4, int i5, int i6,
1438 int i7, int i8)
1439{
1440 int Idx[10];
1441 Idx[0] = i1;
1442 Idx[1] = i2;
1443 Idx[2] = i3;
1444 Idx[3] = i4;
1445 Idx[4] = i5;
1446 Idx[5] = i6;
1447 Idx[6] = i7;
1448 Idx[7] = i8;
1449 fill_idx(Px, Py, Idx, 8, "--", FALSE);
1450}
1451
1452void mp_graphics::fill_polygon9(int *Px, int *Py,
1453 int i1, int i2, int i3, int i4, int i5, int i6,
1454 int i7, int i8, int i9)
1455{
1456 int Idx[10];
1457 Idx[0] = i1;
1458 Idx[1] = i2;
1459 Idx[2] = i3;
1460 Idx[3] = i4;
1461 Idx[4] = i5;
1462 Idx[5] = i6;
1463 Idx[6] = i7;
1464 Idx[7] = i8;
1465 Idx[8] = i9;
1466 fill_idx(Px, Py, Idx, 9, "--", FALSE);
1467}
1468
1469void mp_graphics::fill_polygon10(int *Px, int *Py,
1470 int i1, int i2, int i3, int i4, int i5, int i6,
1471 int i7, int i8, int i9, int i10)
1472{
1473 int Idx[20];
1474 Idx[0] = i1;
1475 Idx[1] = i2;
1476 Idx[2] = i3;
1477 Idx[3] = i4;
1478 Idx[4] = i5;
1479 Idx[5] = i6;
1480 Idx[6] = i7;
1481 Idx[7] = i8;
1482 Idx[8] = i9;
1483 Idx[9] = i10;
1484 fill_idx(Px, Py, Idx, 10, "--", FALSE);
1485}
1486
1487void mp_graphics::fill_polygon11(int *Px, int *Py,
1488 int i1, int i2, int i3, int i4, int i5, int i6,
1489 int i7, int i8, int i9, int i10, int i11)
1490{
1491 int Idx[20];
1492 Idx[0] = i1;
1493 Idx[1] = i2;
1494 Idx[2] = i3;
1495 Idx[3] = i4;
1496 Idx[4] = i5;
1497 Idx[5] = i6;
1498 Idx[6] = i7;
1499 Idx[7] = i8;
1500 Idx[8] = i9;
1501 Idx[9] = i10;
1502 Idx[10] = i11;
1503 fill_idx(Px, Py, Idx, 11, "--", FALSE);
1504}
1505
1507 int i1, int i2)
1508{
1509 int Idx[3];
1510 int X[3], Y[3];
1511
1512 X[0] = Px[i1];
1513 X[1] = Px[i2];
1514 X[2] = (Px[i1] + Px[i2]) >> 1;
1515 Y[0] = Py[i1];
1516 Y[1] = Py[i2];
1517 Y[2] = (Py[i1] + Py[i2]) >> 1;
1518
1519 sl_ends(0, 0);
1520 Idx[0] = 0;
1521 Idx[1] = 1;
1522
1523 polygon_idx(X, Y, Idx, 2);
1524
1525 sl_ends(0, 1);
1526
1527 Idx[0] = 0;
1528 Idx[1] = 2;
1529 polygon_idx(X, Y, Idx, 2);
1530
1531 sl_ends(0, 0);
1532}
1533
1535 int i1, int i2,
1536 const char *alignment, const char *txt)
1537{
1538 int Idx[3];
1539 int X[3], Y[3];
1540
1541 X[0] = Px[i1];
1542 X[1] = Px[i2];
1543 X[2] = (Px[i1] + Px[i2]) >> 1;
1544 Y[0] = Py[i1];
1545 Y[1] = Py[i2];
1546 Y[2] = (Py[i1] + Py[i2]) >> 1;
1547
1548 sl_ends(0, 0);
1549 Idx[0] = 0;
1550 Idx[1] = 1;
1551
1552 polygon_idx(X, Y, Idx, 2);
1553
1554 sl_ends(0, 1);
1555
1556 Idx[0] = 0;
1557 Idx[1] = 2;
1558 polygon_idx(X, Y, Idx, 2);
1559
1560 sl_ends(0, 0);
1561
1562 aligned_text(X[2], Y[2], alignment, txt);
1563}
1564
1566 int x, int y, const char *alignment, const char *p)
1567{
1568 int *Px, *Py;
1569
1570 Px = NEW_int(1);
1571 Py = NEW_int(1);
1572
1573 if (F->f_matrix_notation) {
1574 Px[0] = (int)(F->origin_x + y * F->dx);
1575 Py[0] = (int)(F->origin_y + (F->m - x) * F->dy);
1576 }
1577 else {
1578 Px[0] = (int)(F->origin_x + x * F->dx);
1579 Py[0] = (int)(F->origin_y + y * F->dy);
1580 }
1581 aligned_text(Px[0], Py[0], alignment, p);
1582 FREE_int(Px);
1583 FREE_int(Py);
1584}
1585
1587 const char *alignment, const char *p)
1588{
1589 //fp_log << "AlignedText " << x << " " << y << " "
1590 // << alignment << " \"" << p << "\"" << endl;
1591 aligned_text_with_offset(x, y, 0, 0, alignment, p);
1592}
1593
1594void mp_graphics::aligned_text_array(int *Px, int *Py, int idx,
1595 const char *alignment, const char *p)
1596{
1597 aligned_text(Px[idx], Py[idx], alignment, p);
1598}
1599
1601 int xoffset, int yoffset,
1602 const char *alignment, const char *p)
1603{
1604 int h_align = 1, v_align = 1;
1605 int l, i;
1606 char c;
1607
1608 //fp_log << "AlignedText " << x << " " << y << " " << xoffset
1609 // << " " << yoffset << " " << alignment << " \"" << p << "\"" << endl;
1610 l = strlen(alignment);
1611 for (i = 0; i < l; i++) {
1612 c = alignment[i];
1613 if (c == 'r')
1614 h_align = 2;
1615 else if (c == 'l')
1616 h_align = 0;
1617 else if (c == 'b')
1618 v_align = 0;
1619 else if (c == 't')
1620 v_align = 2;
1621 else {
1622 cout << "mp_graphics::aligned_text: "
1623 "unknown alignment character " << c << endl;
1624 }
1625 }
1626 //cout << "xoffset=" << xoffset << endl;
1627 //cout << "yoffset=" << yoffset << endl;
1628 //cout << "text=" << p << endl;
1629 st_alignment(h_align, v_align);
1630 text(x + xoffset, y + yoffset, p);
1631}
1632
1633
1634
1635
1636
1637
1638
1639void mp_graphics::st_alignment(int txt_halign, int txt_valign)
1640{
1641 mp_graphics::txt_halign = txt_halign;
1642 mp_graphics::txt_valign = txt_valign;
1644}
1645
1646void mp_graphics::sl_udsty(int line_dashing)
1647{
1648 mp_graphics::line_dashing = line_dashing;
1649 sl_udsty_log();
1650}
1651
1652void mp_graphics::sl_ends(int line_beg_style, int line_end_style)
1653{
1654 mp_graphics::line_beg_style = line_beg_style;
1655 mp_graphics::line_end_style = line_end_style;
1656 sl_ends_log();
1657}
1658
1659void mp_graphics::sl_thickness(int line_thickness)
1660{
1661 mp_graphics::line_thickness = line_thickness;
1664}
1665
1666void mp_graphics::sl_color(int line_color)
1667{
1668 mp_graphics::line_color = line_color;
1669 sl_color_log();
1670}
1671
1672void mp_graphics::sf_interior(int fill_interior)
1673{
1674 mp_graphics::fill_interior = fill_interior;
1676}
1677
1678void mp_graphics::sf_color(int fill_color)
1679{
1680 mp_graphics::fill_color = fill_color;
1681 sf_color_log();
1682}
1683
1684void mp_graphics::sf_outline(int fill_outline)
1685{
1686 mp_graphics::fill_outline = fill_outline;
1688}
1689
1690void mp_graphics::sf_shape(int fill_shape)
1691{
1692 mp_graphics::fill_shape = fill_shape;
1693 sf_shape_log();
1694}
1695
1696void mp_graphics::sf_nofill(int fill_nofill)
1697{
1698 mp_graphics::fill_nofill = fill_nofill;
1699 sf_nofill_log();
1700}
1701
1702void mp_graphics::st_boxed(int txt_boxed)
1703{
1704 mp_graphics::txt_boxed = txt_boxed;
1705 st_boxed_log();
1706}
1707
1708void mp_graphics::st_overwrite(int txt_overwrite)
1709{
1710 mp_graphics::txt_overwrite = txt_overwrite;
1712}
1713
1714void mp_graphics::st_rotate(int txt_rotate)
1715{
1716 mp_graphics::txt_rotate = txt_rotate;
1717 st_rotate_log();
1718}
1719
1720
1721
1722
1724{
1725 if (!f_min_max_set) {
1726 x_min = x_max = x;
1727 y_min = y_max = y;
1728 }
1729 else {
1730 x_min = MINIMUM(x_min, x);
1731 y_min = MINIMUM(y_min, y);
1732 x_max = MAXIMUM(x_max, x);
1733 y_max = MAXIMUM(y_max, y);
1734 }
1735 f_min_max_set = TRUE;
1736}
1737
1738
1739// #############################################################################
1740// output commands:
1741// #############################################################################
1742
1744{
1745
1746 f_min_max_set = FALSE;
1747 //system("rm a");
1748
1750 string str;
1751
1752 Os.get_date(str);
1753
1754 header_log(str);
1755 header_mp(str);
1756 header_tikz(str);
1757}
1758
1760{
1761 footer_log();
1762 footer_mp();
1763 footer_tikz();
1764}
1765
1766void mp_graphics::begin_figure(int factor_1000)
1767{
1768 begin_figure_mp(factor_1000);
1769}
1770
1772{
1773 end_figure_mp();
1774}
1775
1776void mp_graphics::comment(const char *p)
1777{
1778 comment_log(p);
1779 comment_mp(p);
1780 comment_tikz(p);
1781}
1782
1783
1784
1785
1786void mp_graphics::text(int x, int y, const char *p)
1787{
1788 int x1, y1;
1789
1790 //fp_log << "Text " << x << " " << y << " \"" << p << "\"" << endl;
1791
1792 x1 = x;
1793 y1 = y;
1794 coords_min_max(x1, y1);
1795 user2dev(x1, y1);
1796
1797 text_log(x1, y1, p);
1798 text_mp(x1, y1, p);
1799 text_tikz(x1, y1, p);
1800}
1801
1802void mp_graphics::circle(int x, int y, int rad)
1803{
1804 //fp_log << "Circle " << x << " " << y << " " << rad << endl;
1805
1806 //cout << "mp_graphics::circle x=" << x << " y=" << y << " rad=" << rad << endl;
1807 coords_min_max(x, y);
1808 user2dev(x, y);
1809 user2dev_dist_x(rad);
1810
1811 if (rad <= 0) rad = 1;
1812
1813 circle_log(x, y, rad);
1814 circle_mp(x, y, rad);
1815 circle_tikz(x, y, rad);
1816}
1817
1818void mp_graphics::circle_text(int x, int y, int rad, const char *p)
1819{
1820 //fp_log << "CircleText " << x << " " << y << " \"" << p << "\"" << endl;
1821
1822#if 0
1823 coords_min_max(x, y);
1824 user2dev(x, y);
1825 user2dev_dist_x(rad);
1826#endif
1827
1828 nice_circle(x, y, rad);
1829 text(x, y, p);
1830 //output_circle_text_mp(x, y, idx, p);
1831 //output_circle_text_tikz(x, y, idx, rad, p);
1832}
1833
1834#if 0
1835void mp_graphics::polygon_or_bezier_idx(int *Px, int *Py, int *Idx, int n,
1836 const char *symbol, int f_cycle)
1837{
1838 polygon_or_bezier_idx_mp(Px, Py, Idx, n, symbol, f_cycle);
1839 polygon_or_bezier_idx_tikz(Px, Py, Idx, n, symbol, f_cycle);
1840}
1841#endif
1842
1843void mp_graphics::polygon_idx2(int *Px, int *Py, int *Idx, int n,
1844 int f_cycle)
1845{
1846 polygon_idx_mp(Px, Py, Idx, n, f_cycle);
1847 polygon_idx_tikz(Px, Py, Idx, n, f_cycle);
1848}
1849
1850void mp_graphics::bezier_idx2(int *Px, int *Py, int *Idx, int n,
1851 int f_cycle)
1852{
1853 bezier_idx_mp(Px, Py, Idx, n, f_cycle);
1854 bezier_idx_tikz(Px, Py, Idx, n, f_cycle);
1855}
1856
1857void mp_graphics::fill_idx(int *Px, int *Py, int *Idx, int n,
1858 const char *symbol, int f_cycle)
1859{
1860 fill_idx_mp(Px, Py, Idx, n, symbol, f_cycle);
1861 fill_idx_tikz(fp_tikz, Px, Py, Idx, n, symbol, f_cycle);
1862}
1863
1864
1865
1866// #############################################################################
1867// device specific output commands: log file
1868// #############################################################################
1869
1870void mp_graphics::header_log(std::string &str_date)
1871{
1872 fp_log << "% file: " << fname_log << endl;
1873 fp_log << "% created by Orbiter graphics interface" << endl;
1874 fp_log << "% creation date: " << str_date << endl << endl;
1875 fp_log << "DeviceCoordinates " << dev[0] << " " << dev[1] << " " << dev[2] << " " << dev[3] << endl;
1876 fp_log << "UserCoordinates " << user[0] << " " << user[1] << " " << user[2] << " " << user[3] << endl;
1877
1878}
1879
1881{
1882 fp_log << "END_OF_FILE" << endl << endl;
1883}
1884
1885void mp_graphics::comment_log(const char *p)
1886{
1887 fp_log << "Comment " << p << endl;
1888}
1889
1891{
1892 fp_log << "st_alignment " << txt_halign << ", " << txt_valign << endl;
1893}
1894
1896{
1897 fp_log << "sl_udsty " << line_dashing << endl;
1898}
1899
1901{
1902 fp_log << "sl_ends " << line_beg_style << ", " << line_end_style << endl;
1903}
1904
1906{
1907 fp_log << "sl_thickness " << line_thickness << endl;
1908}
1909
1911{
1912 fp_log << "sl_color " << line_color << endl;
1913}
1914
1916{
1917 fp_log << "sf_interior " << fill_interior << endl;
1918}
1919
1921{
1922 fp_log << "sf_color " << fill_color << endl;
1923}
1924
1926{
1927 fp_log << "sf_shape " << fill_shape << endl;
1928}
1929
1931{
1932 fp_log << "sf_outline " << fill_outline << endl;
1933}
1934
1936{
1937 fp_log << "sf_nofill " << fill_nofill << endl;
1938}
1939
1941{
1942 fp_log << "st_boxed " << txt_boxed << endl;
1943}
1944
1946{
1947 fp_log << "st_overwrite " << txt_overwrite << endl;
1948}
1949
1951{
1952 fp_log << "st_rotate " << txt_rotate << endl;
1953}
1954
1955void mp_graphics::bezier_idx_log(int *Px, int *Py, int *Idx, int n)
1956{
1957 int i;
1958
1959 fp_log << "Bezier " << n;
1960 for (i = 0; i < n; i++) {
1961 fp_log << " " << Px[Idx[i]] << " " << Py[Idx[i]];
1962 }
1963 fp_log << endl;
1964}
1965
1966void mp_graphics::polygon_log(int *Px, int *Py, int n)
1967{
1968 int i;
1969
1970 fp_log << "Polygon " << n;
1971 for (i = 0; i < n; i++) {
1972 fp_log << " " << Px[i] << " " << Py[i];
1973 }
1974 fp_log << endl;
1975}
1976
1977void mp_graphics::polygon_idx_log(int *Px, int *Py, int *Idx, int n)
1978{
1979 int i;
1980
1981 fp_log << "Polygon " << n;
1982 for (i = 0; i < n; i++) {
1983 fp_log << " " << Px[Idx[i]] << " " << Py[Idx[i]];
1984 }
1985 fp_log << endl;
1986}
1987
1988void mp_graphics::text_log(int x1, int y1, const char *p)
1989{
1990 fp_log << "Text " << x1 << ", " << y1 << ", \"" << p << "\"" << endl;
1991}
1992
1993void mp_graphics::circle_log(int x1, int y1, int rad)
1994{
1995 fp_log << "Circle " << x1 << ", " << y1 << ", " << rad << endl;
1996}
1997
1998
1999// #############################################################################
2000// device specific output commands: metapost
2001// #############################################################################
2002
2003
2004void mp_graphics::header_mp(std::string &str_date)
2005{
2006 fp_mp << "% file: " << fname_mp << endl;
2007 fp_mp << "% created by Orbiter metapost interface" << endl;
2008 fp_mp << "% creation date: " << str_date << endl << endl;
2009 fp_mp << "input boxes" << endl << endl;
2010
2011 fp_mp << "verbatimtex" << endl;
2012 fp_mp << "\\documentclass[10pt]{article}" << endl;
2013 fp_mp << "\\usepackage[noBBpl]{mathpazo}" << endl;
2014 fp_mp << "\\usepackage{amsmath}" << endl;
2015 fp_mp << "\\usepackage{amssymb}" << endl;
2016 fp_mp << "\\begin{document}" << endl;
2017 fp_mp << "\\scriptsize" << endl;
2018 fp_mp << "etex;" << endl;
2019}
2020
2022{
2023 fp_mp << "end" << endl << endl;
2024}
2025
2026void mp_graphics::begin_figure_mp(int factor_1000)
2027{
2028 double d;
2029 char str[1000];
2030 int i, l;
2031
2032 d = (double) factor_1000 * 0.001 * 0.1;
2033
2034 //fp_mp << "defaultfont:=\"cmr7\";\n";
2035
2036 sprintf(str, "%lf", d);
2037 l = strlen(str);
2038 for (i = 0; i < l; i++) {
2039 if (str[i] == ',')
2040 str[i] = '.';
2041 }
2042 fp_mp << "u=" << str << "mm;\n";
2043 fp_mp << "beginfig(1);" << endl;
2044 fp_mp << "path p[];" << endl;
2045}
2046
2048{
2049 fp_mp << "endfig;" << endl << endl;
2050}
2051
2052void mp_graphics::comment_mp(const char *p)
2053{
2054 fp_mp << "% " << p << endl;
2055}
2056
2057void mp_graphics::text_mp(int x1, int y1, const char *p)
2058{
2059 char align[64];
2060 int lab;
2061
2062 get_alignment_mp(align);
2063 if (txt_boxed) {
2064 lab = get_label(x1, y1);
2065 fp_mp << "boxit.l" << lab << "(btex " << p << " etex);" << endl;
2066 fp_mp << lab << ".c=";
2067 output_xy_metapost(x1, y1);
2068 fp_mp << endl;
2069 if (txt_overwrite) {
2070 fp_mp << "unfill bpath " << lab << ";" << endl;
2071 }
2072 fp_mp << "drawboxed(" << lab << ");" << endl;
2073
2074 }
2075 else {
2076 fp_mp << "label" << align << "(btex " << p << " etex";
2077 if (txt_rotate) {
2078 fp_mp << " rotated " << txt_rotate;
2079 }
2080 fp_mp << ", ";
2081 output_xy_metapost(x1, y1);
2082 fp_mp << ");" << endl;
2083 }
2084}
2085
2086void mp_graphics::circle_mp(int x, int y, int rad)
2087{
2088 int X[10], Y[10], i;
2089
2090 X[0] = x + rad;
2091 Y[0] = y;
2092 X[1] = x;
2093 Y[1] = y + rad;
2094 X[2] = x - rad;
2095 Y[2] = y;
2096 X[3] = x;
2097 Y[3] = y - rad;
2098 X[4] = x + rad;
2099 Y[4] = y;
2100 fp_mp << "path pp;" << endl;
2101 //fp_mp << "pickup pencircle scaled " << line_thickness << "pt;" << endl;
2102 fp_mp << "pp = ";
2103 for (i = 0; i < 5; i++) {
2104 if (i) {
2105 fp_mp << " .. ";
2106 }
2107 output_xy_metapost(X[i], Y[i]);
2108 }
2109 fp_mp << " .. cycle;" << endl;
2110 if (fill_interior > 0) {
2111 fp_mp << "fill pp withcolor ";
2112 if (fill_interior > 99) {
2113 fp_mp << "1 ";
2114 }
2115 else {
2116 fp_mp << "." << fill_interior << " ";
2117 // fprintf(mp_draw_fp, ".%02ld ", fill_interior);
2118 }
2119 if (fill_color == 1)
2120 fp_mp << "black";
2121 else
2122 fp_mp << "white";
2123 fp_mp << ";" << endl;
2124 }
2125 else {
2126 fp_mp << "draw pp";
2127 if (line_dashing) {
2128 fp_mp << " dashed evenly";
2129 if (line_dashing != 100) {
2130 fp_mp << " scaled " << (double) line_dashing / 100.;
2131 }
2132 }
2133 fp_mp << ";" << endl;
2134 }
2135}
2136
2138 int idx, const char *text)
2139{
2140 fp_mp << "circleit.l" << idx << "(btex " << text << " etex);" << endl;
2141 fp_mp << "l" << idx << ".c = ";
2142 output_xy_metapost(x, y);
2143 fp_mp << endl;
2144 fp_mp << "unfill bpath l" << idx << ";" << endl;
2145 fp_mp << "drawboxed(l" << idx << ");" << endl;
2146}
2147
2148void mp_graphics::polygon_idx_mp(int *Px, int *Py,
2149 int *Idx, int n, int f_cycle)
2150{
2151 int x, y, i;
2152
2153 //f << "pickup pencircle scaled " << line_thickness << "pt;" << endl;
2154 if (line_end_style == 1)
2155 fp_mp << "drawarrow ";
2156 else
2157 fp_mp << "draw ";
2158 for (i = 0; i < n; i++) {
2159 x = Px[Idx[i]];
2160 y = Py[Idx[i]];
2161 coords_min_max(x, y);
2162 user2dev(x, y);
2163
2164 if (i) {
2165 fp_mp << "--";
2166 }
2167 //fp_mp << "(" << x << "u," << y << "u)";
2168 output_xy_metapost(x, y);
2169 if (((i + 1) % 30) == 0)
2170 fp_mp << endl;
2171 }
2172 if (f_cycle) {
2173 fp_mp << " " << "--" << " cycle ";
2174 }
2175
2176 if (line_dashing) {
2177 fp_mp << " dashed evenly";
2178 if (line_dashing != 100) {
2179 fp_mp << " scaled " << (double) line_dashing / 100.;
2180 }
2181 }
2182 fp_mp << ";" << endl;
2183}
2184
2185void mp_graphics::bezier_idx_mp(int *Px, int *Py,
2186 int *Idx, int n, int f_cycle)
2187{
2188 int x, y, i;
2189
2190 //f << "pickup pencircle scaled " << line_thickness << "pt;" << endl;
2191 if (line_end_style == 1)
2192 fp_mp << "drawarrow ";
2193 else
2194 fp_mp << "draw ";
2195 for (i = 0; i < n; i++) {
2196 x = Px[Idx[i]];
2197 y = Py[Idx[i]];
2198 coords_min_max(x, y);
2199 user2dev(x, y);
2200
2201 if (i) {
2202 fp_mp << "..";
2203 }
2204 //fp_mp << "(" << x << "u," << y << "u)";
2205 output_xy_metapost(x, y);
2206 if (((i + 1) % 30) == 0)
2207 fp_mp << endl;
2208 }
2209 if (f_cycle) {
2210 fp_mp << " " << ".." << " cycle ";
2211 }
2212
2213 if (line_dashing) {
2214 fp_mp << " dashed evenly";
2215 if (line_dashing != 100) {
2216 fp_mp << " scaled " << (double) line_dashing / 100.;
2217 }
2218 }
2219 fp_mp << ";" << endl;
2220}
2221
2222void mp_graphics::fill_idx_mp(int *Px, int *Py,
2223 int *Idx, int n, const char *symbol, int f_cycle)
2224{
2225 int x, y, i;
2226
2227 fp_mp << "fill buildcycle(";
2228 //fp_mp << "p[" << cur_path << "] = buildcycle(";
2229 for (i = 0; i < n; i++) {
2230 x = Px[Idx[i]];
2231 y = Py[Idx[i]];
2232 coords_min_max(x, y);
2233 user2dev(x, y);
2234
2235 if (i) {
2236 fp_mp << symbol;
2237 }
2238 output_xy_metapost(x, y);
2239 if (((i + 1) % 30) == 0)
2240 fp_mp << endl;
2241 }
2242 if (f_cycle) {
2243 fp_mp << " " << symbol << " cycle ";
2244 }
2245 fp_mp << ")";
2246
2247 //fp_mp << "fill p" << cur_path << " withcolor ";
2248 fp_mp << " withcolor ";
2249 fp_mp << ((double)fill_interior / (double) 100);
2250 if (fill_color == 0) {
2251 fp_mp << " white;" << endl;
2252 }
2253 else if (fill_color == 1) {
2254 fp_mp << " black;" << endl;
2255 }
2256 cur_path++;
2257
2258}
2259
2261{
2262 fp_mp << "(";
2264 fp_mp << ",";
2266 fp_mp << ")";
2267}
2268
2270{
2271 double d;
2272
2273 d = (double) x;
2274 d /= 1000.;
2275 fp_mp << d << "u ";
2276}
2277
2279{
2280 double d;
2281
2282 d = (double) y;
2283 d /= 1000.;
2284 fp_mp << d << "u ";
2285}
2286
2287int mp_graphics::get_label(int x, int y)
2288{
2289 static int i = 0;
2290
2291 return i++;
2292}
2293
2295{
2296 if (txt_halign == 2) {
2297 // right aligned, text to the
2298 // left of the current position
2299 if (txt_valign == 2)
2300 strcpy(align, ".llft");
2301 else if (txt_valign == 1)
2302 strcpy(align, ".lft");
2303 else if (txt_valign == 0)
2304 strcpy(align, ".ulft");
2305 }
2306 else if (txt_halign == 1) { // horizontally centered
2307 if (txt_valign == 2)
2308 strcpy(align, ".bot");
2309 else if (txt_valign == 1)
2310 strcpy(align, "");
2311 else if (txt_valign == 0)
2312 strcpy(align, ".top");
2313 }
2314 else if (txt_halign == 0) {
2315 if (txt_valign == 2)
2316 strcpy(align, ".lrt");
2317 else if (txt_valign == 1)
2318 strcpy(align, ".rt");
2319 else if (txt_valign == 0)
2320 strcpy(align, ".urt");
2321 }
2322}
2323
2325{
2326 double d;
2327
2328 d = line_thickness * 0.01;
2329 fp_mp << "pickup pencircle scaled " << d << "pt;" << endl;
2330
2331 //cout << "mp_graphics::line_thickness = "
2332 // << mp_graphics::line_thickness << endl;
2333}
2334
2335
2336
2337
2338// #############################################################################
2339// device specific output commands: tikz
2340// #############################################################################
2341
2342void mp_graphics::header_tikz(std::string &str_date)
2343{
2344 fp_tikz << "% file: " << fname_tikz << endl;
2345 fp_tikz << "% created by Orbiter tikz interface" << endl;
2346
2347 fp_tikz << "% creation date: " << str_date << endl;
2348
2349 // no extra spaces in tikz mode so that we do not create a line feed.
2350 // this allows for multiple tikz pictures on the same line
2351 fp_tikz << "% DeviceCoordinates " << dev[0] << " " << dev[1]
2352 << " " << dev[2] << " " << dev[3] << endl;
2353 fp_tikz << "% UserCoordinates " << user[0] << " " << user[1]
2354 << " " << user[2] << " " << user[3] << endl;
2355
2356 if (Draw_options->f_embedded) {
2357 fp_tikz << "\\documentclass[12pt]{article}" << endl;
2358 fp_tikz << "\\usepackage{amsmath, amssymb, amsthm}" << endl;
2359 fp_tikz << "\\usepackage{tikz} " << endl;
2360 if (Draw_options->f_sideways) {
2361 fp_tikz << "\\usepackage{rotating} " << endl;
2362 }
2363 fp_tikz << "%\\usepackage{anysize}" << endl;
2364
2365
2366 if (Draw_options->f_paperheight) {
2367 fp_tikz << "\\paperheight=" << (double) Draw_options->paperheight * 0.1 << "in" << endl;
2368 }
2369 if (Draw_options->f_paperwidth) {
2370 fp_tikz << "\\paperwidth=" << (double) Draw_options->paperwidth * 0.1 << "in" << endl;
2371 }
2372
2373 fp_tikz << "\\begin{document}" << endl;
2374 fp_tikz << "%\\bibliographystyle{plain}" << endl;
2375 fp_tikz << "\\pagestyle{empty}" << endl;
2376 }
2377
2378 if (Draw_options->f_sideways) {
2379 fp_tikz << "\\begin{sideways}" << endl;
2380 }
2381 fp_tikz << "\\begin{tikzpicture}[scale=" << Draw_options->scale
2382 << ",line width = " << Draw_options->line_width << "pt]" << endl;
2383 //fp_tikz << "\\begin{tikzpicture}[scale=.05,line width = 0.5pt]" << endl;
2384}
2385
2387{
2388 fp_tikz << "\\end{tikzpicture}" << endl;
2389 if (Draw_options->f_sideways) {
2390 fp_tikz << "\\end{sideways}" << endl;
2391 }
2392 if (Draw_options->f_embedded) {
2393 fp_tikz << "\\end{document}" << endl;
2394 }
2395}
2396
2397void mp_graphics::comment_tikz(const char *p)
2398{
2399 fp_tikz << "% " << p << endl;
2400}
2401
2402
2403void mp_graphics::text_tikz(int x1, int y1, const char *p)
2404{
2405 if (txt_overwrite) {
2406 fp_tikz << "\\draw ";
2407 output_xy_tikz(x1, y1);
2408 fp_tikz << " node[fill=white] {";
2409 fp_tikz << p;
2410 fp_tikz << "};" << endl;
2411 }
2412 else {
2413 fp_tikz << "\\draw ";
2414 output_xy_tikz(x1, y1);
2415 fp_tikz << " node{";
2416 fp_tikz << p;
2417 fp_tikz << "};" << endl;
2418 }
2419}
2420
2421
2422void mp_graphics::circle_tikz(int x, int y, int rad)
2423{
2424 //cout << "mp_graphics::circle_tikz x=" << x << " y=" << y << " rad=" << rad << endl;
2425 if (fill_interior > 0) {
2426 fp_tikz << "\\filldraw[color=";
2427 color_tikz(fp_tikz, fill_color);
2428 fp_tikz << "] ";
2429 output_xy_tikz(x, y);
2430 fp_tikz << " circle [radius = ";
2431 output_x_tikz(rad * 1);
2432 fp_tikz << "cm];" << endl;
2433 }
2434 else {
2435 fp_tikz << "\\draw ";
2436 output_xy_tikz(x, y);
2437 fp_tikz << " circle [radius = ";
2438 output_x_tikz(rad * 1);
2439 fp_tikz << "cm];" << endl;
2440 }
2441}
2442
2443
2445 int idx, int rad, const char *text)
2446{
2447 //char str[1000];
2448
2449 //sprintf(str, "%d", idx);
2450
2451 fp_tikz << "\\draw ";
2452 output_xy_tikz(x, y);
2453 fp_tikz << " circle [fill=white,radius = ";
2454 output_x_tikz(rad * 1);
2455 fp_tikz << "cm];" << endl;
2456
2457 fp_tikz << "\\draw ";
2458 output_xy_tikz(x, y);
2459 fp_tikz << " node{" << text;
2460 //fp_tikz << " node[fill=white]{" << text;
2461 fp_tikz << "};" << endl;
2462
2463}
2464
2465
2466void mp_graphics::polygon_idx_tikz(int *Px, int *Py,
2467 int *Idx, int n, int f_cycle)
2468{
2469 int f_need_comma = FALSE;
2470 int verbose_level = 0;
2471 int f_v = (verbose_level >= 1);
2472 int x, y, i;
2473
2474 fp_tikz << "\\draw [";
2475 if (line_end_style == 1 && line_beg_style == 0) {
2476 fp_tikz << "->";
2477 f_need_comma = TRUE;
2478 }
2479 else if (line_end_style == 0 && line_beg_style == 1) {
2480 fp_tikz << "<-";
2481 f_need_comma = TRUE;
2482 }
2483 else if (line_end_style == 1 && line_beg_style == 0) {
2484 fp_tikz << "<->";
2485 f_need_comma = TRUE;
2486 }
2487 if (line_thickness != 100) {
2488 if (f_need_comma) {
2489 fp_tikz << ",";
2490 }
2491 fp_tikz << "line width=" << ((double)line_thickness * 0.01) << "mm";
2492 f_need_comma = TRUE;
2493 }
2494 if (line_color != 1) {
2495 if (f_need_comma) {
2496 fp_tikz << ",";
2497 }
2498 fp_tikz << "color=";
2499 color_tikz(fp_tikz, line_color);
2500 f_need_comma = TRUE;
2501 }
2502
2503 fp_tikz << "] ";
2504 for (i = 0; i < n; i++) {
2505 x = Px[Idx[i]];
2506 y = Py[Idx[i]];
2507 if (f_v) {
2508 cout << "mp_graphics::polygon_idx_tikz x=" << x << " y=" << y << endl;
2509 }
2510 coords_min_max(x, y);
2511 user2dev(x, y);
2512 if (f_v) {
2513 cout << "mp_graphics::polygon_idx_tikz x'=" << x << " y'=" << y << endl;
2514 }
2515
2516 if (i) {
2517 fp_tikz << " -- ";
2518 }
2519 output_xy_tikz(x, y);
2520 }
2521 fp_tikz << ";" << endl;
2522}
2523
2524void mp_graphics::bezier_idx_tikz(int *Px, int *Py,
2525 int *Idx, int n, int f_cycle)
2526{
2527 int f_need_comma = FALSE;
2528 int x, y, i;
2529
2530 fp_tikz << "\\draw [";
2531 if (line_end_style == 1 && line_beg_style == 0) {
2532 fp_tikz << "->";
2533 f_need_comma = TRUE;
2534 }
2535 else if (line_end_style == 0 && line_beg_style == 1) {
2536 fp_tikz << "<-";
2537 f_need_comma = TRUE;
2538 }
2539 else if (line_end_style == 1 && line_beg_style == 0) {
2540 fp_tikz << "<->";
2541 f_need_comma = TRUE;
2542 }
2543 if (line_thickness != 100) {
2544 if (f_need_comma) {
2545 fp_tikz << ",";
2546 }
2547 fp_tikz << "line width=" << ((double)line_thickness * 0.01) << "mm";
2548 f_need_comma = TRUE;
2549 }
2550 if (line_color != 1) {
2551 if (f_need_comma) {
2552 fp_tikz << ",";
2553 }
2554 fp_tikz << "color=";
2555 color_tikz(fp_tikz, line_color);
2556 f_need_comma = TRUE;
2557 }
2558
2559 fp_tikz << "] ";
2560 for (i = 0; i < n; i++) {
2561 x = Px[Idx[i]];
2562 y = Py[Idx[i]];
2563 coords_min_max(x, y);
2564 user2dev(x, y);
2565
2566 if (i) {
2567 fp_tikz << " .. ";
2568 }
2569#if 0
2570 if (i == 1) {
2571 fp_tikz << " .. controls ";
2572 }
2573 else if (i == n - 1) {
2574 fp_tikz << " .. ";
2575 }
2576 else if (i) {
2577 fp_tikz << " and ";
2578 }
2579#endif
2580 output_xy_tikz(x, y);
2581 }
2582 fp_tikz << ";" << endl;
2583}
2584
2585void mp_graphics::color_tikz(ofstream &fp, int color)
2586{
2587 if (color == 0)
2588 fp << "white";
2589 else if (color == 1)
2590 fp << "black";
2591 else if (color == 2)
2592 fp << "red";
2593 else if (color == 3)
2594 fp << "green";
2595 else if (color == 4)
2596 fp << "blue";
2597 else if (color == 5)
2598 fp << "cyan";
2599 else if (color == 6)
2600 fp << "magenta";
2601 else if (color == 7)
2602 fp << "pink";
2603 else if (color == 8)
2604 fp << "orange";
2605 else if (color == 9)
2606 fp << "lightgray";
2607 else if (color == 10)
2608 fp << "brown";
2609 else if (color == 11)
2610 fp << "lime";
2611 else if (color == 12)
2612 fp << "olive";
2613 else if (color == 13)
2614 fp << "gray";
2615 else if (color == 14)
2616 fp << "purple";
2617 else if (color == 15)
2618 fp << "teal";
2619 else if (color == 16)
2620 fp << "violet";
2621 else if (color == 17)
2622 fp << "darkgray";
2623 else if (color == 18)
2624 fp << "lightgray";
2625 else if (color == 19)
2626 fp << "yellow";
2627 else if (color == 20)
2628 fp << "green!50!red";
2629 else if (color == 21)
2630 fp << "violet!50!red";
2631 else if (color == 22)
2632 fp << "cyan!50!red";
2633 else if (color == 23)
2634 fp << "green!50!blue";
2635 else if (color == 24)
2636 fp << "brown!50!red";
2637 else if (color == 25)
2638 fp << "purple!50!red";
2639 else {
2640 cout << "mp_graphics::color_tikz color = " << color
2641 << ", we don't have a color for this" << endl;
2642 }
2643}
2644
2645
2646// red, green, blue, cyan, magenta, yellow, black, gray,
2647// darkgray, lightgray, brown, lime, olive, orange, pink,
2648// purple, teal, violet and white.
2649
2650void mp_graphics::fill_idx_tikz(ofstream &fp, int *Px, int *Py,
2651 int *Idx, int n, const char *symbol, int f_cycle)
2652{
2653 int f_need_comma;
2654 int i, x, y;
2655
2656 fp << "\\fill [color=";
2657
2658 color_tikz(fp, fill_color);
2659#if 0
2660 if (fill_color == 0)
2661 fp << "white";
2662 else if (fill_color == 1)
2663 fp << "black";
2664 else if (fill_color == 2)
2665 fp << "red";
2666 else if (fill_color == 3)
2667 fp << "green";
2668#endif
2669
2670 if (fill_interior < 100) {
2671 fp << "!" << fill_interior;
2672 }
2673 f_need_comma = TRUE;
2674 if (line_end_style == 1 && line_beg_style == 0) {
2675 if (f_need_comma) {
2676 fp << ", ";
2677 }
2678 fp << "->";
2679 }
2680 else if (line_end_style == 0 && line_beg_style == 1) {
2681 if (f_need_comma) {
2682 fp << ", ";
2683 }
2684 fp << "<-";
2685 }
2686 else if (line_end_style == 1 && line_beg_style == 0) {
2687 if (f_need_comma) {
2688 fp << ", ";
2689 }
2690 fp << "<->";
2691 }
2692 if (line_thickness != 100) {
2693 if (f_need_comma) {
2694 fp << ", ";
2695 }
2696 fp << "line width=" << ((double)line_thickness * 0.01) << "mm";
2697 }
2698 fp << "] ";
2699 for (i = 0; i < n; i++) {
2700 x = Px[Idx[i]];
2701 y = Py[Idx[i]];
2702 coords_min_max(x, y);
2703 user2dev(x, y);
2704
2705 if (i) {
2706 fp << " -- ";
2707 }
2708 output_xy_tikz(x, y);
2709 }
2710 fp << ";" << endl;
2711
2712
2713
2714}
2715
2716#if 1
2718{
2719 fp_tikz << "(";
2720 output_x_tikz(x);
2721 fp_tikz << ",";
2722 output_y_tikz(y);
2723 fp_tikz << ")";
2724}
2725#else
2726void mp_graphics::output_xy_tikz(int x, int y)
2727{
2728 double dx, dy, x2, y2, f;
2729
2730 dx = (double) x / 30000;
2731 dy = (double) y / 30000;
2732 f = 1. / sqrt(3. * 3. + dx * dx + dy * dy);
2733 x2 = dx * f;
2734 y2 = dy * f;
2735 fp_tikz << "(";
2736 if (ABS(x2) < 0.0001) {
2737 fp_tikz << 0;
2738 }
2739 else {
2740 fp_tikz << x2 * 10;
2741 }
2742 //output_x_tikz(x);
2743 fp_tikz << ",";
2744 if (ABS(y2) < 0.0001) {
2745 fp_tikz << 0;
2746 }
2747 else {
2748 fp_tikz << y2 * 10;
2749 }
2750 //output_y_tikz(y);
2751 fp_tikz << ")";
2752}
2753#endif
2754
2756{
2757 double d;
2758
2759 d = (double) x;
2760 d /= 30000.;
2761 if (ABS(d) < 0.0001) {
2762 fp_tikz << 0;
2763 }
2764 else {
2765 fp_tikz << d;
2766 }
2767}
2768
2770{
2771 double d;
2772
2773 d = (double) y;
2774 d /= 30000.;
2775 if (ABS(d) < 0.0001) {
2776 fp_tikz << 0;
2777 }
2778 else {
2779 fp_tikz << d;
2780 }
2781}
2782
2783
2784
2785void mp_graphics::polygon3D(int *Px, int *Py,
2786 int dim, int x0, int y0, int z0, int x1, int y1, int z1)
2787{
2788 int idx0, idx1;
2789 idx0 = x0 * 9 + y0 * 3 + z0;
2790 idx1 = x1 * 9 + y1 * 3 + z1;
2791 polygon2(Px, Py, idx0, idx1);
2792}
2793
2794void mp_graphics::integer_4pts(int *Px, int *Py,
2795 int p1, int p2, int p3, int p4,
2796 const char *align, int a)
2797{
2798 char str[100];
2799
2800 sprintf(str, "%d", a);
2801 text_4pts(Px, Py, p1, p2, p3, p4, align, str);
2802}
2803
2804void mp_graphics::text_4pts(int *Px, int *Py,
2805 int p1, int p2, int p3, int p4,
2806 const char *align, const char *str)
2807{
2808 int x = Px[p1] + Px[p2] + Px[p3] + Px[p4];
2809 int y = Py[p1] + Py[p2] + Py[p3] + Py[p4];
2810 x >>= 2;
2811 y >>= 2;
2812 aligned_text(x, y, align, str);
2813}
2814
2815
2816void mp_graphics::draw_graph(int x, int y,
2817 int dx, int dy, int nb_V, long int *Edges, int nb_E, int radius,
2818 int verbose_level)
2819{
2820 int f_v = (verbose_level >= 1);
2821
2822 if (f_v) {
2823 cout << "mp_graphics::draw_graph nb_V=" << nb_V << " nb_E=" << nb_E << endl;
2824 }
2825 double *X, *Y;
2826 double h = dy * .7;
2827 double w = dx * .7;
2828 int i, e, u, v;
2829 double phi = M_PI * 2. / nb_V;
2830 int Px[2];
2831 int Py[2];
2832 int rad = radius;
2833 //int rad = (int)(dx * .05);
2835
2836 //cout << "draw_graph nb_V=" << nb_V << endl;
2837
2838 if (f_v) {
2839 cout << "mp_graphics::draw_graph edges=";
2840 //Orbiter->Int_vec.print(cout, Edges, nb_E);
2841 Lint_vec_print(cout, Edges, nb_E);
2842 cout << endl;
2843 }
2844
2845 sl_thickness(100); // was 30
2846
2847 X = new double [nb_V];
2848 Y = new double [nb_V];
2849 for (i = 0; i < nb_V; i++) {
2850 X[i] = cos(i * phi) * w;
2851 Y[i] = sin(i * phi) * h;
2852 }
2853 for (i = 0; i < nb_E; i++) {
2854 e = Edges[i];
2855 Combi.k2ij(e, u, v, nb_V);
2856 Px[0] = x + (int) X[u];
2857 Py[0] = y + (int) Y[u];
2858 Px[1] = x + (int) X[v];
2859 Py[1] = y + (int) Y[v];
2860 polygon2(Px, Py, 0, 1);
2861 }
2862 for (i = 0; i < nb_V; i++) {
2863 Px[0] = x + (int) X[i];
2864 Py[0] = y + (int) Y[i];
2865 nice_circle(Px[0], Py[0], rad);
2866 }
2867 delete X;
2868 delete Y;
2869 if (f_v) {
2870 cout << "mp_graphics::draw_graph done" << endl;
2871 }
2872}
2873
2875 int x, int y,
2876 int dx, int dy, int nb_V, long int *Edges, int nb_E,
2877 int distinguished_edge, int verbose_level)
2878{
2879 int f_v = (verbose_level >= 1);
2880 double *X, *Y;
2881 double h = dy * .7;
2882 double w = dx * .7;
2883 int i, e, u, v;
2884 double phi = M_PI * 2. / nb_V;
2885 int Px[2];
2886 int Py[2];
2887 int rad = (int)(dx * .05);
2889
2890 if (f_v) {
2891 cout << "mp_graphics::draw_graph_with_distinguished_edge "
2892 "nb_V=" << nb_V << endl;
2893 }
2894 X = new double [nb_V];
2895 Y = new double [nb_V];
2896 for (i = 0; i < nb_V; i++) {
2897 X[i] = cos(i * phi) * w;
2898 Y[i] = sin(i * phi) * h;
2899 }
2900
2901 sl_thickness(30);
2902
2903 for (i = 0; i < nb_E; i++) {
2904 e = Edges[i];
2905 Combi.k2ij(e, u, v, nb_V);
2906 Px[0] = x + (int) X[u];
2907 Py[0] = y + (int) Y[u];
2908 Px[1] = x + (int) X[v];
2909 Py[1] = y + (int) Y[v];
2910 if (distinguished_edge == i) {
2911 sl_thickness(80);
2912 }
2913 polygon2(Px, Py, 0, 1);
2914 if (distinguished_edge == i) {
2915 sl_thickness(30);
2916 }
2917 }
2918 for (i = 0; i < nb_V; i++) {
2919 Px[0] = x + (int) X[i];
2920 Py[0] = y + (int) Y[i];
2921 nice_circle(Px[0], Py[0], rad);
2922 }
2923 delete X;
2924 delete Y;
2925}
2926
2928 int dx, int dy, int nb_V, int *Edges, int nb_E, int nb_circles)
2929{
2930 double *X, *Y;
2931 double h = dy * .7;
2932 double w = dx * .7;
2933 int i, j, e, u, v;
2934 double phi;
2935 int Px[2];
2936 int Py[2];
2937 int rad = (int)(dx * .05);
2938 int nb_per_circle;
2940
2941 cout << "mp_graphics::draw_graph_on_multiple_circles "
2942 "nb_V=" << nb_V << endl;
2943 nb_per_circle = nb_V / nb_circles;
2944 cout << "nb_per_circle = " << nb_per_circle << endl;
2945 phi = M_PI * 2. / nb_per_circle;
2946 X = new double [nb_V];
2947 Y = new double [nb_V];
2948 for (j = 0; j < nb_circles; j++) {
2949 for (i = 0; i < nb_per_circle; i++) {
2950 X[j * nb_per_circle + i] = cos(i * phi) * w;
2951 Y[j * nb_per_circle + i] = sin(i * phi) * h;
2952 }
2953 w = w * .5;
2954 h = h * .5;
2955 }
2956 for (i = 0; i < nb_E; i++) {
2957 e = Edges[i];
2958 Combi.k2ij(e, u, v, nb_V);
2959 Px[0] = x + (int) X[u];
2960 Py[0] = y + (int) Y[u];
2961 Px[1] = x + (int) X[v];
2962 Py[1] = y + (int) Y[v];
2963 polygon2(Px, Py, 0, 1);
2964 }
2965 for (i = 0; i < nb_V; i++) {
2966 Px[0] = x + (int) X[i];
2967 Py[0] = y + (int) Y[i];
2968 nice_circle(Px[0], Py[0], rad);
2969 }
2970 delete X;
2971 delete Y;
2972}
2973
2975 int x, int y, int dx, int dy, int rad, int nb_V,
2976 int *Edges, int nb_E, int *coords_2D, int *Base,
2977 int f_point_labels, int point_label_offset, int f_directed)
2978{
2979 double *X, *Y;
2980 //double h = dy * .7;
2981 //double w = dx * .7;
2982 int i, u, v;
2983 int Px[2];
2984 int Py[2];
2985 //int rad = (int)(dx * .1);
2986
2987 cout << "mp_graphics::draw_graph_on_2D_grid "
2988 "nb_V=" << nb_V << endl;
2989 X = new double [nb_V];
2990 Y = new double [nb_V];
2991 for (i = 0; i < nb_V; i++) {
2992 u = coords_2D[2 * i + 0];
2993 v = coords_2D[2 * i + 1];
2994 X[i] = u * Base[0] + v * Base[2];
2995 Y[i] = u * Base[1] + v * Base[3];
2996 }
2997
2998 if (f_directed) {
2999 sl_ends(0, 1);
3000 }
3001 for (i = 0; i < nb_E; i++) {
3002 u = Edges[2 * i + 0];
3003 v = Edges[2 * i + 1];
3004 //k2ij(e, u, v, nb_V);
3005 Px[0] = x + (int) X[u];
3006 Py[0] = y + (int) Y[u];
3007 Px[1] = x + (int) X[v];
3008 Py[1] = y + (int) Y[v];
3009 polygon2(Px, Py, 0, 1);
3010 }
3011 for (i = 0; i < nb_V; i++) {
3012 Px[0] = x + (int) X[i];
3013 Py[0] = y + (int) Y[i];
3014 nice_circle(Px[0], Py[0], rad);
3015 }
3016
3017 if (f_point_labels) {
3018 char str[1000];
3019
3020 for (i = 0; i < nb_V; i++) {
3021 sprintf(str, "%d", i+ point_label_offset);
3022 Px[0] = x + (int) X[i];
3023 Py[0] = y + (int) Y[i];
3024 aligned_text(Px[0], Py[0], "", str);
3025 }
3026 }
3027 if (f_directed) {
3028 sl_ends(0, 0);
3029 }
3030 delete X;
3031 delete Y;
3032}
3033
3035 int dx, int dy, int nb_V, long int *Edges, int nb_E,
3036 int radius,
3037 int verbose_level)
3038{
3039 int f_v = (verbose_level >= 1);
3040 double *X, *Y;
3041 double h = dy * .7;
3042 double w = dx * .7;
3043 int i, a, a2, swap, u, v;
3044 double phi = M_PI * 2. / nb_V;
3045 int Px[3];
3046 int Py[3];
3047 int rad = radius;
3048 //int rad = (int)(dx * .05);
3050
3051 if (f_v) {
3052 cout << "mp_graphics::draw_tournament nb_V=" << nb_V << endl;
3053 }
3054 X = new double [nb_V];
3055 Y = new double [nb_V];
3056 for (i = 0; i < nb_V; i++) {
3057 X[i] = cos(i * phi) * w;
3058 Y[i] = sin(i * phi) * h;
3059 }
3060
3061 // draw the edges:
3062 for (i = 0; i < nb_E; i++) {
3063 a = Edges[i];
3064
3065
3066
3067 swap = a % 2;
3068 a2 = a / 2;
3069 Combi.k2ij(a2, u, v, nb_V);
3070
3071
3072
3073 Px[0] = x + (int) X[u];
3074 Py[0] = y + (int) Y[u];
3075 Px[1] = x + (int) X[v];
3076 Py[1] = y + (int) Y[v];
3077 if (swap) {
3078 Px[2] = (3 * Px[0] + Px[1]) >> 2;
3079 Py[2] = (3 * Py[0] + Py[1]) >> 2;
3080 sl_ends(0, 1);
3081 polygon2(Px, Py, 1, 2);
3082 }
3083 else {
3084 Px[2] = (Px[0] + 3 * Px[1]) >> 2;
3085 Py[2] = (Py[0] + 3 * Py[1]) >> 2;
3086 sl_ends(0, 1);
3087 polygon2(Px, Py, 0, 2);
3088 }
3089 }
3090
3091 // now draw vertices:
3092
3093 for (i = 0; i < nb_V; i++) {
3094 Px[0] = x + (int) X[i];
3095 Py[0] = y + (int) Y[i];
3096 nice_circle(Px[0], Py[0], rad);
3097 }
3098 delete X;
3099 delete Y;
3100}
3101
3103 int f_partition, int nb_row_parts, int *row_part_first,
3104 int nb_col_parts, int *col_part_first,
3105 int f_row_grid, int f_col_grid,
3106 int f_bitmatrix, data_structures::bitmatrix *Bitmatrix,
3107 int *M, int m, int n,
3108 int f_has_labels, int *labels)
3109{
3110 char str[1000];
3111 grid_frame F;
3112 int i, j, ii, jj, ij, a, cnt, mn, mtn, mtn1;
3113 int indent = 0;
3114
3115 mn = MAXIMUM(m, n);
3117 F.m = m;
3118 F.n = n;
3119 F.origin_x = 0.;
3120 F.origin_y = 0.;
3121 F.dx = ONE_MILLION / (10 * mn);
3122 F.dy = ONE_MILLION / (10 * mn);
3123
3124 cout << "draw_it2" << endl;
3125 cout << "dx=" << F.dx << endl;
3126 cout << "dy=" << F.dy << endl;
3127
3128 // draw a box around it:
3129
3130 sprintf(str, "box outline");
3131 comment(str);
3132
3133 grid_polygon2(&F, 0, 0, 10 * m, 0);
3134 grid_polygon2(&F, 10 * m, 0, 10 * m, 10 * n);
3135 grid_polygon2(&F, 10 * m, 10 * n, 0, 10 * n);
3136 grid_polygon2(&F, 0, 10 * n, 0, 0);
3137
3138 sf_interior(100);
3139 sf_color(1); // black
3140
3141
3142 sl_thickness(20); // 100 is standard
3143
3144 if (f_partition) {
3145 sprintf(str, "row partition");
3146 comment(str);
3147 for (i = 0; i < nb_row_parts + 1; i++) {
3148 sprintf(str, "part_%d", i);
3149 comment(str);
3150 ii = row_part_first[i];
3151 grid_polygon2(&F, ii * 10, 0 * 10, ii * 10, (n + 0) * 10);
3152 //G.grid_polygon2(&F, ii * 10, -1 * 10, ii * 10, (n + 1) * 10);
3153 }
3154 sprintf(str, "column partition");
3155 comment(str);
3156 for (j = 0; j < nb_col_parts + 1; j++) {
3157 sprintf(str, "part_%d", j);
3158 comment(str);
3159 jj = col_part_first[j];
3160 grid_polygon2(&F, 0 * 10, jj * 10, (m + 0) * 10, jj * 10);
3161 //G.grid_polygon2(&F, -1 * 10, jj * 10, (m + 1) * 10, jj * 10);
3162 }
3163 }
3164
3165
3166
3167
3168 sl_thickness(10); // 100 is standard
3169
3170 sf_interior(0);
3171 sf_color(1);
3172
3173 if (f_row_grid) {
3174 for (i = 0; i < m; i++) {
3175 sprintf(str, "row_%d", i);
3176 if (f_has_labels) {
3177 sprintf(str + strlen(str), " label %d", labels[i]);
3178 }
3179 comment(str);
3180 j = 0;
3182 10 * i + indent, 10 * j + indent,
3183 10 * (i + 1) - indent, 10 * j + indent,
3184 10 * (i + 1) - indent, 10 * n - indent,
3185 10 * i + indent, 10 * n - indent,
3186 10 * i + indent, 10 * j + indent);
3187 }
3188 }
3189
3190 if (f_col_grid) {
3191 for (j = 0; j < n; j++) {
3192 sprintf(str, "col_%d", j);
3193 if (f_has_labels) {
3194 sprintf(str + strlen(str), " label %d", labels[j]);
3195 }
3196 comment(str);
3197 i = 0;
3199 10 * i + indent, 10 * j + indent,
3200 10 * m - indent, 10 * j + indent,
3201 10 * m - indent, 10 * (j + 1) - indent,
3202 10 * i + indent, 10 * (j + 1) - indent,
3203 10 * i + indent, 10 * j + indent);
3204 }
3205 }
3206
3207 if (f_has_labels) {
3208 for (i = 0; i < m; i++) {
3209 sprintf(str, "%d", labels[i]);
3210 grid_aligned_text(&F, i * 10 + 5, -1 * 10, "", str);
3211 }
3212 for (j = 0; j < n; j++) {
3213 sprintf(str, "%d", labels[m + j] - m);
3214 grid_aligned_text(&F, -1 * 10, j * 10 + 5, "", str);
3215 }
3216 }
3217
3218
3219 sl_thickness(10); // 100 is standard
3220
3221 sf_interior(100);
3222
3223 cnt = 0;
3224 mtn = m * n;
3225 mtn1 = mtn / 20;
3226 if (mtn1 == 0) {
3227 mtn1 = 1;
3228 }
3229 for (i = 0; i < m; i++) {
3230#if 0
3231 if (i && (i % 1000) == 0) {
3232 cout << "draw_it2 " << i << " / " << m << endl;
3233 }
3234#endif
3235 for (j = 0; j < n; j++) {
3236
3237 ij = i * n + j;
3238 if ((ij % mtn1) == 0) {
3239 cout << "draw_bitmatrix2 " << ij << " / " << mtn << endl;
3240 }
3241
3242 //a = Aij(i, j);
3243
3244 if (f_bitmatrix) {
3245 a = Bitmatrix->s_ij(i, j);
3246 //a = bitvector_s_i(D, i * n + j);
3247 }
3248 else {
3249 a = M[i * n + j];
3250 }
3251 if (a == 0) {
3252 continue;
3253 }
3254 cnt++;
3255
3256 //if (cnt > 5000) continue;
3257 //grid_fill_polygon4(&F, i, j, i + 1, j, i + 1, j + 1, i, j + 1);
3258
3259
3260
3261 sprintf(str, "%d_%d", i, j);
3262 comment(str);
3263
3264 if (f_dots) {
3265 grid_polygon2(&F, 10 * i, 10 * j, 10 * i, 10 * j);
3266 }
3267 else {
3268 sf_interior(100);
3269 sf_color(1);
3270
3271#if 0
3273 10 * i + 1, 10 * j + 1,
3274 10 * (i + 1) - 1, 10 * j + 1,
3275 10 * (i + 1) - 1, 10 * (j + 1) - 1,
3276 10 * i + 1, 10 * (j + 1) - 1);
3277#else
3279 10 * i + indent, 10 * j + indent,
3280 10 * (i + 1) - indent, 10 * j + indent,
3281 10 * (i + 1) - indent, 10 * (j + 1) - indent,
3282 10 * i + indent, 10 * (j + 1) - indent,
3283 10 * i + indent, 10 * j + indent);
3284#endif
3285 //grid_polygon2(&F, i, j, i + 1, j);
3286 //grid_polygon2(&F, i + 1, j, i + 1, j + 1);
3287 //grid_polygon2(&F, i + 1, j + 1, i, j + 1);
3288 //grid_polygon2(&F, i, j + 1, i, j);
3289 }
3290 }
3291 }
3292 cout << "mp_graphics::draw_bitmatrix2 "
3293 "# of non-zero coefficients = " << cnt << endl;
3294}
3295
3296
3297
3299 int *outline_value, int *outline_number, int outline_sz,
3300 int min_value, int max_value, int offset_x, int f_switch_x,
3301 int f_title, const char *title,
3302 const char *label_x,
3303 int f_circle, int circle_at, int circle_rad,
3304 int f_mu, int f_sigma, int nb_standard_deviations,
3305 int f_v_grid, int v_grid, int f_h_grid, int h_grid)
3306{
3307 int i;
3308 int Px[1000], Py[1000];
3309 //int phi = 360 / 12;
3310 //int rad1 = 400;
3311 char str[1000];
3312 int y_in, x, y, k;
3313
3314 int min_x, max_x, min_y, max_y;
3315 int sum, a;
3316 int mini_x, i0;
3317 double average;
3318 double sigma; // standard deviation
3319 double sum1, f;
3320 plot_tools Pt;
3321
3322 if (outline_value[0] == 0) {
3323 i0 = 1;
3324 mini_x = outline_number[0];
3325 }
3326 else {
3327 i0 = 0;
3328 mini_x = 0; // outline_number[0];
3329 }
3330 min_x = 0;
3331 max_x = outline_number[outline_sz - 1]; // number of students
3332
3333 min_y = min_value;
3334 max_y = max_value;
3335
3336 sum = 0;
3337 for (i = outline_sz - 1; i >= i0; i--) {
3338 if (i) {
3339 a = outline_number[i] - outline_number[i - 1];
3340 }
3341 else {
3342 a = outline_number[i];
3343 }
3344 sum += outline_value[i] * a;
3345 }
3346
3347 //cout << "sum=" << sum << endl;
3348 average = sum / MAXIMUM((max_x - mini_x), 1);
3349
3350 // now for the standard deviation:
3351 sum1 = 0;
3352 for (i = outline_sz - 1; i >= 0; i--) {
3353 if (i) {
3354 a = outline_number[i] - outline_number[i - 1];
3355 }
3356 else {
3357 a = outline_number[i];
3358 }
3359 f = ((double) outline_value[i]) - average;
3360 f = f * f;
3361 sum1 += f;
3362 }
3363 sigma = sqrt(sum1 / max_x);
3364
3365
3366 Pt.get_coord(Px, Py, 0, min_x, min_y, min_x, min_y, max_x, max_y, FALSE);
3367 for (i = 0; i < outline_sz; i++) {
3368 Pt.get_coord(Px, Py, 2, outline_number[i], outline_value[i],
3369 min_x, min_y, max_x, max_y, FALSE);
3370 Px[1] = Px[0];
3371 Py[1] = Py[2];
3372 polygon3(Px, Py, 0, 1, 2);
3373 Px[0] = Px[2];
3374 Py[0] = Py[2];
3375 }
3376 Pt.get_coord(Px, Py, 2, max_x, max_value,
3377 min_x, min_y, max_x, max_y, FALSE);
3378 polygon2(Px, Py, 0, 2);
3379 Pt.get_coord(Px, Py, 0, min_x, min_y, min_x, min_y, max_x, max_y, FALSE);
3380 Pt.get_coord(Px, Py, 1, max_x, min_y, min_x, min_y, max_x, max_y, FALSE);
3381 Pt.get_coord(Px, Py, 2, max_x, max_y, min_x, min_y, max_x, max_y, FALSE);
3382 Pt.get_coord(Px, Py, 3, min_x, max_y, min_x, min_y, max_x, max_y, FALSE);
3383 polygon5(Px, Py, 0, 1, 2, 3, 0);
3384
3385
3386 if (f_switch_x) {
3387 sprintf(str, "{\\bf {\\large %d}}", max_x + offset_x);
3388 aligned_text(Px[0], Py[0], "t", str);
3389 sprintf(str, "{\\bf {\\large %d}}", min_x + offset_x);
3390 aligned_text(Px[1], Py[1], "t", str);
3391 }
3392 else {
3393 sprintf(str, "{\\bf {\\large %d}}", min_x + offset_x);
3394 aligned_text(Px[0], Py[0], "t", str);
3395 sprintf(str, "{\\bf {\\large %d}}", max_x + offset_x);
3396 aligned_text(Px[1], Py[1], "t", str);
3397 }
3398 sprintf(str, "{\\bf {\\large %d}}", min_y);
3399 aligned_text(Px[0], Py[0], "r", str);
3400 sprintf(str, "{\\bf {\\large %d}}", max_y);
3401 aligned_text(Px[3], Py[3], "r", str);
3402
3403
3404
3405 Px[0] = 5 * 100;
3406 Py[0] = 0;
3407 sprintf(str, "{\\bf {\\large %s}}", label_x);
3408 aligned_text(Px[0], Py[0], "t", str);
3409
3410 Px[0] = 5 * 100;
3411 Py[0] = -50;
3412 sprintf(str, "{\\bf {\\large $");
3413 if (f_mu) {
3414 sprintf(str + strlen(str), "\\overline{x}=%.1lf", average);
3415 }
3416 if (f_sigma) {
3417 if (f_mu) {
3418 sprintf(str + strlen(str), "\\, ");
3419 }
3420 sprintf(str + strlen(str), "\\sigma=%.1lf", sigma);
3421 }
3422 if (f_mu || f_sigma) {
3423 sprintf(str + strlen(str), "$}}");
3424 aligned_text(Px[0], Py[0], "t", str);
3425 }
3426
3427
3428 if (f_mu) {
3429 y_in = (int) average;
3430 Pt.y_to_pt_on_curve(y_in, x, y,
3431 outline_value, outline_number, outline_sz);
3432 Pt.get_coord(Px, Py, 0, x, min_y, min_x, min_y, max_x, max_y, FALSE);
3433 Pt.get_coord(Px, Py, 1, x, y, min_x, min_y, max_x, max_y, FALSE);
3434 Pt.get_coord(Px, Py, 2, min_x, y, min_x, min_y, max_x, max_y, FALSE);
3435 Py[0] -= 10;
3436 polygon3(Px, Py, 0, 1, 2);
3437 aligned_text(Px[2], Py[2], "r", "$\\overline{x}$");
3438 }
3439
3440
3441 if (f_circle) {
3442 Pt.y_to_pt_on_curve(circle_at, x, y,
3443 outline_value, outline_number, outline_sz);
3444 Pt.get_coord(Px, Py, 0, x, y, min_x, min_y, max_x, max_y, FALSE);
3445 circle(Px[0], Py[0], circle_rad);
3446 }
3447
3448
3449 for (k = 1; k < nb_standard_deviations; k++) {
3450 y_in = (int) (average + k * sigma);
3451 Pt.y_to_pt_on_curve(y_in, x, y,
3452 outline_value, outline_number, outline_sz);
3453 Pt.get_coord(Px, Py, 0, x, min_y, min_x, min_y, max_x, max_y, FALSE);
3454 Pt.get_coord(Px, Py, 1, x, y, min_x, min_y, max_x, max_y, FALSE);
3455 Pt.get_coord(Px, Py, 2, min_x, y, min_x, min_y, max_x, max_y, FALSE);
3456 Py[0] -= 10;
3457 polygon3(Px, Py, 0, 1, 2);
3458 if (k > 1) {
3459 sprintf(str, "$\\overline{x}+%d \\sigma$", k);
3460 }
3461 else {
3462 sprintf(str, "$\\overline{x}+\\sigma$");
3463 }
3464 aligned_text(Px[2], Py[2], "r", str);
3465
3466 y_in = (int) (average - k * sigma);
3467 Pt.y_to_pt_on_curve(y_in, x, y,
3468 outline_value, outline_number, outline_sz);
3469 Pt.get_coord(Px, Py, 0, x, min_y, min_x, min_y, max_x, max_y, FALSE);
3470 Pt.get_coord(Px, Py, 1, x, y, min_x, min_y, max_x, max_y, FALSE);
3471 Pt.get_coord(Px, Py, 2, min_x, y, min_x, min_y, max_x, max_y, FALSE);
3472 Py[0] -= 10;
3473 polygon3(Px, Py, 0, 1, 2);
3474 if (k > 1) {
3475 sprintf(str, "{\\bf {\\large $\\overline{x}-%d \\sigma$}}", k);
3476 }
3477 else {
3478 sprintf(str, "{\\bf {\\large $\\overline{x}-\\sigma$}}");
3479 }
3480 aligned_text(Px[2], Py[2], "r", str);
3481 }
3482
3483#if 0
3484 y_in = (int) (average + 2 * sigma);
3485 y_to_pt_on_curve(y_in, x, y,
3486 outline_value, outline_number, outline_sz);
3487 get_coord(Px, Py, 0, x, min_y, min_x, min_y, max_x, max_y);
3488 get_coord(Px, Py, 1, x, y, min_x, min_y, max_x, max_y);
3489 get_coord(Px, Py, 2, min_x, y, min_x, min_y, max_x, max_y);
3490 Py[0] -= 10;
3491 G.polygon3(Px, Py, 0, 1, 2);
3492 G.aligned_text(Px[2], Py[2], "r", "$\\overline{x}+2\\sigma$");
3493
3494 y_in = (int) (average - 2 * sigma);
3495 y_to_pt_on_curve(y_in, x, y,
3496 outline_value, outline_number, outline_sz);
3497 get_coord(Px, Py, 0, x, min_y, min_x, min_y, max_x, max_y);
3498 get_coord(Px, Py, 1, x, y, min_x, min_y, max_x, max_y);
3499 get_coord(Px, Py, 2, min_x, y, min_x, min_y, max_x, max_y);
3500 Py[0] -= 10;
3501 G.polygon3(Px, Py, 0, 1, 2);
3502 G.aligned_text(Px[2], Py[2], "r", "$\\overline{x}-2\\sigma$");
3503#endif
3504
3505
3506
3507
3508 int line_dashing = 50;
3509 sl_udsty(line_dashing);
3510
3511 if (f_v_grid) {
3512 int delta;
3513
3514 delta = 1000 / v_grid;
3515 for (i = 1; i <= v_grid - 1; i++) {
3516 Px[0] = i * delta;
3517 Py[0] = 0;
3518 Px[1] = i * delta;
3519 Py[1] = 1000;
3520 polygon2(Px, Py, 0, 1);
3521 }
3522 }
3523 if (f_h_grid) {
3524 int delta;
3525
3526 delta = 1000 / h_grid;
3527 for (i = 1; i <= h_grid - 1; i++) {
3528 Px[0] = 0;
3529 Py[0] = i * delta;
3530 Px[1] = 1000;
3531 Py[1] = i * delta;
3532 polygon2(Px, Py, 0, 1);
3533 }
3534 }
3535
3536
3537 if (f_title) {
3538 Px[0] = 5 * 100;
3539 Py[0] = 1050;
3540 sprintf(str, "{\\bf {\\large %s}}", title);
3541 aligned_text(Px[0], Py[0], "b", str);
3542 }
3543
3544}
3545
3547 int **outline_value, int **outline_number, int *outline_sz, int nb_curves,
3548 int min_x, int max_x, int min_y, int max_y,
3549 int offset_x, int f_switch_x,
3550 int f_title, const char *title,
3551 const char *label_x,
3552 int f_v_grid, int v_grid, int f_h_grid, int h_grid,
3553 int f_v_logarithmic, double log_base)
3554{
3555 int i;
3556 int Px[1000], Py[1000];
3557 //int phi = 360 / 12;
3558 //int rad1 = 400;
3559 char str[1000];
3560 int curve;
3561 plot_tools Pt;
3562
3563#if 0
3564 int min_x, max_x, min_y, max_y;
3565
3566 min_x = INT_MAX;
3567 max_x = int_MIN;
3568 for (curve = 0; curve < nb_curves; curve++) {
3569 min_x = MINIMUM(min_x, outline_number[curve][0]);
3570 min_x = MINIMUM(min_x, outline_number[curve][outline_sz[curve] - 1]);
3571 max_x = MAXIMUM(max_x, outline_number[curve][0]);
3572 max_x = MAXIMUM(max_x, outline_number[curve][outline_sz[curve] - 1]);
3573 }
3574
3575 cout << "min_x=" << min_x << endl;
3576 cout << "max_x=" << max_x << endl;
3577
3578 min_y = min_value;
3579 max_y = max_value;
3580#endif
3581
3582
3583 for (curve = 0; curve < nb_curves; curve++) {
3584 if (f_v_logarithmic) {
3585 Pt.get_coord_log(Px, Py, 0,
3586 min_x, min_y, min_x, min_y, max_x, max_y,
3587 log_base, f_switch_x);
3588 }
3589 else {
3590 Pt.get_coord(Px, Py, 0,
3591 min_x, min_y, min_x, min_y, max_x, max_y, f_switch_x);
3592 }
3593 for (i = 0; i < outline_sz[curve]; i++) {
3594 if (f_v_logarithmic) {
3595 Pt.get_coord_log(Px, Py, 2,
3596 outline_number[curve][i], outline_value[curve][i],
3597 min_x, min_y, max_x, max_y, log_base, f_switch_x);
3598 }
3599 else {
3600 Pt.get_coord(Px, Py, 2,
3601 outline_number[curve][i], outline_value[curve][i],
3602 min_x, min_y, max_x, max_y, f_switch_x);
3603 }
3604 Px[1] = Px[0];
3605 Py[1] = Py[2];
3606 polygon3(Px, Py, 0, 1, 2);
3607 Px[0] = Px[2];
3608 Py[0] = Py[2];
3609 }
3610 if (f_v_logarithmic) {
3611 Pt.get_coord_log(Px, Py, 2, max_x, max_y,
3612 min_x, min_y, max_x, max_y, log_base, f_switch_x);
3613 }
3614 else {
3615 Pt.get_coord(Px, Py, 2, max_x, max_y,
3616 min_x, min_y, max_x, max_y, f_switch_x);
3617 }
3618 polygon2(Px, Py, 0, 2);
3619 }
3620
3621
3622 if (f_v_logarithmic) {
3623 Pt.get_coord_log(Px, Py, 0,
3624 min_x, min_y, min_x, min_y, max_x, max_y, log_base, FALSE);
3625 Pt.get_coord_log(Px, Py, 1,
3626 max_x, min_y, min_x, min_y, max_x, max_y, log_base, FALSE);
3627 Pt.get_coord_log(Px, Py, 2,
3628 max_x, max_y, min_x, min_y, max_x, max_y, log_base, FALSE);
3629 Pt.get_coord_log(Px, Py, 3,
3630 min_x, max_y, min_x, min_y, max_x, max_y, log_base, FALSE);
3631 }
3632 else {
3633 Pt.get_coord(Px, Py, 0, min_x, min_y, min_x, min_y, max_x, max_y, FALSE);
3634 Pt.get_coord(Px, Py, 1, max_x, min_y, min_x, min_y, max_x, max_y, FALSE);
3635 Pt.get_coord(Px, Py, 2, max_x, max_y, min_x, min_y, max_x, max_y, FALSE);
3636 Pt.get_coord(Px, Py, 3, min_x, max_y, min_x, min_y, max_x, max_y, FALSE);
3637 }
3638 polygon5(Px, Py, 0, 1, 2, 3, 0);
3639
3640
3641
3642 if (f_switch_x) {
3643 sprintf(str, "{\\bf {\\large %d}}", max_x + offset_x);
3644 aligned_text(Px[1], Py[1], "t", str);
3645 sprintf(str, "{\\bf {\\large %d}}", min_x + offset_x);
3646 aligned_text(Px[0], Py[0], "t", str);
3647 }
3648 else {
3649 sprintf(str, "{\\bf {\\large %d}}", min_x + offset_x);
3650 aligned_text(Px[0], Py[0], "t", str);
3651 sprintf(str, "{\\bf {\\large %d}}", max_x + offset_x);
3652 aligned_text(Px[1], Py[1], "t", str);
3653 }
3654
3655 sprintf(str, "{\\bf {\\large %d}}", min_y);
3656 aligned_text(Px[0], Py[0], "r", str);
3657 sprintf(str, "{\\bf {\\large %d}}", max_y);
3658 aligned_text(Px[3], Py[3], "r", str);
3659
3660
3661
3662 Px[0] = 5 * 100;
3663 Py[0] = 0;
3664 sprintf(str, "{\\bf {\\large %s}}", label_x);
3665 aligned_text(Px[0], Py[0], "t", str);
3666
3667
3668
3669
3670
3671 int line_dashing = 50;
3672 int line_thickness = 15;
3673 sl_udsty(line_dashing);
3674 sl_thickness(line_thickness);
3675
3676 if (f_v_grid) {
3677 if (FALSE) {
3678 double delta, a;
3679
3680 delta = log10(max_x - min_x) / v_grid;
3681 for (i = 1; i <= v_grid - 1; i++) {
3682 a = min_x + pow(10, i * delta);
3683 Px[0] = (int)a;
3684 Py[0] = 0;
3685 Px[1] = (int)a;
3686 Py[1] = 1000;
3687 polygon2(Px, Py, 0, 1);
3688 }
3689 }
3690 else {
3691 int delta;
3692 delta = 1000 / v_grid;
3693 for (i = 1; i <= v_grid - 1; i++) {
3694 Px[0] = i * delta;
3695 Py[0] = 0;
3696 Px[1] = i * delta;
3697 Py[1] = 1000;
3698 polygon2(Px, Py, 0, 1);
3699 }
3700 }
3701 }
3702 if (f_h_grid) {
3703 if (f_v_logarithmic) {
3704 double delta, a;
3705
3706 delta = (log(max_y - min_y + 1) / log(log_base))/ h_grid;
3707 for (i = 1; i <= h_grid - 1; i++) {
3708 a = min_y + pow(log_base, i * delta);
3709 Pt.get_coord_log(Px, Py, 2, min_x, (int)a,
3710 min_x, min_y, max_x, max_y, log_base,
3711 FALSE /* f_switch_x */);
3712 Px[0] = Px[2];
3713 Py[0] = Py[2];
3714 Px[1] = 1000;
3715 Py[1] = Py[2];
3716 polygon2(Px, Py, 0, 1);
3717 sprintf(str, "{%d}", (int)a);
3718 aligned_text(Px[0], Py[0], "r", str);
3719 }
3720 }
3721 else {
3722 int delta;
3723
3724 delta = 1000 / h_grid;
3725 for (i = 1; i <= h_grid - 1; i++) {
3726 Px[0] = 0;
3727 Py[0] = i * delta;
3728 Px[1] = 1000;
3729 Py[1] = i * delta;
3730 polygon2(Px, Py, 0, 1);
3731 }
3732 }
3733 }
3734
3735
3736 if (f_title) {
3737 Px[0] = 5 * 100;
3738 Py[0] = 1050;
3739 sprintf(str, "{\\bf {\\large %s}}", title);
3740 aligned_text(Px[0], Py[0], "b", str);
3741 }
3742
3743}
3744
3747 int q,
3748 int *Table, int nb,
3749 int f_point_labels, char **Point_labels, int verbose_level)
3750{
3751 int f_v = (verbose_level >= 1);
3752 double a, b;
3753 int x1, x2, x3;
3754
3755 //int rad = 17000;
3756 int i, h;
3757 //double x_stretch = 1.0 / (double) (q + 1);
3758 //double y_stretch = 1.0 / (double) (q + 1);
3759 //double x_stretch = 0.01;
3760 //double y_stretch = 0.01;
3761
3762 double *Dx, *Dy;
3763 int *Px, *Py;
3764 double dx = O->xin * 0.5 / (double) (q + 1);
3765 double dy = O->yin * 0.5 / (double) (q + 1); // stretch factor
3766 int N = 1000;
3767
3768
3769 if (f_v) {
3770 cout << "projective_plane_draw_grid2" << endl;
3771 cout << "projective_plane_draw_grid2 q=" << q << endl;
3772 //cout << "projective_plane_draw_grid2 x_stretch=" << x_stretch << " y_stretch" << y_stretch << endl;
3773 cout << "projective_plane_draw_grid2 dx=" << dx << " dy=" << dy << endl;
3774 }
3775
3776
3777 Px = NEW_int(N);
3778 Py = NEW_int(N);
3779 Dx = new double[N];
3780 Dy = new double[N];
3781
3782
3783
3784
3785
3786
3787 if (f_v) {
3788 cout << "projective_plane_draw_grid2 "
3789 "before G.draw_axes_and_grid" << endl;
3790 }
3791
3792
3794 0., (double)(q - 1), 0., (double)(q - 1), dx, dy,
3795 TRUE /* f_x_axis_at_y_min */, TRUE /* f_y_axis_at_x_min */,
3796 1 /* x_mod */, 1 /* y_mod */, 1, 1,
3797 -1. /* x_labels_offset */, -1. /* y_labels_offset */,
3798 0.5 /* x_tick_half_width */, 0.5 /* y_tick_half_width */,
3799 TRUE /* f_v_lines */, 1 /* subdivide_v */,
3800 TRUE /* f_h_lines */, 1 /* subdivide_h */,
3801 verbose_level - 1);
3802
3803
3804
3805 if (f_v) {
3806 cout << "projective_plane_draw_grid2 "
3807 "after G.draw_axes_and_grid" << endl;
3808 }
3809
3810 Dx[0] = q;
3811 Dy[0] = -1;
3812 Dx[1] = -1;
3813 Dy[1] = q;
3814 for (i = 0; i < 2; i++) {
3815 Px[i] = Dx[i] * dx;
3816 Py[i] = Dy[i] * dy;
3817 }
3818 text(Px[0], Py[0], "$x$");
3819 text(Px[1], Py[1], "$y$");
3820
3821 sl_thickness(100);
3822
3823 projective_plane_make_affine_point(q, 0, 1, 0, a, b);
3824 Dx[0] = a;
3825 Dy[0] = b;
3826 projective_plane_make_affine_point(q, 1, 0, 0, a, b);
3827 Dx[1] = a;
3828 Dy[1] = b;
3829 if (EVEN(q)) {
3830 projective_plane_make_affine_point(q, q / 2, 1, 0, a, b);
3831 Dx[2] = a;
3832 Dy[2] = b;
3833 Dx[3] = a;
3834 Dy[3] = b;
3835 }
3836 else {
3837 projective_plane_make_affine_point(q, q / 2, 1, 0, a, b);
3838 Dx[2] = a;
3839 Dy[2] = b;
3840 projective_plane_make_affine_point(q, (q + 1) / 2, 1, 0, a, b);
3841 Dx[3] = a;
3842 Dy[3] = b;
3843 }
3844
3845 for (i = 0; i < 4; i++) {
3846 Px[i] = Dx[i] * dx;
3847 Py[i] = Dy[i] * dy;
3848 }
3849 polygon4(Px, Py, 0, 2, 3, 1);
3850
3851 if (!O->f_nodes_empty) {
3852
3853 if (f_v) {
3854 cout << "projective_plane_draw_grid2 "
3855 "drawing points, nb=" << nb << endl;
3856 }
3857
3858 sl_thickness(50);
3859
3860#if 0
3861 if (nb >= 40) {
3862 rad = 2000;
3863 }
3864#endif
3865 for (h = 0; h < nb; h++) {
3866 x1 = Table[3 * h + 0];
3867 x2 = Table[3 * h + 1];
3868 x3 = Table[3 * h + 2];
3869 //get_ab(q, x1, x2, x3, a, b);
3870 projective_plane_make_affine_point(q, x1, x2, x3, a, b);
3871
3872 if (f_v) {
3873 cout << "projective_plane_draw_grid2 "
3874 "point " << h << " : " << x1 << ", " << x2
3875 << ", " << x3 << " : " << a << ", " << b << endl;
3876 }
3877
3878 Dx[0] = a;
3879 Dy[0] = b;
3880
3881 for (i = 0; i < 1; i++) {
3882 Px[i] = Dx[i] * dx;
3883 Py[i] = Dy[i] * dy;
3884 }
3885
3886 //G.nice_circle(Px[a * Q + b], Py[a * Q + b], rad);
3887 nice_circle(Px[0], Py[0], O->rad);
3888 if (f_point_labels) {
3889 text(Px[0], Py[0], Point_labels[h]);
3890 }
3891 }
3892
3893
3894 }
3895 else {
3896 cout << "projective_plane_draw_grid2 not drawing any points" << endl;
3897 }
3898
3899
3900
3901
3902
3903 FREE_int(Px);
3904 FREE_int(Py);
3905 delete [] Dx;
3906 delete [] Dy;
3907
3908
3909
3910 if (f_v) {
3911 cout << "projective_plane_draw_grid2 done" << endl;
3912 }
3913}
3914
3915
3917 int f_row_grid, int f_col_grid,
3918 int *Table, int nb_colors,
3919 int m, int n,
3920 int *color_scale, int nb_colors_in_scale,
3921 int f_has_labels, int *labels)
3922{
3923 char str[1000];
3924 grid_frame F;
3925 int i, j, a, cnt, mn;
3926 int indent = 0;
3927
3928 mn = MAXIMUM(m, n);
3930 F.m = m;
3931 F.n = n;
3932 F.origin_x = 0.;
3933 F.origin_y = 0.;
3934 F.dx = ONE_MILLION / (10 * mn);
3935 F.dy = ONE_MILLION / (10 * mn);
3936
3937 cout << "mp_graphics::draw_matrix_in_color" << endl;
3938 cout << "dx=" << F.dx << endl;
3939 cout << "dy=" << F.dy << endl;
3940
3941 // draw a box around it:
3942
3943 sprintf(str, "box outline");
3944 comment(str);
3945
3946 grid_polygon2(&F, 0, 0, 10 * m, 0);
3947 grid_polygon2(&F, 10 * m, 0, 10 * m, 10 * n);
3948 grid_polygon2(&F, 10 * m, 10 * n, 0, 10 * n);
3949 grid_polygon2(&F, 0, 10 * n, 0, 0);
3950
3951 sf_interior(100);
3952 sf_color(1); // black
3953
3954
3955 //sl_thickness(20); // 100 is standard
3956
3957
3958
3959 sl_thickness(10); // 100 is standard
3960
3961 sf_interior(0);
3962 sf_color(1);
3963
3964 if (f_row_grid) {
3965 for (i = 0; i < m; i++) {
3966 sprintf(str, "row_%d", i);
3967 if (f_has_labels) {
3968 sprintf(str + strlen(str), " label %d", labels[i]);
3969 }
3970 comment(str);
3971 j = 0;
3973 10 * i + indent, 10 * j + indent,
3974 10 * (i + 1) - indent, 10 * j + indent,
3975 10 * (i + 1) - indent, 10 * n - indent,
3976 10 * i + indent, 10 * n - indent,
3977 10 * i + indent, 10 * j + indent);
3978 }
3979 }
3980
3981 if (f_col_grid) {
3982 for (j = 0; j < n; j++) {
3983 sprintf(str, "col_%d", j);
3984 if (f_has_labels) {
3985 sprintf(str + strlen(str), " label %d", labels[j]);
3986 }
3987 comment(str);
3988 i = 0;
3990 10 * i + indent, 10 * j + indent,
3991 10 * m - indent, 10 * j + indent,
3992 10 * m - indent, 10 * (j + 1) - indent,
3993 10 * i + indent, 10 * (j + 1) - indent,
3994 10 * i + indent, 10 * j + indent);
3995 }
3996 }
3997
3998 if (f_has_labels) {
3999 for (i = 0; i < m; i++) {
4000 sprintf(str, "%d", labels[i]);
4001 grid_aligned_text(&F, i * 10 + 5, -1 * 10, "", str);
4002 }
4003 for (j = 0; j < n; j++) {
4004 sprintf(str, "%d", labels[m + j] - m);
4005 grid_aligned_text(&F, -1 * 10, j * 10 + 5, "", str);
4006 }
4007 }
4008
4009
4010 sl_thickness(10); // 100 is standard
4011
4012 sf_interior(100);
4013
4014 cnt = 0;
4015
4016
4017 double color_step = (double) nb_colors / (double) (nb_colors_in_scale);
4018 //double shade_step = (double) color_step * 100 / ((double) nb_colors / (double)nb_colors_in_scale);
4019 double f_sufficiently_many_colors;
4020 int c, a1, c1;
4021
4022 cout << "color_step=" << color_step << endl;
4023 //cout << "shade_step=" << shade_step << endl;
4024
4025 if (nb_colors_in_scale > nb_colors) {
4026 f_sufficiently_many_colors = TRUE;
4027 }
4028 else {
4029 f_sufficiently_many_colors = FALSE;
4030 }
4031
4032 for (i = 0; i < m; i++) {
4033 for (j = 0; j < n; j++) {
4034
4035
4036 a = Table[i * n + j];
4037
4038 cnt++;
4039
4040 //if (cnt > 5000) continue;
4041 //grid_fill_polygon4(&F, i, j, i + 1, j, i + 1, j + 1, i, j + 1);
4042
4043
4044
4045
4046 if (a) {
4047
4048 sprintf(str, "%d_%d", i, j);
4049 comment(str);
4050
4051 c = (int)((double) a / (double) color_step) + 1;
4052 if (f_sufficiently_many_colors) {
4053 sf_interior(100);
4054 sf_color(a);
4055 }
4056 else {
4057 a1 = a - c * color_step;
4058 c1 = a1 / color_step * 40 + 60;
4059 sf_color(c);
4060 sf_interior(c1);
4061 }
4062
4064 10 * i + indent, 10 * j + indent,
4065 10 * (i + 1) - indent, 10 * j + indent,
4066 10 * (i + 1) - indent, 10 * (j + 1) - indent,
4067 10 * i + indent, 10 * (j + 1) - indent,
4068 10 * i + indent, 10 * j + indent);
4069 }
4070
4071 //grid_polygon2(&F, i, j, i + 1, j);
4072 //grid_polygon2(&F, i + 1, j, i + 1, j + 1);
4073 //grid_polygon2(&F, i + 1, j + 1, i, j + 1);
4074 //grid_polygon2(&F, i, j + 1, i, j);
4075 } // next j
4076 } // next i
4077 cout << "mp_graphics::draw_matrix_in_color done" << endl;
4078}
4079
4080
4081
4082
4083static void projective_plane_make_affine_point(
4084 int q, int x1, int x2, int x3, double &a, double &b)
4085{
4086 if (x3 == 0) {
4087 if (x2 == 0) {
4088 a = 3 * q / 2;
4089 b = q / 2;
4090 }
4091 else {
4092 a = q / 2 + x1;
4093 b = 3 * q / 2 - x1;
4094 }
4095 // make it lie on the rim:
4096 // if x1 < q/2, we decrease the y coordinate.
4097 // if x1 > q/2, we decrease the x coordinate.
4098 if (x2 == 0) {
4099 a = q;
4100 }
4101 else {
4102 if (x1 < (q / 2)) {
4103 b = q;
4104 }
4105 if (x1 > q / 2) {
4106 a = q;
4107 }
4108 }
4109 }
4110 else {
4111 a = x1;
4112 b = x2;
4113 }
4114}
4115
4117 int i, int j, int dx, int dy, int rad, int f_horizontal)
4118{
4119 int Px[100], Py[100];
4120
4121 Px[0] = j * dx + (dx >> 1);
4122 Py[0] = (M - i) * dy - (dy >> 1);
4123
4124 circle(Px[0], Py[0], rad);
4125}
4126
4127
4129 int i, int j, int dx, int dy, int rad, int f_horizontal)
4130{
4131 int Px[100], Py[100];
4132 int ddx = compute_dd(dx);
4133 int ddy = compute_dd(dy);
4134
4135 Px[0] = j * dx + (dx >> 1);
4136 Py[0] = (M - i) * dy - (dy >> 1);
4137 if (f_horizontal) {
4138 Px[1] = Px[0] - ddx;
4139 Py[1] = Py[0] + ddy;
4140 Px[2] = Px[0] + ddx;
4141 Py[2] = Py[0] - ddy;
4142 }
4143 else {
4144 Px[1] = Px[0] + ddx;
4145 Py[1] = Py[0] + ddy;
4146 Px[2] = Px[0] - ddx;
4147 Py[2] = Py[0] - ddy;
4148 }
4149
4150 circle(Px[1], Py[1], rad);
4151 circle(Px[2], Py[2], rad);
4152}
4153
4155 int i, int j, int dx, int dy, int rad, int f_horizontal)
4156{
4157 int Px[100], Py[100];
4158 int ddx = compute_dd(dx);
4159 int ddy = compute_dd(dy);
4160
4161 Px[0] = j * dx + (dx >> 1);
4162 Py[0] = (M - i) * dy - (dy >> 1);
4163 if (f_horizontal) {
4164 Px[1] = Px[0] - ddx;
4165 Py[1] = Py[0] + ddy;
4166 Px[2] = Px[0] + ddx;
4167 Py[2] = Py[0] - ddy;
4168 }
4169 else {
4170 Px[1] = Px[0] + ddx;
4171 Py[1] = Py[0] + ddy;
4172 Px[2] = Px[0] - ddx;
4173 Py[2] = Py[0] - ddy;
4174 }
4175
4176 circle(Px[0], Py[0], rad);
4177 circle(Px[1], Py[1], rad);
4178 circle(Px[2], Py[2], rad);
4179}
4180
4182 int i, int j, int dx, int dy, int rad, int f_horizontal)
4183{
4184 int Px[100], Py[100];
4185 int ddx = compute_dd(dx);
4186 int ddy = compute_dd(dy);
4187
4188 Px[0] = j * dx + (dx >> 1);
4189 Py[0] = (M - i) * dy - (dy >> 1);
4190
4191 Px[1] = Px[0] - ddx;
4192 Py[1] = Py[0] + ddy;
4193 Px[2] = Px[0] + ddx;
4194 Py[2] = Py[0] + ddy;
4195 Px[3] = Px[0] + ddx;
4196 Py[3] = Py[0] - ddy;
4197 Px[4] = Px[0] - ddx;
4198 Py[4] = Py[0] - ddy;
4199
4200 circle(Px[1], Py[1], rad);
4201 circle(Px[2], Py[2], rad);
4202 circle(Px[3], Py[3], rad);
4203 circle(Px[4], Py[4], rad);
4204}
4205
4207 int i, int j, int dx, int dy, int rad, int f_horizontal)
4208{
4209 int Px[100], Py[100];
4210 int ddx = compute_dd(dx);
4211 int ddy = compute_dd(dy);
4212
4213 Px[0] = j * dx + (dx >> 1);
4214 Py[0] = (M - i) * dy - (dy >> 1);
4215
4216 Px[1] = Px[0] - ddx;
4217 Py[1] = Py[0] + ddy;
4218 Px[2] = Px[0] + ddx;
4219 Py[2] = Py[0] + ddy;
4220 Px[3] = Px[0] + ddx;
4221 Py[3] = Py[0] - ddy;
4222 Px[4] = Px[0] - ddx;
4223 Py[4] = Py[0] - ddy;
4224
4225 circle(Px[0], Py[0], rad);
4226 circle(Px[1], Py[1], rad);
4227 circle(Px[2], Py[2], rad);
4228 circle(Px[3], Py[3], rad);
4229 circle(Px[4], Py[4], rad);
4230}
4231
4233 int i, int j, int dx, int dy, int rad, int f_horizontal)
4234{
4235 int Px[100], Py[100];
4236 int ddx = compute_dd(dx);
4237 int ddy = compute_dd(dy);
4238
4239 Px[0] = j * dx + (dx >> 1);
4240 Py[0] = (M - i) * dy - (dy >> 1);
4241
4242 Px[1] = Px[0] - ddx;
4243 Py[1] = Py[0] + ddy;
4244 Px[2] = Px[0] + ddx;
4245 Py[2] = Py[0] + ddy;
4246 Px[3] = Px[0] + ddx;
4247 Py[3] = Py[0] - ddy;
4248 Px[4] = Px[0] - ddx;
4249 Py[4] = Py[0] - ddy;
4250
4251 if (f_horizontal) {
4252 Px[5] = Px[0];
4253 Py[5] = Py[0] + ddy;
4254 Px[6] = Px[0];
4255 Py[6] = Py[0] - ddy;
4256 }
4257 else {
4258 Px[5] = Px[0] - ddx;
4259 Py[5] = Py[0];
4260 Px[6] = Px[0] + ddx;
4261 Py[6] = Py[0];
4262 }
4263
4264 circle(Px[1], Py[1], rad);
4265 circle(Px[2], Py[2], rad);
4266 circle(Px[3], Py[3], rad);
4267 circle(Px[4], Py[4], rad);
4268 circle(Px[5], Py[5], rad);
4269 circle(Px[6], Py[6], rad);
4270}
4271
4273 int i, int j, int dx, int dy, int rad, int f_horizontal)
4274{
4275 int Px[100], Py[100];
4276 int ddx = compute_dd(dx);
4277 int ddy = compute_dd(dy);
4278
4279 Px[0] = j * dx + (dx >> 1);
4280 Py[0] = (M - i) * dy - (dy >> 1);
4281
4282 Px[1] = Px[0] - ddx;
4283 Py[1] = Py[0] + ddy;
4284 Px[2] = Px[0] + ddx;
4285 Py[2] = Py[0] + ddy;
4286 Px[3] = Px[0] + ddx;
4287 Py[3] = Py[0] - ddy;
4288 Px[4] = Px[0] - ddx;
4289 Py[4] = Py[0] - ddy;
4290
4291 if (f_horizontal) {
4292 Px[5] = Px[0];
4293 Py[5] = Py[0] + ddy;
4294 Px[6] = Px[0];
4295 Py[6] = Py[0] - ddy;
4296 Px[7] = Px[0];
4297 Py[7] = Py[0];
4298 }
4299 else {
4300 Px[5] = Px[0] - ddx;
4301 Py[5] = Py[0];
4302 Px[6] = Px[0] + ddx;
4303 Py[6] = Py[0];
4304 Px[7] = Px[0];
4305 Py[7] = Py[0];
4306 }
4307
4308 circle(Px[1], Py[1], rad);
4309 circle(Px[2], Py[2], rad);
4310 circle(Px[3], Py[3], rad);
4311 circle(Px[4], Py[4], rad);
4312 circle(Px[5], Py[5], rad);
4313 circle(Px[6], Py[6], rad);
4314 circle(Px[7], Py[7], rad);
4315}
4316
4318 int i, int j, int dx, int dy, int rad, int f_horizontal)
4319{
4320 int Px[100], Py[100];
4321 int ddx = compute_dd(dx);
4322 int ddy = compute_dd(dy);
4323
4324 Px[0] = j * dx + (dx >> 1);
4325 Py[0] = (M - i) * dy - (dy >> 1);
4326
4327 Px[1] = Px[0] - ddx;
4328 Py[1] = Py[0] + ddy;
4329 Px[2] = Px[0] + ddx;
4330 Py[2] = Py[0] + ddy;
4331 Px[3] = Px[0] + ddx;
4332 Py[3] = Py[0] - ddy;
4333 Px[4] = Px[0] - ddx;
4334 Py[4] = Py[0] - ddy;
4335
4336 if (f_horizontal) {
4337 Px[5] = Px[0];
4338 Py[5] = Py[0] + ddy;
4339 Px[6] = Px[0];
4340 Py[6] = Py[0] - ddy;
4341 Px[7] = Px[0];
4342 Py[7] = Py[0];
4343 Px[8] = Px[0] - ddx;
4344 Py[8] = Py[0];
4345 Px[9] = Px[0] + ddx;
4346 Py[9] = Py[0];
4347 }
4348 else {
4349 Px[5] = Px[0] - ddx;
4350 Py[5] = Py[0];
4351 Px[6] = Px[0] + ddx;
4352 Py[6] = Py[0];
4353 Px[7] = Px[0];
4354 Py[7] = Py[0];
4355 Px[8] = Px[0];
4356 Py[8] = Py[0] + ddy;
4357 Px[9] = Px[0];
4358 Py[9] = Py[0] - ddy;
4359 }
4360
4361 circle(Px[1], Py[1], rad);
4362 circle(Px[2], Py[2], rad);
4363 circle(Px[3], Py[3], rad);
4364 circle(Px[4], Py[4], rad);
4365 circle(Px[5], Py[5], rad);
4366 circle(Px[6], Py[6], rad);
4367 //circle(Px[7], Py[7], rad);
4368 circle(Px[8], Py[8], rad);
4369 circle(Px[9], Py[9], rad);
4370}
4371
4373 int i, int j, int dx, int dy, int rad, int f_horizontal)
4374{
4375 int Px[100], Py[100];
4376 int ddx = compute_dd(dx);
4377 int ddy = compute_dd(dy);
4378
4379 Px[0] = j * dx + (dx >> 1);
4380 Py[0] = (M - i) * dy - (dy >> 1);
4381
4382 Px[1] = Px[0] - ddx;
4383 Py[1] = Py[0] + ddy;
4384 Px[2] = Px[0] + ddx;
4385 Py[2] = Py[0] + ddy;
4386 Px[3] = Px[0] + ddx;
4387 Py[3] = Py[0] - ddy;
4388 Px[4] = Px[0] - ddx;
4389 Py[4] = Py[0] - ddy;
4390
4391 if (f_horizontal) {
4392 Px[5] = Px[0];
4393 Py[5] = Py[0] + ddy;
4394 Px[6] = Px[0];
4395 Py[6] = Py[0] - ddy;
4396 Px[7] = Px[0];
4397 Py[7] = Py[0];
4398 Px[8] = Px[0] - ddx;
4399 Py[8] = Py[0];
4400 Px[9] = Px[0] + ddx;
4401 Py[9] = Py[0];
4402 }
4403 else {
4404 Px[5] = Px[0] - ddx;
4405 Py[5] = Py[0];
4406 Px[6] = Px[0] + ddx;
4407 Py[6] = Py[0];
4408 Px[7] = Px[0];
4409 Py[7] = Py[0];
4410 Px[8] = Px[0];
4411 Py[8] = Py[0] + ddy;
4412 Px[9] = Px[0];
4413 Py[9] = Py[0] - ddy;
4414 }
4415
4416 circle(Px[1], Py[1], rad);
4417 circle(Px[2], Py[2], rad);
4418 circle(Px[3], Py[3], rad);
4419 circle(Px[4], Py[4], rad);
4420 circle(Px[5], Py[5], rad);
4421 circle(Px[6], Py[6], rad);
4422 circle(Px[7], Py[7], rad);
4423 circle(Px[8], Py[8], rad);
4424 circle(Px[9], Py[9], rad);
4425}
4426
4427
4428#define DD_MULTIPLIER 8.5
4429
4430
4431static int compute_dd(int dx)
4432{
4433 return (int)(((double) dx) / 32 * DD_MULTIPLIER);
4434}
4435
4437 int i, int j, int dx, int dy, int rad)
4438{
4439 if (Ap == 1)
4440 domino_draw1(M, i, j, dx, dy, rad, TRUE /* f_horizontal */);
4441 if (Aq == 1)
4442 domino_draw1(M, i, j + 1, dx, dy, rad, TRUE /* f_horizontal */);
4443 if (Ap == 2)
4444 domino_draw2(M, i, j, dx, dy, rad, TRUE /* f_horizontal */);
4445 if (Aq == 2)
4446 domino_draw2(M, i, j + 1, dx, dy, rad, TRUE /* f_horizontal */);
4447 if (Ap == 3)
4448 domino_draw3(M, i, j, dx, dy, rad, TRUE /* f_horizontal */);
4449 if (Aq == 3)
4450 domino_draw3(M, i, j + 1, dx, dy, rad, TRUE /* f_horizontal */);
4451 if (Ap == 4)
4452 domino_draw4(M, i, j, dx, dy, rad, TRUE /* f_horizontal */);
4453 if (Aq == 4)
4454 domino_draw4(M, i, j + 1, dx, dy, rad, TRUE /* f_horizontal */);
4455 if (Ap == 5)
4456 domino_draw5(M, i, j, dx, dy, rad, TRUE /* f_horizontal */);
4457 if (Aq == 5)
4458 domino_draw5(M, i, j + 1, dx, dy, rad, TRUE /* f_horizontal */);
4459 if (Ap == 6)
4460 domino_draw6(M, i, j, dx, dy, rad, TRUE /* f_horizontal */);
4461 if (Aq == 6)
4462 domino_draw6(M, i, j + 1, dx, dy, rad, TRUE /* f_horizontal */);
4463 if (Ap == 7)
4464 domino_draw7(M, i, j, dx, dy, rad, TRUE /* f_horizontal */);
4465 if (Aq == 7)
4466 domino_draw7(M, i, j + 1, dx, dy, rad, TRUE /* f_horizontal */);
4467 if (Ap == 8)
4468 domino_draw8(M, i, j, dx, dy, rad, TRUE /* f_horizontal */);
4469 if (Aq == 8)
4470 domino_draw8(M, i, j + 1, dx, dy, rad, TRUE /* f_horizontal */);
4471 if (Ap == 9)
4472 domino_draw9(M, i, j, dx, dy, rad, TRUE /* f_horizontal */);
4473 if (Aq == 9)
4474 domino_draw9(M, i, j + 1, dx, dy, rad, TRUE /* f_horizontal */);
4475}
4476
4478 int i, int j, int dx, int dy, int rad)
4479{
4480 if (Ap == 1)
4481 domino_draw1(M, i, j, dx, dy, rad, FALSE /* f_horizontal */);
4482 if (Aq == 1)
4483 domino_draw1(M, i + 1, j, dx, dy, rad, FALSE /* f_horizontal */);
4484 if (Ap == 2)
4485 domino_draw2(M, i, j, dx, dy, rad, FALSE /* f_horizontal */);
4486 if (Aq == 2)
4487 domino_draw2(M, i + 1, j, dx, dy, rad, FALSE /* f_horizontal */);
4488 if (Ap == 3)
4489 domino_draw3(M, i, j, dx, dy, rad, FALSE /* f_horizontal */);
4490 if (Aq == 3)
4491 domino_draw3(M, i + 1, j, dx, dy, rad, FALSE /* f_horizontal */);
4492 if (Ap == 4)
4493 domino_draw4(M, i, j, dx, dy, rad, FALSE /* f_horizontal */);
4494 if (Aq == 4)
4495 domino_draw4(M, i + 1, j, dx, dy, rad, FALSE /* f_horizontal */);
4496 if (Ap == 5)
4497 domino_draw5(M, i, j, dx, dy, rad, FALSE /* f_horizontal */);
4498 if (Aq == 5)
4499 domino_draw5(M, i + 1, j, dx, dy, rad, FALSE /* f_horizontal */);
4500 if (Ap == 6)
4501 domino_draw6(M, i, j, dx, dy, rad, FALSE /* f_horizontal */);
4502 if (Aq == 6)
4503 domino_draw6(M, i + 1, j, dx, dy, rad, FALSE /* f_horizontal */);
4504 if (Ap == 7)
4505 domino_draw7(M, i, j, dx, dy, rad, FALSE /* f_horizontal */);
4506 if (Aq == 7)
4507 domino_draw7(M, i + 1, j, dx, dy, rad, FALSE /* f_horizontal */);
4508 if (Ap == 8)
4509 domino_draw8(M, i, j, dx, dy, rad, FALSE /* f_horizontal */);
4510 if (Aq == 8)
4511 domino_draw8(M, i + 1, j, dx, dy, rad, FALSE /* f_horizontal */);
4512 if (Ap == 9)
4513 domino_draw9(M, i, j, dx, dy, rad, FALSE /* f_horizontal */);
4514 if (Aq == 9)
4515 domino_draw9(M, i + 1, j, dx, dy, rad, FALSE /* f_horizontal */);
4516}
4517
4518
4519void mp_graphics::domino_draw_assignment(int *A, int *matching, int *B,
4520 int M, int N,
4521 int dx, int dy,
4522 int rad, int edge,
4523 int f_grid, int f_gray, int f_numbers, int f_frame,
4524 int f_cost, int cost)
4525{
4526 int Px[100], Py[100];
4527 char str[1000];
4528 int i, j, a, p, q;
4529
4530 if (f_cost) {
4531 Px[0] = (N * dx) / 2;
4532 Py[0] = (M + 1) * dy;
4533 sprintf(str, "${%d}$", cost);
4534 aligned_text(Px[0], Py[0], "", str);
4535 }
4536
4537
4538 for (i = 0; i < M; i++) {
4539 for (j = 0; j < N; j++) {
4540 Px[0] = j * dx;
4541 Py[0] = (M - i) * dy;
4542 Px[1] = (j + 1) * dx;
4543 Py[1] = (M - i) * dy;
4544 Px[2] = (j + 1) * dx;
4545 Py[2] = (M - i - 1) * dy;
4546 Px[3] = j * dx;
4547 Py[3] = (M - i - 1) * dy;
4548
4549 if (f_grid)
4550 polygon5(Px, Py, 0, 1, 2, 3, 0);
4551 if (f_gray) {
4552 a = B[i * N + j];
4553 if (a < 0)
4554 a = -a;
4555 sf_interior(100 - 10 * a);
4556 sf_color(0);
4557 fill_polygon5(Px, Py, 0, 1, 2, 3, 0);
4558 }
4559 if (f_numbers) {
4560 //Px[4] = j * dx + (dx >> 1);
4561 //Py[4] = (M - i) * dy - (dy >> 1);
4562 sprintf(str, "$%d$", B[i * N + j]);
4563 aligned_text(Px[2], Py[2], "br", str);
4564 }
4565 //cout << "i=" << i << "j=" << j << "p=" << p << endl;
4566 }
4567 }
4568
4569 sf_interior(100 /* fill_interior */);
4570 sf_color(1 /* fill_color */);
4571
4572 for (i = 0; i < M; i++) {
4573 for (j = 0; j < N; j++) {
4574 p = i * N + j;
4575 //cout << "i=" << i << "j=" << j << "p=" << p << endl;
4576 if (matching[p] == 3) {
4577 //cout << "East" << endl;
4578 Px[0] = j * dx;
4579 Py[0] = (M - i) * dy;
4580 Px[1] = (j + 2) * dx;
4581 Py[1] = (M - i) * dy;
4582 Px[2] = (j + 2) * dx;
4583 Py[2] = (M - i - 1) * dy;
4584 Px[3] = j * dx;
4585 Py[3] = (M - i - 1) * dy;
4586
4587 Px[4] = Px[0] + edge;
4588 Py[4] = Py[0] - edge;
4589 Px[5] = Px[1] - edge;
4590 Py[5] = Py[1] - edge;
4591 Px[6] = Px[2] - edge;
4592 Py[6] = Py[2] + edge;
4593 Px[7] = Px[3] + edge;
4594 Py[7] = Py[3] + edge;
4595
4596
4597 polygon5(Px, Py, 4, 5, 6, 7, 4);
4598 q = i * N + j + 1;
4599
4600 domino_draw_assignment_East(A[p], A[q], M,
4601 i, j, dx, dy, rad);
4602 }
4603 else if (matching[p] == 6) {
4604 //cout << "South" << endl;
4605 Px[0] = j * dx;
4606 Py[0] = (M - i) * dy;
4607 Px[1] = (j + 1) * dx;
4608 Py[1] = (M - i) * dy;
4609 Px[2] = (j + 1) * dx;
4610 Py[2] = (M - i - 2) * dy;
4611 Px[3] = j * dx;
4612 Py[3] = (M - i - 2) * dy;
4613
4614
4615 Px[4] = Px[0] + edge;
4616 Py[4] = Py[0] - edge;
4617 Px[5] = Px[1] - edge;
4618 Py[5] = Py[1] - edge;
4619 Px[6] = Px[2] - edge;
4620 Py[6] = Py[2] + edge;
4621 Px[7] = Px[3] + edge;
4622 Py[7] = Py[3] + edge;
4623
4624
4625 polygon5(Px, Py, 4, 5, 6, 7, 4);
4626 q = (i + 1) * N + j;
4627
4628 domino_draw_assignment_South(A[p], A[q], M,
4629 i, j, dx, dy, rad);
4630 }
4631 }
4632 }
4633
4634 if (f_frame) {
4635 sl_udsty(50);
4636 Px[0] = 0 * dx;
4637 Py[0] = M * dy;
4638 Px[1] = 0 * dx;
4639 Py[1] = 0 * dy;
4640 Px[2] = N * dx;
4641 Py[2] = 0 * dy;
4642 Px[3] = N * dx;
4643 Py[3] = M * dy;
4644 polygon5(Px, Py, 0, 1, 2, 3, 0);
4645 }
4646}
4647
4648}}}
4649
4650
matrices over GF(2) stored as bitvectors
functions related to strings and character arrays
void replace_extension_with(char *p, const char *new_ext)
options for drawing an object of type layered_graph
Definition: graphics.h:457
void bezier4(int *Px, int *Py, int i1, int i2, int i3, int i4)
void domino_draw2(int M, int i, int j, int dx, int dy, int rad, int f_horizontal)
void domino_draw1(int M, int i, int j, int dx, int dy, int rad, int f_horizontal)
void fill_polygon7(int *Px, int *Py, int i1, int i2, int i3, int i4, int i5, int i6, int i7)
void polygon_idx_mp(int *Px, int *Py, int *Idx, int n, int f_cycle)
void polygon_idx(int *Px, int *Py, int *Idx, int n)
void domino_draw_assignment_South(int Ap, int Aq, int M, int i, int j, int dx, int dy, int rad)
void polygon10(int *Px, int *Py, int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9, int i10)
void draw_density2(int no, int *outline_value, int *outline_number, int outline_sz, int min_value, int max_value, int offset_x, int f_switch_x, int f_title, const char *title, const char *label_x, int f_circle, int circle_at, int circle_rad, int f_mu, int f_sigma, int nb_standard_deviations, int f_v_grid, int v_grid, int f_h_grid, int h_grid)
void output_circle_text_tikz(int x, int y, int idx, int rad, const char *text)
void fill_idx(int *Px, int *Py, int *Idx, int n, const char *symbol, int f_cycle)
void domino_draw_assignment_East(int Ap, int Aq, int M, int i, int j, int dx, int dy, int rad)
void text_mp(int x1, int y1, const char *p)
void domino_draw4(int M, int i, int j, int dx, int dy, int rad, int f_horizontal)
void draw_polar_grid(double r_max, int nb_circles, int nb_rays, double x_stretch)
void aligned_text(int x, int y, const char *alignment, const char *p)
void polygon2(int *Px, int *Py, int i1, int i2)
void plot_curve(int N, int *f_DNE, double *Dx, double *Dy, double dx, double dy)
void grid_fill_polygon5(grid_frame *F, int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
void domino_draw8(int M, int i, int j, int dx, int dy, int rad, int f_horizontal)
void grid_polygon5(grid_frame *F, int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
void bezier_idx2(int *Px, int *Py, int *Idx, int n, int f_cycle)
void output_circle_text_mp(int x, int y, int idx, const char *text)
void polygon6(int *Px, int *Py, int i1, int i2, int i3, int i4, int i5, int i6)
void bezier_idx_log(int *Px, int *Py, int *Idx, int n)
void init(std::string &file_name, layered_graph_draw_options *Draw_options, int verbose_level)
Definition: mp_graphics.cpp:71
void fill_polygon3(int *Px, int *Py, int i1, int i2, int i3)
void fill_polygon11(int *Px, int *Py, int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9, int i10, int i11)
void draw_bitmatrix2(int f_dots, int f_partition, int nb_row_parts, int *row_part_first, int nb_col_parts, int *col_part_first, int f_row_grid, int f_col_grid, int f_bitmatrix, data_structures::bitmatrix *Bitmatrix, int *M, int m, int n, int f_has_labels, int *labels)
void polygon9(int *Px, int *Py, int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9)
void polygon2_arrow_halfway(int *Px, int *Py, int i1, int i2)
void polygon8(int *Px, int *Py, int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8)
void polygon11(int *Px, int *Py, int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9, int i10, int i11)
void draw_tournament(int x, int y, int dx, int dy, int nb_V, long int *Edges, int nb_E, int radius, int verbose_level)
void integer_4pts(int *Px, int *Py, int p1, int p2, int p3, int p4, const char *align, int a)
void fill_idx_tikz(std::ofstream &fp, int *Px, int *Py, int *Idx, int n, const char *symbol, int f_cycle)
void bezier_idx(int *Px, int *Py, int *Idx, int n)
void draw_axes_and_grid(layered_graph_draw_options *O, double x_min, double x_max, double y_min, double y_max, double dx, double dy, int f_x_axis_at_y_min, int f_y_axis_at_x_min, int x_mod, int y_mod, int x_tick_mod, int y_tick_mod, double x_labels_offset, double y_labels_offset, double x_tick_half_width, double y_tick_half_width, int f_v_lines, int subdivide_v, int f_h_lines, int subdivide_h, int verbose_level)
void polygon2_arrow_halfway_and_label(int *Px, int *Py, int i1, int i2, const char *alignment, const char *txt)
void text_log(int x1, int y1, const char *p)
void domino_draw3(int M, int i, int j, int dx, int dy, int rad, int f_horizontal)
void polygon7(int *Px, int *Py, int i1, int i2, int i3, int i4, int i5, int i6, int i7)
void projective_plane_draw_grid2(layered_graph_draw_options *O, int q, int *Table, int nb, int f_point_labels, char **Point_labels, int verbose_level)
void circle_text(int x, int y, int rad, const char *text)
void draw_matrix_in_color(int f_row_grid, int f_col_grid, int *Table, int nb_colors, int m, int n, int *color_scale, int nb_colors_in_scale, int f_has_labels, int *labels)
void exit(std::ostream &ost, int verbose_level)
void aligned_text_array(int *Px, int *Py, int idx, const char *alignment, const char *p)
void sl_ends(int line_beg_style, int line_end_style)
void domino_draw6(int M, int i, int j, int dx, int dy, int rad, int f_horizontal)
void text_tikz(int x1, int y1, const char *p)
void bezier2(int *Px, int *Py, int i1, int i2)
void draw_density2_multiple_curves(int no, int **outline_value, int **outline_number, int *outline_sz, int nb_curves, int min_x, int max_x, int min_y, int max_y, int offset_x, int f_switch_x, int f_title, const char *title, const char *label_x, int f_v_grid, int v_grid, int f_h_grid, int h_grid, int f_v_logarithmic, double log_base)
void bezier6(int *Px, int *Py, int i1, int i2, int i3, int i4, int i5, int i6)
void grid_polygon2(grid_frame *F, int x0, int y0, int x1, int y1)
void domino_draw5(int M, int i, int j, int dx, int dy, int rad, int f_horizontal)
void grid_aligned_text(grid_frame *F, int x, int y, const char *alignment, const char *p)
void polygon5(int *Px, int *Py, int i1, int i2, int i3, int i4, int i5)
void draw_graph_on_2D_grid(int x, int y, int dx, int dy, int rad, int nb_V, int *Edges, int nb_E, int *coords_2D, int *Base, int f_point_labels, int point_label_offset, int f_directed)
void bezier_idx_tikz(int *Px, int *Py, int *Idx, int n, int f_cycle)
void draw_graph_with_distinguished_edge(int x, int y, int dx, int dy, int nb_V, long int *Edges, int nb_E, int distinguished_edge, int verbose_level)
void bezier3(int *Px, int *Py, int i1, int i2, int i3)
void fill_polygon6(int *Px, int *Py, int i1, int i2, int i3, int i4, int i5, int i6)
void polygon_idx_tikz(int *Px, int *Py, int *Idx, int n, int f_cycle)
void domino_draw9(int M, int i, int j, int dx, int dy, int rad, int f_horizontal)
void aligned_text_with_offset(int x, int y, int xoffset, int yoffset, const char *alignment, const char *p)
void color_tikz(std::ofstream &fp, int color)
void polygon_idx_log(int *Px, int *Py, int *Idx, int n)
void fill_polygon9(int *Px, int *Py, int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9)
void bezier7(int *Px, int *Py, int i1, int i2, int i3, int i4, int i5, int i6, int i7)
void grid_polygon4(grid_frame *F, int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3)
void grid_fill_polygon4(grid_frame *F, int x0, int y0, int x1, int y1, int x2, int y2, int x3, int y3)
void polygon4(int *Px, int *Py, int i1, int i2, int i3, int i4)
void fill_polygon4(int *Px, int *Py, int i1, int i2, int i3, int i4)
void domino_draw7(int M, int i, int j, int dx, int dy, int rad, int f_horizontal)
void polygon3(int *Px, int *Py, int i1, int i2, int i3)
void draw_graph_on_multiple_circles(int x, int y, int dx, int dy, int nb_V, int *Edges, int nb_E, int nb_circles)
void fill_polygon10(int *Px, int *Py, int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9, int i10)
void domino_draw_assignment(int *A, int *matching, int *B, int M, int N, int dx, int dy, int rad, int edge, int f_grid, int f_gray, int f_numbers, int f_frame, int f_cost, int cost)
void polygon_idx2(int *Px, int *Py, int *Idx, int n, int f_cycle)
void text_4pts(int *Px, int *Py, int p1, int p2, int p3, int p4, const char *align, const char *str)
void draw_graph(int x, int y, int dx, int dy, int nb_V, long int *Edges, int nb_E, int radius, int verbose_level)
void fill_polygon5(int *Px, int *Py, int i1, int i2, int i3, int i4, int i5)
void fill_polygon8(int *Px, int *Py, int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8)
void finish(std::ostream &ost, int verbose_level)
void polygon3D(int *Px, int *Py, int dim, int x0, int y0, int z0, int x1, int y1, int z1)
void fill_idx_mp(int *Px, int *Py, int *Idx, int n, const char *symbol, int f_cycle)
void st_alignment(int txt_halign, int txt_valign)
void bezier_idx_mp(int *Px, int *Py, int *Idx, int n, int f_cycle)
void bezier5(int *Px, int *Py, int i1, int i2, int i3, int i4, int i5)
utility functions for plotting (graphing)
Definition: graphics.h:972
void get_coord(int *Px, int *Py, int idx, int x, int y, int min_x, int min_y, int max_x, int max_y, int f_switch_x)
Definition: plot_tools.cpp:289
void get_coord_log(int *Px, int *Py, int idx, int x, int y, int min_x, int min_y, int max_x, int max_y, double log_base, int f_switch_x)
Definition: plot_tools.cpp:299
void y_to_pt_on_curve(int y_in, int &x, int &y, int *outline_value, int *outline_number, int outline_sz)
Definition: plot_tools.cpp:313
numerical functions, mostly concerned with double
Definition: globals.h:129
void transform_llur(int *in, int *out, int &x, int &y)
Definition: numerics.cpp:2587
void transform_dist_x(int *in, int *out, int &x)
Definition: numerics.cpp:2640
void transform_dist_y(int *in, int *out, int &y)
Definition: numerics.cpp:2650
void on_circle_double(double *Px, double *Py, int idx, double angle_in_degree, double rad)
Definition: numerics.cpp:2548
#define MINIMUM(x, y)
Definition: foundations.h:216
#define FREE_int(p)
Definition: foundations.h:640
#define ONE_MILLION
Definition: foundations.h:226
#define Lint_vec_print(A, B, C)
Definition: foundations.h:686
#define NEW_int(n)
Definition: foundations.h:625
#define ABS(x)
Definition: foundations.h:220
#define TRUE
Definition: foundations.h:231
#define FALSE
Definition: foundations.h:234
#define EVEN(x)
Definition: foundations.h:221
#define M_PI
Definition: foundations.h:237
#define MAXIMUM(x, y)
Definition: foundations.h:217
#define DD_MULTIPLIER
the orbiter library for the classification of combinatorial objects
a class to help with drawing elements in a 2D grid fashion
Definition: graphics.h:531