1 /* { dg-do compile } */
2 /* { dg-options "-O2 -ftree-tail-merge" } */
3 typedef int BoxCoordinate;
4 typedef int BoxDimension;
5 const BoxDimension X = 0;
6 const BoxDimension Y = 1;
7 const BoxDimension NDimensions = 2;
9 BoxCoordinate point[NDimensions];
12 void operator += (const BoxPoint& p) {
13 if (isValid() && p.isValid()) {
14 point[X] += p.point[X];
17 const BoxCoordinate& operator [] (const BoxDimension& dimension) const {
18 return point[dimension];
23 BoxCoordinate& origin(BoxDimension d) const;
24 BoxCoordinate& space(BoxDimension d) const;
26 inline bool operator <= (const BoxPoint& p, const BoxRegion& r) {
27 for (BoxDimension d = X;
29 d++) if (p[d] < r.origin(d) || p[d] >= r.origin(d) + r.space(d))
33 typedef struct _WidgetRec *Widget;
35 BoxPoint offsetIfSelected;
40 GraphNode *from() const;
41 GraphNode *to() const;
43 class LineGraphEdge: public GraphEdge {
45 virtual void drawLine(Widget w, const GraphGC& gc) const;
46 void _print(const GraphGC &gc) const;
48 class ArcGraphEdge: public LineGraphEdge {
49 static bool center(const BoxPoint& p1, const BoxPoint& p2,
50 const BoxPoint& p3, double& x, double& y);
51 void makeLine(Widget w, const GraphGC& gc) const;
56 GraphEdge *firstTo() const;
57 GraphEdge *nextTo(GraphEdge *ref) const;
58 virtual const BoxPoint& pos() const = 0;
59 virtual const BoxRegion& region(const GraphGC& gc) const = 0;
60 virtual bool isHint() const;
62 class PosGraphNode: public GraphNode { };
63 class RegionGraphNode: public PosGraphNode { };
64 class HintGraphNode: public RegionGraphNode { };
65 void ArcGraphEdge::makeLine(Widget w, const GraphGC& gc) const {
66 HintGraphNode *arc_hint = 0;
67 RegionGraphNode *arc_from = 0;
68 RegionGraphNode *arc_to = 0;
70 if (from()->isHint() && to()->isHint()) {
73 else if (from()->isHint() && from()->firstTo() != 0) {
74 if (arc_hint == 0 || arc_from == 0 || arc_to == 0
75 || arc_hint->nextTo(arc_hint->firstTo()) != 0) {
80 if (w != 0) LineGraphEdge::drawLine(w, gc);
81 else LineGraphEdge::_print(gc);
84 BoxPoint pos_from = arc_from->pos();
85 BoxRegion region_from = arc_from->region(gc);
86 BoxPoint pos_to = arc_to->pos();
87 BoxRegion region_to = arc_to->region(gc);
88 BoxPoint pos_hint = arc_hint->pos();
89 if (arc_hint->selected()) {
90 pos_hint += gc.offsetIfSelected;
92 if (pos_hint <= region_from || pos_hint <= region_to) {
96 bool ok = center(pos_from, pos_hint, pos_to, cx, cy);
98 if (w != 0) LineGraphEdge::drawLine(w, gc);
99 else LineGraphEdge::_print(gc);