Solve bug #23: Floating versus Integer Coordinates
authoralpar
Mon, 30 Jan 2006 09:37:41 +0000
changeset 193092b70deed0c5
parent 1929 84d87d6024af
child 1931 6abf67b02ff5
Solve bug #23: Floating versus Integer Coordinates

- BoundingBox values rounds to integer
- The generated .eps rescales if the bounding box were too small otherwise.
demo/graph_to_eps_demo.cc
lemon/graph_to_eps.h
     1.1 --- a/demo/graph_to_eps_demo.cc	Mon Jan 30 09:32:52 2006 +0000
     1.2 +++ b/demo/graph_to_eps_demo.cc	Mon Jan 30 09:37:41 2006 +0000
     1.3 @@ -79,7 +79,9 @@
     1.4    IdMap<ListGraph,Node> id(g);
     1.5  
     1.6    cout << "Create 'graph_to_eps_demo_out.eps'" << endl;
     1.7 -  graphToEps(g,"graph_to_eps_demo_out.eps").scale(10).coords(coords).
     1.8 +  graphToEps(g,"graph_to_eps_demo_out.eps").
     1.9 +    //scale(10).
    1.10 +    coords(coords).
    1.11      title("Sample .eps figure").
    1.12      copyright("(C) 2006 LEMON Project").
    1.13      nodeScale(2).nodeSizes(sizes).
    1.14 @@ -92,7 +94,8 @@
    1.15  
    1.16  
    1.17    cout << "Create 'graph_to_eps_demo_out_arr.eps'" << endl;
    1.18 -  graphToEps(g,"graph_to_eps_demo_out_arr.eps").scale(10).
    1.19 +  graphToEps(g,"graph_to_eps_demo_out_arr.eps").
    1.20 +    //scale(10).
    1.21      title("Sample .eps figure (with arrowheads)").
    1.22      copyright("(C) 2006 LEMON Project").
    1.23      nodeColors(composeMap(colorSet,colors)).
    1.24 @@ -117,7 +120,8 @@
    1.25    e=g.addEdge(n1,n2); ecolors[e]=7; widths[e]=1;
    1.26  
    1.27    cout << "Create 'graph_to_eps_demo_out_par.eps'" << endl;
    1.28 -  graphToEps(g,"graph_to_eps_demo_out_par.eps").scale(10).
    1.29 +  graphToEps(g,"graph_to_eps_demo_out_par.eps").
    1.30 +    //scale(10).
    1.31      title("Sample .eps figure (parallel edges)").
    1.32      copyright("(C) 2006 LEMON Project").
    1.33      nodeShapes(shapes).
    1.34 @@ -131,7 +135,8 @@
    1.35      run();
    1.36    
    1.37    cout << "Create 'graph_to_eps_demo_out_par_arr.eps'" << endl;
    1.38 -  graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").scale(10).
    1.39 +  graphToEps(g,"graph_to_eps_demo_out_par_arr.eps").
    1.40 +    //scale(10).
    1.41      title("Sample .eps figure (parallel edges and arrowheads)").
    1.42      copyright("(C) 2006 LEMON Project").
    1.43      nodeScale(2).nodeSizes(sizes).
    1.44 @@ -172,7 +177,8 @@
    1.45    }
    1.46    
    1.47    cout << "Create 'graph_to_eps_demo_out_colors.eps'" << endl;
    1.48 -  graphToEps(h,"graph_to_eps_demo_out_colors.eps").scale(60).
    1.49 +  graphToEps(h,"graph_to_eps_demo_out_colors.eps").
    1.50 +    //scale(60).
    1.51      title("Sample .eps figure (ColorSet demo)").
    1.52      copyright("(C) 2006 LEMON Project").
    1.53      coords(hcoords).
     2.1 --- a/lemon/graph_to_eps.h	Mon Jan 30 09:32:52 2006 +0000
     2.2 +++ b/lemon/graph_to_eps.h	Mon Jan 30 09:37:41 2006 +0000
     2.3 @@ -851,11 +851,17 @@
     2.4      
     2.5      if(_scaleToA4)
     2.6        os <<"%%BoundingBox: 0 0 596 842\n%%DocumentPaperSizes: a4\n";
     2.7 -    else os << "%%BoundingBox: "
     2.8 -	    << bb.left()   * _scale - _xBorder << ' '
     2.9 -	    << bb.bottom() * _scale - _yBorder << ' '
    2.10 -	    << bb.right()  * _scale + _xBorder << ' '
    2.11 -	    << bb.top()    * _scale + _yBorder << '\n';
    2.12 +    else {
    2.13 +      //Rescale so that BoundingBox won't be neither to big nor too small.
    2.14 +      while(bb.height()*_scale>1000||bb.width()*_scale>1000) _scale/=10;
    2.15 +      while(bb.height()*_scale<100||bb.width()*_scale<100) _scale*=10;
    2.16 +    
    2.17 +      os << "%%BoundingBox: "
    2.18 +	 << int(floor(bb.left()   * _scale - _xBorder)) << ' '
    2.19 +	 << int(floor(bb.bottom() * _scale - _yBorder)) << ' '
    2.20 +	 << int(ceil(bb.right()  * _scale + _xBorder)) << ' '
    2.21 +	 << int(ceil(bb.top()    * _scale + _yBorder)) << '\n';
    2.22 +    }
    2.23      
    2.24      os << "%%EndComments\n";
    2.25