Back to index

wims  3.65+svn20090927
CircleIntersectionObject.java
Go to the documentation of this file.
00001 package rene.zirkel.objects;
00002 
00003 // file: CircleIntersectionObject.java
00004 
00005 import rene.util.xml.*;
00006 import rene.zirkel.construction.*;
00007 import rene.zirkel.structures.*;
00008 
00009 public class CircleIntersectionObject extends IntersectionObject
00010 {      public CircleIntersectionObject (
00011               Construction c, PrimitiveCircleObject P1, PrimitiveCircleObject P2,
00012               boolean first)
00013        {      super(c,P1,P2);
00014               First=first;
00015               validate();
00016        }
00017 
00018        public void updateCircleDep ()
00019        {      ((PrimitiveCircleObject)P1).addDep(this);
00020               ((PrimitiveCircleObject)P2).addDep(this);
00021        }
00022 
00023        public void validate ()
00024        {      boolean oldvalid=Valid;
00025               if (!P1.valid() || !P2.valid()) Valid=false;
00026               else Valid=true; 
00027               if (!Valid) return;
00028               Coordinates c=PrimitiveCircleObject.intersect(
00029                      (PrimitiveCircleObject)P1,(PrimitiveCircleObject)P2);
00030               if (c==null)
00031               {      if (oldvalid && getConstruction().shouldSwitch())
00032                      {      doSwitch();
00033                             if (!getConstruction().noteSwitch()) Switched=false;
00034                      }
00035                      else if (oldvalid && Alternate && Away==null && getConstruction().canAlternate())
00036                      {      First=!First;
00037                      }
00038                      Valid=false; return; 
00039               }
00040               PointObject oa=getAway();
00041               if (oa!=null)
00042               {      double x=oa.getX(),y=oa.getY();
00043                      double r=(x-c.X)*(x-c.X)+(y-c.Y)*(y-c.Y);
00044                      double r1=(x-c.X1)*(x-c.X1)+(y-c.Y1)*(y-c.Y1);
00045                      boolean flag=(r>r1);
00046                      if (!StayAway) flag=!flag;
00047                      if (flag)
00048                      {      X=c.X; Y=c.Y;
00049                      }
00050                      else
00051                      {      X=c.X1; Y=c.Y1;
00052                      }
00053               }
00054               else
00055               {      if (First) { X=c.X; Y=c.Y; }
00056                      else { X=c.X1; Y=c.Y1; }
00057               }
00058               if (Restricted)
00059               {      if (!(((PrimitiveCircleObject)P1).getStart()==this ||
00060                             ((PrimitiveCircleObject)P1).getEnd()==this) &&
00061                             !((PrimitiveCircleObject)P1).contains(X,Y)) Valid=false;
00062                      if (!(((PrimitiveCircleObject)P2).getStart()==this ||
00063                                    ((PrimitiveCircleObject)P2).getEnd()==this) &&
00064                             !((PrimitiveCircleObject)P2).contains(X,Y)) Valid=false;
00065               }
00066        }
00067 
00068        public void printArgs (XmlWriter xml)
00069        {      super.printArgs(xml);
00070               if (First) xml.printArg("which","first");
00071               else xml.printArg("which","second");
00072        }
00073 
00074        public boolean isSwitchable ()
00075        {      return true;
00076        }
00077 
00078        public boolean canAlternate ()
00079        {      return true;
00080        }
00081 }