Back to index

wims  3.65+svn20090927
PolygonFiller.java
Go to the documentation of this file.
00001 /*
00002  * Created on 06.11.2005
00003  *
00004  */
00005 package rene.zirkel.graphics;
00006 
00007 import rene.zirkel.objects.ConstructionObject;
00008 
00013 public class PolygonFiller
00014 {      MyGraphics G;
00015        ConstructionObject O;
00016        double C,R;
00017        double C1,R1;
00018        boolean HaveToFinish;
00019        public static int step=5;
00020        public boolean Started;
00021        boolean Solid;
00022        
00023        double x[],y[];
00024        int nx;
00025        
00026        public PolygonFiller (MyGraphics g, ConstructionObject o)
00027        {      G=g; O=o;
00028               Started=false;
00029        }
00030        
00031        public void startPolygon (double c, double r)
00032        {      C=c; R=r;
00033               HaveToFinish=false;
00034               nx=0;
00035               Started=true;
00036               drawTo(c,r,false);
00037        }
00038        
00039        public void start ()
00040        {      nx=0; Started=false;
00041        }
00042        
00043        public void drawTo (double c, double r)
00044        {      drawTo(c,r,true);
00045        }
00046        
00047        public void drawTo (double c, double r, boolean optimized)
00048        {      if (!Started)
00049               {      startPolygon(c,r);
00050                      return;
00051               }
00052               if (!optimized || (c-C)*(c-C)+(r-R)*(r-R)>step)
00053               {      if (x==null)
00054                      {      x=new double[1000];
00055                             y=new double[1000];
00056                             nx=0;
00057                      }
00058                      if (nx>=x.length)
00059                      {      double xn[]=new double[2*x.length]; 
00060                             double yn[]=new double[2*x.length];
00061                             for (int i=0; i<nx; i++)
00062                             {      xn[i]=x[i]; yn[i]=y[i]; 
00063                             }
00064                             x=xn; y=yn;
00065                      }
00066                      x[nx]=c; y[nx++]=r;
00067                      C=c; R=r;
00068                      HaveToFinish=false;
00069               }
00070               else
00071               {      C1=c; R1=r;
00072                      HaveToFinish=true;
00073               }
00074        }
00075        
00076        public void finishPolygon ()
00077        {      if (HaveToFinish)
00078               {      drawTo(C1,R1,false);
00079                      HaveToFinish=false;
00080               }
00081               G.fillPolygon(x,y,nx,false,true,O);
00082               Started=false;
00083        }
00084        
00085        public int length ()
00086        {      return nx;
00087        }
00088        
00089        public double x (int i)
00090        {      return x[i];
00091        }
00092        public double y (int i)
00093        {      return y[i];
00094        }
00095 
00096        public void setGraphics (MyGraphics g)
00097        {      G=g;
00098        }
00099 }
00100