Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
eepicgeom.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
61# ifndef EEPICGEOM_H
62# define EEPICGEOM_H
63
64
65# include <fstream>
66# include <tpl_dynDlist.H>
67# include <tpl_sort_utils.H>
68# include <point.H>
69# include <polygon.H>
70# include <ah-errors.H>
71
77extern bool tiny_keys;
78
79// TODO: dotted polygon curves
80
81class Eepic_Plane;
82
83
108{
110
112
113protected:
120
127
128public:
135 Eepic_Geom_Object(Geom_Object *ptr, const bool & __to_delete = false)
137 {
138 // empty
139 }
140
146 {
147 if (to_delete)
148 delete geom_object_ptr;
149 }
150
162 virtual void draw(Eepic_Plane *plane, std::ostream & output) const
163 {
164 (void)plane;
165 (void)output;
166
168 << "Eepic_Geom_Object is null";
169
170 ah_logic_error() << "Call to draw() method from abstract class";
171 }
172
180 virtual Eepic_Geom_Object * clone() const = 0;
181
185 virtual Point highest_point() const = 0;
186
190 virtual Point lowest_point() const = 0;
191
195 virtual Point leftmost_point() const = 0;
196
200 virtual Point rightmost_point() const = 0;
201};
202
203
250{
251 // Picture environment frame defined at construction time
252 double wide;
253 double height;
254
255 // Final frame dimensions based on user's scaling choice
256 double real_wide = 0;
257 double real_height = 0;
258
259 double xoffset;
260 double yoffset;
261
264
266
269
270 // NOTE: These must be initialized to zero as they are used in
271 // self-referential calculations
272 double x_min;
273 double y_min;
274
275 // Extreme points for computing object dimensions
278 Point __highest;
279 Point __lowest;
280
282
284 static const double default_r;
285
286 double r;
287
288 // Parameters that control the LaTeX picture environment
289 double resolution;
290
291 std::string fill_type;
292 std::string shade_type;
293
294 static const double normal_thickness;
295 static const double default_shade_thickness;
296
298
299 static const double dotgap;
300
307 const Geom_Number & geom_max,
308 const double & max) const
309 {
310 const Geom_Number ratio = p / geom_max;
311
312 double result = geom_number_to_double(ratio);
313
314 result = max * result;
315
316 return result;
317 }
318
325 double xpic(const double & x) const
326 {
327 return x - x_min;
328 }
329
331 double ypic(const double & y) const
332 {
333 return y - y_min;
334 }
335
336public:
338 double h_geom_number_to_eepic(const Geom_Number & x) const
339 {
341 }
342
345 {
347 }
348
350 double x_geom_number_to_eepic(const Geom_Number & x) const
351 {
353 }
354
357 {
358 const double result = geom_number_to_plane(y, geom_height, height);
359
360 return ypic(result);
361 }
362
365 {
366 // Scan all objects searching extreme coordinates (left, right, top, bottom).
368
369 Eepic_Geom_Object *curr = it.get_curr();
370
371 __lowest = curr->lowest_point();
372 __highest = curr->highest_point();
373 __leftmost = curr->leftmost_point();
375
376 for (it.next(); it.has_curr(); it.next_ne())
377 {
378 curr = it.get_curr();
379
380 if (curr->lowest_point().get_y() < __lowest.get_y())
381 __lowest = curr->lowest_point();
382
383 if (curr->highest_point().get_y() > __highest.get_y())
384 __highest = curr->highest_point();
385
386 if (curr->leftmost_point().get_x() < __leftmost.get_x())
387 __leftmost = curr->leftmost_point();
388
389 if (curr->rightmost_point().get_x() > __rightmost.get_x())
391 }
392 }
393
395 void zoom(const double & factor)
396 {
397 ah_domain_error_if(factor <= 0) << "zoom factor must be greater than zero";
398
399 height *= factor;
400 wide *= factor;
401 }
402
403private:
406 void compute_geom_plane(const bool & squarize)
407 {
409
410 // Compute minimal bounding box from contained figures.
411 geom_height = __highest.get_y() - __lowest.get_y();
412 geom_wide = __rightmost.get_x() - __leftmost.get_x();
413
414 // Compute minimal x/y.
417
418 // Shift so that min point maps to plane origin (0,0).
421
422 if (squarize) // Preserve aspect ratio (avoid distorting figures).
423 {
425 {
428 real_wide = wide;
429 }
430 else
431 {
435 }
436 }
437 else
438 {
439 real_wide = wide;
441 }
442
444 }
445
446 void draw_cartesian_axis(std::ostream & output);
447
448public:
449 const Point &leftmost() const { return __leftmost; }
450
451 const Point &rightmost() const { return __rightmost; }
452
453 const Point &highest() const { return __highest; }
454
455 const Point &lowest() const { return __lowest; }
456
458 std::string point_string(const Point & p)
459 {
460 const double x = x_geom_number_to_eepic(p.get_x());
461 const double y = y_geom_number_to_eepic(p.get_y());
462 return "(" + std::to_string(x) + "," + std::to_string(y) + ")";
463 }
464
475 void draw(std::ostream & output, const bool & squarize = true)
476 {
478
479 // Set floating point output format.
480 output << std::fixed << std::setprecision(6);
481
482 // Emit header and open picture environment.
483 output << "\\setlength{\\unitlength}{" << resolution << "mm}" << std::endl
484 << std::endl
485 << "\\filltype{" << fill_type << "}" << std::endl
486 << std::endl
487 << "% leftmost point is " << __leftmost.to_string() << " --> "
488 << point_string(__leftmost) << std::endl
489 << "% rightmost point is " << __rightmost.to_string() << " --> "
490 << point_string(__rightmost) << std::endl
491 << "% highest point is " << __highest.to_string() << " --> "
492 << point_string(__highest) << std::endl
493 << "% lowest point is " << __lowest.to_string() << " --> "
494 << point_string(__lowest) << std::endl
495 << "% " << list.size() << " geometric objects were put in the plane"
496 << std::endl
497 << "\\begin{picture}(" << real_wide << "," << real_height << ")"
498 << "(" << xoffset << "," << yoffset << ")" << std::endl
499 << std::endl;
500
501 draw_cartesian_axis(output); // Only if enabled.
502
503 // Draw each object.
505 it.has_curr(); it.next_ne())
506 {
507 Eepic_Geom_Object *curr = it.get_curr();
508
509 // Reset to default thickness each time.
510 output << "\\thinlines" << std::endl
511 << std::endl;
512
513 curr->draw(this, output);
514 }
515
516 // Close picture environment.
517 output << "\\end{picture}" << std::endl
518 << std::endl;
519 }
520
523 const double &get_wide() const { return wide; }
524
526 const double &get_height() const { return height; }
527
529 const double &get_yoffset() const { return yoffset; }
530
532 const double &get_xoffset() const { return xoffset; }
533
535 const double &get_r() const { return r; }
536
544 Eepic_Plane(const double & __wide,
545 const double & __height,
546 const double & __xoffset = 0.0,
547 const double & __yoffset = 0.0)
552 {
553 // empty
554 }
555
558 {
559 while (not list.is_empty())
560 delete list.remove_first_ne();
561 }
562
565 {
566 with_cartesian_axis = true;
567 }
568
605
607 void set_resolution(const double & res)
608 {
609 resolution = res;
610 }
611
613 const double &get_resolution() const { return resolution; }
614
616 void set_fill_type(const std::string & ftype)
617 {
619 }
620
622 void set_shade_thickness(const double & __thickness)
623 {
625 }
626
628 double get_shade_thickness() const { return shade_thickness; }
629
631 double get_dotgap() const { return dotgap; }
632
644 void draw_point(const Point & p, std::ostream & output)
645 {
646 const double x = x_geom_number_to_eepic(p.get_x());
647
648 const double y = y_geom_number_to_eepic(p.get_y());
649
650 output << " %% Point " << p.to_string()
651 << " %% mapped in this plane to (" << x << "," << y << ")"
652 << std::endl
653 << "\\put(" << x << "," << y << "){\\ellipse{" << r
654 << "}{" << r << "}}" << std::endl
655 << std::endl;
656 }
657
658 // Compute source/target EEPIC coordinates for a segment (macro for brevity).
659# define COMPUTE_SEGMENT_EEPIC_COORDENATES() \
660 const double src_x = x_geom_number_to_eepic(sg.get_src_point().get_x()); \
661 \
662 const double src_y = y_geom_number_to_eepic(sg.get_src_point().get_y()); \
663 \
664 const double tgt_x = x_geom_number_to_eepic(sg.get_tgt_point().get_x()); \
665 \
666 const double tgt_y = y_geom_number_to_eepic(sg.get_tgt_point().get_y());
667
668 // Draw the segment `sg` to `output` (macro uses locals above).
669# define DRAW_SEGMENT(sg, output) \
670 COMPUTE_SEGMENT_EEPIC_COORDENATES(); \
671 output << " %% Segment from " << sg.get_src_point().to_string() \
672 << " to " << sg.get_tgt_point().to_string() << std::endl \
673 << " %% mapped in this plane to (" << src_x << "," << src_y \
674 << ") to (" << tgt_x << "," << tgt_y << ")" << std::endl \
675 << "\\path(" << src_x << "," << src_y \
676 << ")(" << tgt_x << "," << tgt_y << ")" << std::endl \
677 << std::endl;
679 void draw_segment(const Segment & sg, std::ostream & output)
680 {
681 DRAW_SEGMENT(sg, output);
682 }
683
684 static const double arrow_width_in_mm;
685
686 static const double arrow_lenght_in_mm;
687
688 // Compute and draw the two small segments that form an arrow head.
689 // Uses src/tgt coordinates from COMPUTE_SEGMENT_EEPIC_COORDENATES().
690 // Geometry is controlled by arrow_width_in_mm and arrow_lenght_in_mm.
691# define PUT_ARROW() \
692 const double arrow_width = arrow_width_in_mm/resolution; \
693 const double arrow_lenght = arrow_lenght_in_mm/resolution; \
694 \
695 const double l = sqrt(arrow_width*arrow_width + arrow_lenght*arrow_lenght); \
696 const double tetha = atan2(arrow_width, arrow_lenght); \
697 const double phi = atan( fabs( (tgt_y - src_y)/(tgt_x - src_x) ) ); \
698 \
699 double dx1 = l*cos(phi - tetha); \
700 double dy1 = l*sin(phi - tetha); \
701 \
702 double dx2 = l*sin(M_PI_2 - (phi + tetha)); \
703 double dy2 = l*cos(M_PI_2 - (phi + tetha)); \
704 \
705 if (tgt_x > src_x) \
706 { \
707 dx1 = -dx1; \
708 dx2 = -dx2; \
709 } \
710 \
711 if (tgt_y > src_y) \
712 { \
713 dy1 = -dy1; \
714 dy2 = -dy2; \
715 } \
716 \
717 output << std::endl \
718 << " % Drawing of arrow's edges at (" << tgt_x \
719 << "," << tgt_y << ")" << std::endl \
720 << "\\path(" << tgt_x << "," << tgt_y << ")(" \
721 << tgt_x + dx1 << "," << tgt_y + dy1 << ")" << std::endl \
722 << "\\path(" << tgt_x << "," << tgt_y << ")(" \
723 << tgt_x + dx2 << "," << tgt_y + dy2 << ")" << std::endl << std::endl;
724
725 // Draw segment plus arrow head.
726# define DRAW_ARROW(sg, output) \
727 DRAW_SEGMENT(sg, output); \
728 PUT_ARROW();
729
731 void draw_arrow(const Segment & sg, std::ostream & output)
732 {
733 DRAW_ARROW(sg, output);
734 }
735
736 // Macro to draw a dotted segment.
737# define DRAW_DOTTED_SEGMENT(sg, output) \
738 COMPUTE_SEGMENT_EEPIC_COORDENATES(); \
739 \
740 output << " %% Dotted Segment from " << sg.get_src_point().to_string() \
741 << " to " << sg.get_tgt_point().to_string() << std::endl \
742 << " %% mapped in this plane to (" << src_x << "," << src_y \
743 << ") to (" << tgt_x << "," << tgt_y << ")" << std::endl \
744 << "\\dottedline{" << dotgap << "}(" << src_x \
745 << "," << src_y << ")(" << tgt_x << "," << tgt_y << ")" << std::endl \
746 << std::endl;
747
749 void draw_dotted_segment(const Segment & sg, std::ostream & output)
750 {
752 }
753
754 // Macro to draw a dashed segment.
755# define DRAW_DASH_SEGMENT(sg, output) \
756 COMPUTE_SEGMENT_EEPIC_COORDENATES(); \
757 \
758 output << " %% Dash Segment from " << sg.get_src_point().to_string() \
759 << " to " << sg.get_tgt_point().to_string() << std::endl \
760 << " %% mapped in this plane to (" << src_x << "," << src_y \
761 << ") to (" << tgt_x << "," << tgt_y << ")" << std::endl \
762 << "\\dashline{" << dotgap << "}(" << src_x \
763 << "," << src_y << ")(" << tgt_x << "," << tgt_y << ")" << std::endl \
764 << std::endl;
765
767 void draw_dash_segment(const Segment & sg, std::ostream & output)
768 {
770 }
771
772 // Dotted segment with arrow head (macro).
773# define DRAW_ARROW_DOTTED_SEGMENT(sg, output) \
774 COMPUTE_SEGMENT_EEPIC_COORDENATES(); \
775 \
776 output << " %% Dotted arrow Segment from " << sg.get_src_point().to_string() \
777 << " to " << sg.get_tgt_point().to_string() << std::endl \
778 << " %% mapped in this plane to (" << src_x << "," << src_y \
779 << ") to (" << tgt_x << "," << tgt_y << ")" << std::endl \
780 << "\\dottedline{" << dotgap << "}(" << src_x \
781 << "," << src_y << ")(" << tgt_x << "," << tgt_y << ")" << std::endl \
782 << std::endl; \
783 PUT_ARROW();
784
786 void draw_arrow_dotted_segment(const Segment & sg, std::ostream & output)
787 {
789 }
790
791 // Dashed segment with arrow head (macro).
792# define DRAW_ARROW_DASH_SEGMENT(sg, output) \
793 COMPUTE_SEGMENT_EEPIC_COORDENATES(); \
794 \
795 output << " %% Dash arrow Segment from " << sg.get_src_point().to_string() \
796 << " to " << sg.get_tgt_point().to_string() << std::endl \
797 << " %% mapped in this plane to (" << src_x << "," << src_y \
798 << ") to (" << tgt_x << "," << tgt_y << ")" << std::endl \
799 << "\\dashline{" << dotgap << "}(" << src_x \
800 << "," << src_y << ")(" << tgt_x << "," << tgt_y << ")" << std::endl \
801 << std::endl; \
802 PUT_ARROW();
803
805 void draw_arrow_dash_segment(const Segment & sg, std::ostream & output)
806 {
808 }
809
811 void draw_ellipse(const Ellipse & e, std::ostream & output)
812 {
813 const Point & center = e.get_center();
814
815 const double x = x_geom_number_to_eepic(center.get_x());
816
817 const double y = y_geom_number_to_eepic(center.get_y());
818
819 const double hd = h_geom_number_to_eepic(2 * e.get_hradius());
820
821 const double vd = v_geom_number_to_eepic(2 * e.get_vradius());
822
823 output << " %% Ellipse with center in " << center.to_string()
824 << " with horizontal radius of " << e.get_hradius()
825 << " and vertical radius of " << e.get_vradius() << std::endl
826 << " %% mapped in the plane at center (" << x
827 << "," << y << ") with horizontal radius of " << hd
828 << " and vertical radius of " << vd << std::endl
829 << "\\put(" << x << "," << y << "){\\ellipse{" << hd
830 << "}{" << vd << "}}" << std::endl
831 << std::endl;
832 }
833
834 // Member-function pointer type used to draw a segment.
835 // Lets us implement polygon drawing generically by viewing polygon sides as segments.
837 std::ostream & output);
838
839
840 // Draw a polygon by iterating its sides (segments).
841 // draw_sg_fct is the member-function pointer used to draw each side.
842 // This is generic and is also used for regular polygons.
843 template <class Poly>
844 void draw_polygon(Poly & poly,
845 std::ostream & output,
847 {
848 for (typename Poly::Segment_Iterator it(poly); it.has_curr(); it.next_ne())
849 (this->*draw_sg_fct)(it.get_current_segment(), output);
850 }
851
852 // Draw polygon interior shading using a vertex path.
853 // Faster than the segment-based version, but less flexible.
854 template <class Poly>
855 void draw_closed_polygon(Poly & poly, std::ostream & output)
856 {
857 output << " % Drawing of polygon of " << poly.size()
858 << " sides" << std::endl
859 << "\\shade\\path";
860
861 for (typename Poly::Vertex_Iterator it(poly); it.has_curr(); it.next_ne())
862 output << point_string(it.get_current_vertex());
863
864 if (poly.is_closed())
865 output << point_string(poly.get_first_vertex()) << std::endl;
866 }
867
868 // Draw shaded polygon with dotted border.
869 template <class Poly>
870 void draw_dotted_closed_polygon(Poly & poly, std::ostream & output)
871 {
872 output << " % Drawing of dotted line Polygon" << std::endl
873 << "\\shade\\dottedline{" << dotgap << "}";
874
875 for (typename Poly::Vertex_Iterator it(poly); it.has_curr(); it.next_ne())
876 output << point_string(it.get_current_vertex());
877
878 if (poly.is_closed())
879 output << point_string(poly.get_first_vertex()) << std::endl;
880 }
881
882 // Draw only polygon vertices as points (does NOT draw sides).
883 template <class Poly>
884 void draw_dots_from_polygon(Poly & poly, std::ostream & output)
885 {
886 for (typename Poly::Vertex_Iterator it(poly); it.has_curr(); it.next_ne())
887 {
888 Vertex & vertex = it.get_current_vertex();
889
890 draw_point(vertex, output);
891 }
892 }
893
894 // Draw only the arrow head of segment sg.
895 void draw_arrow_extreme(const Segment & sg, std::ostream & output)
896 { // ¡tal cual!
898 PUT_ARROW();
899 }
900
901 // Draw arrow heads for each polygon side (does NOT draw the sides).
902 template <class Poly>
903 void draw_arrows_in_polygon(Poly & poly, std::ostream & output)
904 {
905 for (typename Poly::Segment_Iterator it(poly); it.has_curr(); it.next_ne())
906 {
907 const Segment & sg = it.get_current_segment();
908
910 }
911 }
912
913 template <class Poly>
914 void draw_closed_polygon_with_arrows(Poly & poly, std::ostream & output)
915 {
918 }
919
920 // Draw a text label for point p (as "(x,y)"), slightly shifted in y.
921 void draw_point_text(const Point & p, std::ostream & output)
922 {
923 const double x = x_geom_number_to_eepic(p.get_x());
924
925 const double y = y_geom_number_to_eepic(p.get_y()) + r;
926
927 const std::string str = p.to_string();
928
929 output << " %% Text Point " << str
930 << " %% mapped in this plane to (" << x << "," << y << ")"
931 << std::endl
932 << "\\put(" << x << "," << y << "){\\texttt{" << str
933 << "}}" << std::endl
934 << std::endl;
935 }
936
937 // Draw text labels for polygon vertices (does NOT draw sides).
938 // TODO: place text inside/outside without crossing edges.
939 template <class Poly>
940 void draw_points_text_in_polygon(Poly & poly, std::ostream & output)
941 {
942 for (typename Poly::Vertex_Iterator it(poly); it.has_curr(); it.next_ne())
943 draw_point_text(it.get_current_vertex(), output);
944 }
945
946 // Draw vertex numbers (does NOT draw sides).
947 // TODO: place numbers inside/outside without crossing edges.
948 template <class Poly>
949 void draw_vertex_numbers_in_polygon(Poly & poly, std::ostream & output)
950 {
951 int n = 0;
952
953 for (typename Poly::Vertex_Iterator it(poly);
954 it.has_curr(); it.next_ne(), ++n)
955 {
956 Vertex & vertex = it.get_current_vertex();
957
958 const double x = x_geom_number_to_eepic(vertex.get_x());
959
960 const double y = y_geom_number_to_eepic(vertex.get_y()) - r;
961
962 output << " %% Poligon Vertex Number " << n
963 << " %% mapped in this plane to (" << x << "," << y << ")"
964 << std::endl
965 << "\\put(" << x << "," << y << "){$" << n << "$}" << std::endl
966 << std::endl;
967 }
968 }
969
970 // Draw a spline through polygon vertices.
971 template <class Poly>
972 void draw_spline(Poly & poly, std::ostream & output)
973 {
974 output << " % Drawing spline of " << poly.size()
975 << " points" << std::endl
976 << "\\spline";
977
978 for (typename Poly::Vertex_Iterator it(poly); it.has_curr(); it.next_ne())
979 output << point_string(it.get_current_vertex());
980
981 if (poly.is_closed())
982 output << point_string(poly.get_first_vertex()) << std::endl;
983 }
984
985 // Draw a piecewise-linear curve through polygon vertices.
986 template <class Poly>
987 void draw_dash_spline(Poly & poly, std::ostream & output)
988 {
989 output << " % Drawing dash curve of " << poly.size()
990 << " points" << std::endl
991 << "\\closecurve";
992
993 for (typename Poly::Vertex_Iterator it(poly); it.has_curr(); it.next_ne())
994 output << point_string(it.get_current_vertex());
995
996 if (poly.is_closed())
997 output << point_string(poly.get_first_vertex()) << std::endl;
998 }
999
1000 // Draw spline plus an arrow head at the last segment.
1001 template <class Poly>
1002 void draw_spline_arrow(Poly & poly, std::ostream & output)
1003 {
1004 draw_spline(poly, output); // draw curve first
1005
1006 // Now draw the arrow head using the slope of the last segment.
1007
1008 draw_arrow_extreme(poly.get_last_segment(), output);
1009 }
1010
1011 // Draw dashed curve plus an arrow head at the last segment.
1012 template <class Poly>
1013 void draw_dash_spline_arrow(Poly & poly, std::ostream & output)
1014 {
1015 draw_dash_spline(poly, output); // draw curve first
1016
1017 // Now draw the arrow head using the slope of the last segment.
1018
1019 draw_arrow_extreme(poly.get_last_segment(), output);
1020 }
1021
1022 void draw_text(const Text & t, std::ostream & output,
1023 const double & hfactor, const double & vfactor)
1024 {
1025 const Point & p = t.get_point();
1026
1028
1029 const double x =
1031
1032 const double y = (y_geom_number_to_eepic(p.get_y()) -
1034
1035 output << "% std::string at " << p.to_string() << std::endl
1036 << "% mapped to the plane at (" << x << "," << y << ")" << std::endl
1037 << "\\put(" << x << "," << y << "){\\texttt{"
1038 << (tiny_keys ? "\\tiny " : "") << t.get_str()
1039 << "}}" << std::endl
1040 << std::endl;
1041 }
1042};
1043
1044
1054# define DEFINE_EEPIC_COPY_CTOR(Type) \
1055 Eepic_##Type(const Type & o) : Eepic_Geom_Object(new Type(o), true) { }
1056
1057
1059# define DEFINE_EEPIC_COMMON_METHODS(Type) \
1060 friend void put_in_plane(Eepic_Plane & plane, const Type & geom_obj); \
1061 \
1062 ~Eepic_##Type() { } \
1063 \
1064 Point highest_point() const override \
1065 { \
1066 return static_cast<const Type*>(geom_object_ptr)->highest_point(); \
1067 } \
1068 \
1069 Point lowest_point() const override \
1070 { \
1071 return static_cast<const Type*>(geom_object_ptr)->lowest_point(); \
1072 } \
1073 \
1074 Point leftmost_point() const override \
1075 { \
1076 return static_cast<const Type*>(geom_object_ptr)->leftmost_point(); \
1077 } \
1078 \
1079 Point rightmost_point() const override \
1080 { \
1081 return static_cast<const Type*>(geom_object_ptr)->rightmost_point(); \
1082 } \
1083 \
1084 Eepic_Geom_Object * clone() const override \
1085 { \
1086 return new Eepic_##Type(static_cast<const Type&>(*geom_object_ptr)); \
1087 } \
1088 \
1089 void draw(Eepic_Plane * plane, std::ostream & output) const override;
1090
1091
1093# define DEFINE_EEPIC_COMMON_WITH_COPY_CTOR(Type) \
1094 DEFINE_EEPIC_COPY_CTOR(Type) \
1095 DEFINE_EEPIC_COMMON_METHODS(Type)
1096
1097
1099# define DEFINE_EEPIC_COMMON_WITHOUT_COPY_CTOR(Type) \
1100 DEFINE_EEPIC_COMMON_METHODS(Type) \
1101 Eepic_##Type(const Type &);
1102
1103
1105# define DEFINE_PUT_IN_PLANE(Type) \
1106 extern void put_in_plane(Eepic_Plane & plane, const Type & geom_obj)
1107
1108
1109# define IMPL_PUT_IN_PLANE(Type) \
1110 void put_in_plane(Eepic_Plane & plane, const Type & geom_obj) \
1111 { \
1112 Eepic_##Type eepic_obj(geom_obj); \
1113 \
1114 plane.put(eepic_obj); \
1115 }
1116
1123// Typical definition of an Eepic_Type wrapper class.
1124// Only Eepic_Plane::put(const Eepic_Type&) needs to be implemented.
1125# define DEFINE_EEPIC_CLASS(Type) \
1126 class Eepic_##Type : public Eepic_Geom_Object \
1127 { \
1128 DEFINE_EEPIC_COMMON_WITH_COPY_CTOR(Type) \
1129 }; \
1130 \
1131 DEFINE_PUT_IN_PLANE(Type)
1132
1133
1134// Typical definition of an Eepic_Type wrapper class with extra members.
1135// This implies defining the copy-constructor separately to initialize
1136// additional attributes.
1137# define DEFINE_EEPIC_CLASS_AND_MEMBERS(Type, ...) \
1138 class Eepic_##Type : public Eepic_Geom_Object \
1139 { \
1140 __VA_ARGS__ ; \
1141 DEFINE_EEPIC_COMMON_WITHOUT_COPY_CTOR(Type) \
1142 }; \
1143 \
1144 DEFINE_PUT_IN_PLANE(Type)
1145
1146
1152
1153
1155
1156
1161# define DEFINE_CLASS_DERIVATED_FROM_SEGMENT(Name) \
1162 struct Name : public Segment \
1163 { \
1164 Name() { } \
1165 \
1166 Name(const Segment & s) : Segment(s) \
1167 { \
1168 \
1169 } \
1170 Name(const Point & __src, const Point & __tgt) \
1171 : Segment(__src, __tgt) \
1172 { \
1173 \
1174 } \
1175 \
1176 Name(const Point & __src, \
1177 const Geom_Number & m, \
1178 const Geom_Number & d) \
1179 : Segment(__src, m, d) \
1180 { \
1181 \
1182 } \
1183 };
1184
1185// Define a Segment-derived type named Name. Purpose: provide a distinct geometric
1186// type name (different from Segment) so it can have different EEPIC drawing behavior.
1187# define DEFINE_EEPIC_SEGMENT_CLASS(Name) \
1188 DEFINE_CLASS_DERIVATED_FROM_SEGMENT(Name) \
1189 DEFINE_EEPIC_CLASS(Name);
1190
1191
1192// Same as DEFINE_EEPIC_SEGMENT_CLASS, but allows extra members to be injected
1193// via the macro parameter list.
1194# define DEFINE_EEPIC_SEGMENT_CLASS_AND_MEMBERS(Name, ...) \
1195 DEFINE_CLASS_DERIVATED_FROM_SEGMENT(Name) \
1196 DEFINE_EEPIC_CLASS_AND_MEMBERS(Name, __VA_ARGS__);
1197
1198
1206
1208
1210
1212
1214
1216
1218
1220
1222
1223
1226
1227
1230
1231
1232// Define an Ellipse-derived type to allow different drawing behaviors.
1233# define DEFINE_CLASS_DERIVATED_FROM_ELLIPSE(Name) \
1234 struct Name : public Ellipse \
1235 { \
1236 Name() { } \
1237 \
1238 Name(const Ellipse & p) : Ellipse(p) \
1239 { \
1240 \
1241 } \
1242 \
1243 Name(const Point & center, \
1244 const Geom_Number & hr, \
1245 const Geom_Number & vr) \
1246 : Ellipse(center, hr, vr) \
1247 { \
1248 \
1249 } \
1250 };
1251
1252
1254
1256
1258
1260
1261
1264# define DEFINE_CLASS_DERIVATED_FROM_TEXT(Name) \
1265 struct Name : public Text \
1266 { \
1267 Name() { } \
1268 \
1269 Name(const Text & t) : Text(t) \
1270 { \
1271 \
1272 } \
1273 \
1274 Name(const Point & p, const std::string & str) \
1275 : Text(p, str) \
1276 { \
1277 \
1278 } \
1279 };
1280
1281
1283
1285
1287
1289
1291
1293
1295
1296
1303// The simplest polygon wrapper (default drawing behavior).
1305
1306
1307// Define a Polygon-derived type to allow different drawing behaviors.
1308# define DEFINE_CLASS_DERIVATED_FROM_POLYGON(Name) \
1309 struct Name : public Polygon \
1310 { \
1311 Name() { } \
1312 \
1313 Name(const Polygon & p) : Polygon(p) \
1314 { \
1315 \
1316 } \
1317 };
1318
1319
1320# define DEFINE_EEPIC_POLYGON(Name) \
1321 DEFINE_CLASS_DERIVATED_FROM_POLYGON(Name); \
1322 DEFINE_EEPIC_CLASS(Name);
1323
1324
1325// Polygon variants.
1326
1327// With point circles at vertices.
1329
1330// With point circles at vertices and arrow heads on sides.
1332
1333// Dotted sides.
1335
1336// Dashed sides.
1338
1339// Dotted sides with point circles at vertices.
1341
1342// Dashed sides with point circles at vertices.
1344
1345// Dashed sides with an arrow head on the last segment.
1347
1348// Shaded interior (gray).
1350
1351// Shaded interior with point circles at vertices.
1353
1354// Shaded interior, sides drawn as arrows.
1356
1357// Shaded interior with vertex coordinate labels.
1359
1360// Shaded interior with vertex numbers.
1362
1363// Spline curve built from polygon vertices.
1365
1366// Piecewise-linear curve built from polygon vertices.
1368
1369// Spline curve with arrow head at the end.
1371
1372// Piecewise-linear curve with arrow head at the end.
1374
1375// With point circles at vertices.
1377
1378// With point circles at vertices.
1380
1381// Dotted sides.
1383
1384// Dashed sides.
1386
1387// Dotted sides with point circles at vertices.
1389
1390// Dashed sides with point circles at vertices.
1392
1393// Dashed sides with arrow heads.
1395
1396// Shaded interior (gray).
1398
1399// Shaded interior with point circles at vertices.
1401
1402// Shaded interior, sides drawn as arrows.
1404
1405// Shaded interior with vertex coordinate text.
1407
1408// Shaded interior with vertex numbers.
1410
1411// Thick spline curve built from polygon vertices.
1413
1414// Thick piecewise-linear curve built from polygon vertices.
1416
1417// Thick spline curve with arrow head.
1419
1420// Thick piecewise-linear curve with arrow head.
1422
1435// Define a new class derived from Regular_Polygon to allow different drawing behaviors.
1436// A new type is needed because the constructor differs.
1437# define DEFINE_CLASS_DERIVATED_FROM_REGULAR_POLYGON(Name) \
1438 struct Name : public Regular_Polygon \
1439 { \
1440 Name() { } \
1441 \
1442 Name(const Regular_Polygon & p) : Regular_Polygon(p) \
1443 { \
1444 \
1445 } \
1446 \
1447 Name(const Point & c, \
1448 const double & side_sz, \
1449 const size_t & n, \
1450 const double & ang = 0) \
1451 : Regular_Polygon(c, side_sz, n, ang) \
1452 { \
1453 \
1454 } \
1455 };
1456
1457
1458# define DEFINE_EEPIC_REGULAR_POLYGON(Name) \
1459 DEFINE_CLASS_DERIVATED_FROM_REGULAR_POLYGON(Name); \
1460 DEFINE_EEPIC_CLASS(Name);
1461
1462
1464
1465// Regular polygon variants.
1467
1469
1471
1473
1475
1477
1479
1481
1483
1485
1486
1487# endif // EEPICGEOM_H
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
Definition ah-errors.H:522
#define ah_logic_error()
Throws std::logic_error unconditionally.
Definition ah-errors.H:341
long double vd
Definition btreepic.C:152
long double hd
Definition btreepic.C:151
Iterator dynamic list.
void next_ne() noexcept
Move the iterator one position forward guaranteeing no exception.
T & get_curr() const
Return the current item; throw overflow_error if there is no current item.
void next()
Move the iterator one item forward.
Dynamic doubly linked list with O(1) size and bidirectional access.
const size_t & size() const noexcept
Return the number of elements (constant time)
T & append(const T &item)
Append a copied item at the end of the list.
T remove_first_ne() noexcept
Remove the first item of the list; return a copy of removed item.
Abstract base class for EEPIC-drawable geometric objects.
Definition eepicgeom.H:108
virtual Eepic_Geom_Object * clone() const =0
Create a polymorphic copy of this object.
const Geom_Object *const geom_object_ptr
Pointer to the wrapped geometric object.
Definition eepicgeom.H:119
virtual ~Eepic_Geom_Object()
Virtual destructor.
Definition eepicgeom.H:145
Eepic_Geom_Object(Geom_Object *ptr, const bool &__to_delete=false)
Construct an EEPIC wrapper for a geometric object.
Definition eepicgeom.H:135
Eepic_Geom_Object(const Eepic_Geom_Object &)
virtual void draw(Eepic_Plane *plane, std::ostream &output) const
Generate EEPIC code for this object.
Definition eepicgeom.H:162
virtual Point lowest_point() const =0
Get the lowest point (minimum y-coordinate) of this object.
virtual Point highest_point() const =0
Get the highest point (maximum y-coordinate) of this object.
bool to_delete
Flag indicating ownership of geom_object_ptr.
Definition eepicgeom.H:126
virtual Point rightmost_point() const =0
Get the rightmost point (maximum x-coordinate) of this object.
virtual Point leftmost_point() const =0
Get the leftmost point (minimum x-coordinate) of this object.
2D canvas for generating EEPIC/LaTeX picture environments.
Definition eepicgeom.H:250
static const double dotgap
Gap between dots in dotted lines.
Definition eepicgeom.H:299
void draw_dotted_segment(const Segment &sg, std::ostream &output)
Emit EEPIC code to draw dotted segment sg.
Definition eepicgeom.H:749
const double & get_height() const
Picture height (in EEPIC units).
Definition eepicgeom.H:526
Geom_Number geom_height
Height from lowest to highest point.
Definition eepicgeom.H:263
std::string fill_type
Fill type for shapes (e.g., "black")
Definition eepicgeom.H:291
void draw_arrow_dash_segment(const Segment &sg, std::ostream &output)
Emit EEPIC code to draw dashed segment sg with arrow head.
Definition eepicgeom.H:805
Point __lowest
Point with minimum y-coordinate.
Definition eepicgeom.H:279
Point __leftmost
Point with minimum x-coordinate.
Definition eepicgeom.H:276
Eepic_Plane(const double &__wide, const double &__height, const double &__xoffset=0.0, const double &__yoffset=0.0)
Construct a plane with a fixed picture frame.
Definition eepicgeom.H:544
void zoom(const double &factor)
Scale the EEPIC plane in real points (zoom in/out).
Definition eepicgeom.H:395
void set_fill_type(const std::string &ftype)
Set the fill type used by LaTeX eepic (e.g., "black").
Definition eepicgeom.H:616
void draw_point_text(const Point &p, std::ostream &output)
Definition eepicgeom.H:921
double real_wide
Actual width after scaling.
Definition eepicgeom.H:256
void draw_segment(const Segment &sg, std::ostream &output)
Emit EEPIC code to draw segment sg.
Definition eepicgeom.H:679
double get_shade_thickness() const
Return the current shading thickness.
Definition eepicgeom.H:628
Geom_Number geom_y_min
Minimum y value in geometric coordinates.
Definition eepicgeom.H:268
double y_geom_number_to_eepic(const Geom_Number &y) const
Convert a geometric y coordinate into plane y coordinate.
Definition eepicgeom.H:356
void compute_geom_plane(const bool &squarize)
Compute extreme coordinates and derive width/height of all objects.
Definition eepicgeom.H:406
DynDlist< Eepic_Geom_Object * > list
List of geometric objects.
Definition eepicgeom.H:265
double x_min
Minimum x value in plane coordinates.
Definition eepicgeom.H:272
const double & get_yoffset() const
Y offset of the LaTeX picture environment.
Definition eepicgeom.H:529
double r
Actual radius in real points for drawing a point.
Definition eepicgeom.H:286
void draw_dash_spline(Poly &poly, std::ostream &output)
Definition eepicgeom.H:987
void set_resolution(const double &res)
Set the output resolution in millimeters (unitlength = res mm).
Definition eepicgeom.H:607
double y_min
Minimum y value in plane coordinates.
Definition eepicgeom.H:273
double resolution
Resolution in millimeters (default: 0.05mm)
Definition eepicgeom.H:289
double height
Height in resolution points.
Definition eepicgeom.H:253
Point __rightmost
Point with maximum x-coordinate.
Definition eepicgeom.H:277
bool with_cartesian_axis
Flag to draw Cartesian axes.
Definition eepicgeom.H:281
static const double arrow_lenght_in_mm
Definition eepicgeom.H:686
Point __highest
Point with maximum y-coordinate.
Definition eepicgeom.H:278
static const double normal_thickness
Default line thickness.
Definition eepicgeom.H:294
const double & get_wide() const
Plane accessors.
Definition eepicgeom.H:523
Geom_Number geom_wide
Width from leftmost to rightmost point.
Definition eepicgeom.H:262
double wide
Width in resolution points.
Definition eepicgeom.H:252
const double & get_xoffset() const
X offset of the LaTeX picture environment.
Definition eepicgeom.H:532
double ypic(const double &y) const
Normalize to y-axis origin.
Definition eepicgeom.H:331
static const double default_r
Default radius for drawing points (also used for text height)
Definition eepicgeom.H:284
void compute_extreme_points()
Linear scan over all objects to compute extreme points.
Definition eepicgeom.H:364
double get_dotgap() const
Return the dot gap used for dotted/dashed lines.
Definition eepicgeom.H:631
void draw_ellipse(const Ellipse &e, std::ostream &output)
Emit EEPIC code to draw ellipse e.
Definition eepicgeom.H:811
void draw_arrow_extreme(const Segment &sg, std::ostream &output)
Definition eepicgeom.H:895
static const double default_shade_thickness
Default shading thickness.
Definition eepicgeom.H:295
double xoffset
Additional horizontal margin.
Definition eepicgeom.H:259
double h_geom_number_to_eepic(const Geom_Number &x) const
Convert a geometric x proportion into plane units using wide.
Definition eepicgeom.H:338
const double & get_resolution() const
Return the current output resolution in millimeters.
Definition eepicgeom.H:613
void draw_text(const Text &t, std::ostream &output, const double &hfactor, const double &vfactor)
Definition eepicgeom.H:1022
void draw_dots_from_polygon(Poly &poly, std::ostream &output)
Definition eepicgeom.H:884
void set_shade_thickness(const double &__thickness)
Set the thickness used for shaded primitives.
Definition eepicgeom.H:622
void(Eepic_Plane::* Draw_Segment_Fct)(const Segment &poly, std::ostream &output)
Definition eepicgeom.H:836
void draw_points_text_in_polygon(Poly &poly, std::ostream &output)
Definition eepicgeom.H:940
void draw_dash_spline_arrow(Poly &poly, std::ostream &output)
Definition eepicgeom.H:1013
double real_height
Actual height after scaling.
Definition eepicgeom.H:257
void draw_closed_polygon(Poly &poly, std::ostream &output)
Definition eepicgeom.H:855
void draw_polygon(Poly &poly, std::ostream &output, Draw_Segment_Fct draw_sg_fct)
Definition eepicgeom.H:844
void draw_closed_polygon_with_arrows(Poly &poly, std::ostream &output)
Definition eepicgeom.H:914
double x_geom_number_to_eepic(const Geom_Number &x) const
Convert a geometric x coordinate into plane x coordinate.
Definition eepicgeom.H:350
const Point & highest() const
Definition eepicgeom.H:453
std::string shade_type
Shading type for segments.
Definition eepicgeom.H:292
void put_cartesian_axis()
Enable drawing Cartesian axes when calling draw().
Definition eepicgeom.H:564
void draw_arrow(const Segment &sg, std::ostream &output)
Emit EEPIC code to draw segment sg with an arrow head.
Definition eepicgeom.H:731
void draw_vertex_numbers_in_polygon(Poly &poly, std::ostream &output)
Definition eepicgeom.H:949
double shade_thickness
Current shading thickness.
Definition eepicgeom.H:297
double yoffset
Additional vertical margin.
Definition eepicgeom.H:260
const double & get_r() const
Radius used to draw points (also used as text baseline offset).
Definition eepicgeom.H:535
void draw_arrows_in_polygon(Poly &poly, std::ostream &output)
Definition eepicgeom.H:903
double v_geom_number_to_eepic(const Geom_Number &y) const
Convert a geometric y proportion into plane units using height.
Definition eepicgeom.H:344
Geom_Number geom_x_min
Minimum x value in geometric coordinates.
Definition eepicgeom.H:267
static const double arrow_width_in_mm
Definition eepicgeom.H:684
void put(const Eepic_Geom_Object &__eepic_geom_obj)
Design note: why Eepic_Plane stores Eepic_Geom_Object wrappers.
Definition eepicgeom.H:599
const Point & lowest() const
Definition eepicgeom.H:455
const Point & rightmost() const
Definition eepicgeom.H:451
void draw_spline(Poly &poly, std::ostream &output)
Definition eepicgeom.H:972
void draw_point(const Point &p, std::ostream &output)
EEPIC "primitive drawing" methods.
Definition eepicgeom.H:644
double geom_number_to_plane(const Geom_Number &p, const Geom_Number &geom_max, const double &max) const
Rescales a coordinate value p from a geometric scale geom_max into the plane scale max.
Definition eepicgeom.H:306
void draw_dotted_closed_polygon(Poly &poly, std::ostream &output)
Definition eepicgeom.H:870
void draw(std::ostream &output, const bool &squarize=true)
Emits a complete LaTeX picture environment containing the geometric objects.
Definition eepicgeom.H:475
~Eepic_Plane()
Destructor: deletes all stored Eepic_Geom_Object clones.
Definition eepicgeom.H:557
void draw_arrow_dotted_segment(const Segment &sg, std::ostream &output)
Emit EEPIC code to draw dotted segment sg with arrow head.
Definition eepicgeom.H:786
void draw_dash_segment(const Segment &sg, std::ostream &output)
Emit EEPIC code to draw dashed segment sg.
Definition eepicgeom.H:767
void draw_spline_arrow(Poly &poly, std::ostream &output)
Definition eepicgeom.H:1002
void draw_cartesian_axis(std::ostream &output)
Definition eepicgeom.C:243
const Point & leftmost() const
Definition eepicgeom.H:449
double xpic(const double &x) const
Points must be normalized to the plane size (in picture coordinates).
Definition eepicgeom.H:325
std::string point_string(const Point &p)
Given point p, returns "(x,y)" in normalized plane coordinates.
Definition eepicgeom.H:458
const Geom_Number & get_vradius() const
Definition point.H:1182
const Geom_Number & get_hradius() const
Definition point.H:1180
const Point & get_center() const
Definition point.H:1178
A general (irregular) 2D polygon defined by a sequence of vertices.
Definition polygon.H:233
A regular polygon defined by center, side length, and vertex count.
Definition polygon.H:829
Fundamental segment defined by two points.
Definition point.H:417
Definition point.H:1524
static const double font_width_in_points
Definition point.H:1532
const Point & get_point() const
Definition point.H:1548
const std::string & get_str() const
Definition point.H:1553
const size_t & len() const
Definition point.H:1546
static const double font_height_in_points
Definition point.H:1534
A vertex in a polygon's doubly-linked vertex list.
Definition polygon.H:113
#define DRAW_DOTTED_SEGMENT(sg, output)
Definition eepicgeom.H:737
#define DEFINE_EEPIC_CLASS(Type)
Fundamental macro to declare a class derived from Eepic_Geom_Object.
Definition eepicgeom.H:1125
#define DEFINE_EEPIC_REGULAR_POLYGON(Name)
Definition eepicgeom.H:1458
#define DRAW_ARROW(sg, output)
Definition eepicgeom.H:726
bool tiny_keys
Global flag to enable tiny font size for keys/labels.
#define DRAW_ARROW_DOTTED_SEGMENT(sg, output)
Definition eepicgeom.H:773
#define DEFINE_EEPIC_SEGMENT_CLASS(Name)
Definition eepicgeom.H:1187
#define DEFINE_CLASS_DERIVATED_FROM_ELLIPSE(Name)
Definition eepicgeom.H:1233
#define DRAW_DASH_SEGMENT(sg, output)
Definition eepicgeom.H:755
#define PUT_ARROW()
Definition eepicgeom.H:691
#define COMPUTE_SEGMENT_EEPIC_COORDENATES()
Definition eepicgeom.H:659
#define DRAW_ARROW_DASH_SEGMENT(sg, output)
Definition eepicgeom.H:792
#define DEFINE_EEPIC_POLYGON(Name)
Definition eepicgeom.H:1320
#define DEFINE_CLASS_DERIVATED_FROM_TEXT(Name)
Text wrappers.
Definition eepicgeom.H:1264
#define DRAW_SEGMENT(sg, output)
Definition eepicgeom.H:669
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_max_function > > max(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Definition gmpfrxx.h:4110
bool squarize
Definition graphpic.C:259
static mpfr_t y
Definition mpfr_mul_d.c:3
DynList< T > maps(const C &c, Op op)
Classic map operation.
STL namespace.
2D point and geometric utilities.
double geom_number_to_double(const Geom_Number &n)
Definition point.H:70
2D polygon representation and geometric operations.
Segment-drawing variants (types).
Definition eepicgeom.H:1205
Dynamic doubly linked list implementation.
Comprehensive sorting algorithms and search utilities for Aleph-w.
ofstream output
Definition writeHeap.C:213