Generated on Thu Mar 6 14:51:43 2008 for Gecode/J by doxygen 1.5.4

Diamond.java

Go to the documentation of this file.
00001 /* -*- indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Guido Tack, 2006
00008  *
00009  *  Last modified:
00010  *     $Date: 2006-02-09 16:32:56 +0100 (Thu, 09 Feb 2006) $ by $Author: tack $
00011  *     $Revision: 2943 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 package org.gecode.gist.postscript;
00039 
00040 import java.io.Writer;
00041 import java.io.IOException;
00042 
00043 public class Diamond extends Path {
00044     private int cx, cy, r;
00045     private PSColor outline;
00046     private PSColor fill;
00047 
00048     public Diamond(int cx0, int cy0, int r0,
00049                    PSColor outline0, PSColor fill0) {
00050         cx = cx0;
00051         cy = cy0;
00052         r = r0;
00053         outline = outline0;
00054         fill = fill0;
00055     }
00056 
00057     void emit(Writer out) throws IOException {
00058         double c1x = (double) cx;
00059         double c1y = (double) cy;
00060         double c2x = c1x + (double) r;
00061         double c2y = c1y + (double) r;
00062         double c3x = c1x;
00063         double c3y = c1y + (double) (2*r);
00064         double c4x = c1x - (double) r;
00065         double c4y = c2y;
00066 
00067         out.write("gsave\n");
00068         out.write(c1x+" "+c1y+" moveto "+c2x+" "+c2y+" lineto ");
00069         out.write(c3x+" "+c3y+" lineto "+c4x+" "+c4y+" lineto ");
00070         out.write(c1x+" "+c1y+" lineto\n");
00071         out.write(fill.r+" "+fill.g+" "+fill.b+" setrgbcolor\n");
00072         out.write("eofill\n");
00073         out.write(c1x+" "+c1y+" moveto "+c2x+" "+c2y+" lineto ");
00074         out.write(c3x+" "+c3y+" lineto "+c4x+" "+c4y+" lineto ");
00075         out.write(c1x+" "+c1y+" lineto\n");
00076         out.write("1 setlinejoin 1 setlinecap\n");
00077         out.write("1 setlinewidth\n");
00078         out.write("[] 0 setdash\n");
00079         out.write(outline.r+" "+outline.g+" "+outline.b+" setrgbcolor\n");
00080         out.write("stroke\n");
00081         out.write("grestore\n");
00082     }
00083 
00084     BoundingBox bb() {
00085         return new BoundingBox(cx-r,cx+r,cy-r,cy+r);
00086     }
00087 }