src/lemon/graph_to_eps.h
changeset 1088 358526a620f8
parent 1087 d496d1d5a5e7
child 1089 c0f4ebdc0034
equal deleted inserted replaced
3:57da56ad0e00 4:aa33833ed638
   155 
   155 
   156   static const int INTERPOL_PREC=20;
   156   static const int INTERPOL_PREC=20;
   157 
   157 
   158   bool dontPrint;
   158   bool dontPrint;
   159 
   159 
   160   enum NodeShapes { CIRCLE=0, SQUARE=1 };
   160   enum NodeShapes { CIRCLE=0, SQUARE=1, DIAMOND=2 };
   161 		   
   161 		   
   162   class edgeLess {
   162   class edgeLess {
   163     const Graph &g;
   163     const Graph &g;
   164   public:
   164   public:
   165     edgeLess(const Graph &_g) : g(_g) {}
   165     edgeLess(const Graph &_g) : g(_g) {}
   412     switch(t) {
   412     switch(t) {
   413     case CIRCLE:
   413     case CIRCLE:
   414       return p.normSquare()<=r*r;
   414       return p.normSquare()<=r*r;
   415     case SQUARE:
   415     case SQUARE:
   416       return p.x<=r&&p.x>=-r&&p.y<=r&&p.y>=-r;
   416       return p.x<=r&&p.x>=-r&&p.y<=r&&p.y>=-r;
       
   417     case DIAMOND:
       
   418       return p.x+p.y<=r && p.x-p.y<=r && -p.x+p.y<=r && -p.x-p.y<=r;
   417     }
   419     }
   418     return false;
   420     return false;
   419   }
   421   }
   420 
   422 
   421 public:
   423 public:
   447     os << "/sq { newpath 2 index 1 index add 2 index 2 index add moveto\n"
   449     os << "/sq { newpath 2 index 1 index add 2 index 2 index add moveto\n"
   448        << "      2 index 1 index sub 2 index 2 index add lineto\n"
   450        << "      2 index 1 index sub 2 index 2 index add lineto\n"
   449        << "      2 index 1 index sub 2 index 2 index sub lineto\n"
   451        << "      2 index 1 index sub 2 index 2 index sub lineto\n"
   450        << "      2 index 1 index add 2 index 2 index sub lineto\n"
   452        << "      2 index 1 index add 2 index 2 index sub lineto\n"
   451        << "      closepath pop pop pop} bind def\n";
   453        << "      closepath pop pop pop} bind def\n";
       
   454     //x y r
       
   455     os << "/di { newpath 2 index 1 index add 2 index moveto\n"
       
   456        << "      2 index             2 index 2 index add lineto\n"
       
   457        << "      2 index 1 index sub 2 index             lineto\n"
       
   458        << "      2 index             2 index 2 index sub lineto\n"
       
   459        << "      closepath pop pop pop} bind def\n";
   452     // x y r cr cg cb
   460     // x y r cr cg cb
   453     os << "/nc { setrgbcolor 2 index 2 index 2 index c fill\n"
   461     os << "/nc { setrgbcolor 2 index 2 index 2 index c fill\n"
   454        << "     0 0 0 setrgbcolor dup "
   462        << "     0 0 0 setrgbcolor dup "
   455        << _nodeBorderQuotient << " mul setlinewidth "
   463        << _nodeBorderQuotient << " mul setlinewidth "
   456        << 1+_nodeBorderQuotient/2 << " div c stroke\n"
   464        << 1+_nodeBorderQuotient/2 << " div c stroke\n"
   457        << "   } bind def\n";
   465        << "   } bind def\n";
   458     os << "/nsq { setrgbcolor 2 index 2 index 2 index sq fill\n"
   466     os << "/nsq { setrgbcolor 2 index 2 index 2 index sq fill\n"
   459        << "     0 0 0 setrgbcolor dup "
   467        << "     0 0 0 setrgbcolor dup "
   460        << _nodeBorderQuotient << " mul setlinewidth "
   468        << _nodeBorderQuotient << " mul setlinewidth "
   461        << 1+_nodeBorderQuotient/2 << " div sq stroke\n"
   469        << 1+_nodeBorderQuotient/2 << " div sq stroke\n"
       
   470        << "   } bind def\n";
       
   471     os << "/ndi { setrgbcolor 2 index 2 index 2 index di fill\n"
       
   472        << "     0 0 0 setrgbcolor dup "
       
   473        << _nodeBorderQuotient << " mul setlinewidth "
       
   474        << 1+_nodeBorderQuotient/2 << " div di stroke\n"
   462        << "   } bind def\n";
   475        << "   } bind def\n";
   463     os << "/arrl " << _arrowLength << " def\n";
   476     os << "/arrl " << _arrowLength << " def\n";
   464     os << "/arrw " << _arrowWidth << " def\n";
   477     os << "/arrw " << _arrowWidth << " def\n";
   465     // l dx_norm dy_norm
   478     // l dx_norm dy_norm
   466     os << "/lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def\n";
   479     os << "/lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def\n";
   617 	switch(_nodeShapes[n]) {
   630 	switch(_nodeShapes[n]) {
   618 	case CIRCLE:
   631 	case CIRCLE:
   619 	  os<< "nc";break;
   632 	  os<< "nc";break;
   620 	case SQUARE:
   633 	case SQUARE:
   621 	  os<< "nsq";break;
   634 	  os<< "nsq";break;
       
   635 	case DIAMOND:
       
   636 	  os<< "ndi";break;
   622 	}
   637 	}
   623 	os<<'\n';
   638 	os<<'\n';
   624       }
   639       }
   625       os << "grestore\n";
   640       os << "grestore\n";
   626     }
   641     }