Back to index

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