예제 #1
0
 public VectorPath(VectorPath vp)
 {
     list = new List <Vector>(vp.list.Count);
     for (int i = 0; i < vp.list.Count; i++)
     {
         list.Add(vp.list[i]);
     }
 }
예제 #2
0
            private void findPath(int from, int to, List <VectorLine> lines, List <VectorPath> vp)
            {
                VectorPath tp     = new VectorPath();
                List <int> startl = new List <int>();

                tp.addPoint(lines[from].A);
                startl.Add(from);
                tracePath(from, to, lines, vp, tp, startl);
            }
예제 #3
0
            private void tracePath(int from, int to, List <VectorLine> lines, List <VectorPath> vp, VectorPath start, List <int> startl)
            {
                if (from == to)
                {
                    // On the final line
                    VectorPath ep = new VectorPath(start);
                    ep.addPoint(lines[to].B);
                    vp.Add(ep);
                    return;
                }

                // Check for intersections
                for (int i = 0; i < lines.Count; i++)
                {
                    if ((i != from) && (startl.IndexOf(i) < 0))
                    {
                        Vector ip = Vector.Zero;
                        if (VectorLine.intersect(lines[from], lines[i], ref ip))
                        {
                            // Lines intersect!
                            bool isavalidline = true;
                            if (isavalidline && (startl.Count > 1) && _VA.nonZero && _VA.inside(ip))
                            {
                                isavalidline = false;
                            }
                            if (isavalidline && _VB.nonZero && _VB.inside(ip))
                            {
                                isavalidline = false;
                            }
                            VectorLine nl = new VectorLine(start.list.Last(), ip, VectorLine.LineType.AB);
                            if (isavalidline && (startl.Count > 1) && _VA.nonZero && _VA.Intersects(nl))
                            {
                                isavalidline = false;
                            }
                            if (isavalidline && _VB.nonZero && _VB.Intersects(nl))
                            {
                                isavalidline = false;
                            }
                            if (isavalidline)
                            {
                                VectorPath ep      = new VectorPath(start);
                                List <int> startlx = new List <int>(startl);
                                startlx.Add(i);
                                ep.addPoint(ip);
                                tracePath(i, to, lines, vp, ep, startlx);
                            }
                        }
                    }
                }
            }
예제 #4
0
 private void fallback()
 {
     if (_A == _B)
     {
         return;           // This is no line
     }
     pointlist = new VectorPath();
     pointlist.addPoint(_A);
     if (_Adir.nonZero)
     {
         pointlist.addPoint(_A + _Adir * _stdgapA);
     }
     if (_Bdir.nonZero)
     {
         pointlist.addPoint(_B + _Bdir * _stdgapB);
     }
     pointlist.addPoint(_B);
     valid = true;
 }
예제 #5
0
            private void calcConnection(Graphics g, Pen q)
            {
                try
                {
                    if (_A == _B)
                    {
                        return;           // No Line
                    }

                    /*
                     * VectorLine LA = new VectorLine(new Vector(0, 20), new Vector(10, 20), VectorLine.LineType.Infinite);
                     * VectorLine LB = new VectorLine(new Vector(10, 0), new Vector(10, 50), VectorLine.LineType.Infinite);
                     * Vector ip = Vector.Zero;
                     * VectorLine.intersect(LA, LB, ref ip);
                     */

                    List <VectorLine> vl = new List <VectorLine>();
                    int[]             sp;
                    int[]             ep;
                    if (_Adir.isZero)
                    {
                        sp = new int[4] {
                            vl.Count, vl.Count + 1, vl.Count + 2, vl.Count + 3
                        };
                        vl.Add(new VectorLine(_A, _A + Vector.X, VectorLine.LineType.AInf));
                        vl.Add(new VectorLine(_A, _A - Vector.X, VectorLine.LineType.AInf));
                        vl.Add(new VectorLine(_A, _A + Vector.Y, VectorLine.LineType.AInf));
                        vl.Add(new VectorLine(_A, _A - Vector.Y, VectorLine.LineType.AInf));
                    }
                    else
                    {
                        Vector p = _A + _Adir * _stdgapA;
                        sp = new int[1] {
                            vl.Count
                        };
                        vl.Add(new VectorLine(_A, p, VectorLine.LineType.AInf));
                        //vl.Add(new VectorLine(p, p + _Adir, VectorLine.LineType.AInf));
                        //vl.Add(new VectorLine(p, p + _Adir.vrot90(), VectorLine.LineType.AInf));
                        //vl.Add(new VectorLine(p, p + _Adir.vrot270(), VectorLine.LineType.AInf));
                    }
                    if (_Bdir.isZero)
                    {
                        ep = new int[4] {
                            vl.Count, vl.Count + 1, vl.Count + 2, vl.Count + 3
                        };
                        vl.Add(new VectorLine(_B - Vector.X, _B, VectorLine.LineType.InfB));
                        vl.Add(new VectorLine(_B - Vector.X, _B, VectorLine.LineType.InfB));
                        vl.Add(new VectorLine(_B - Vector.Y, _B, VectorLine.LineType.InfB));
                        vl.Add(new VectorLine(_B - Vector.Y, _B, VectorLine.LineType.InfB));
                    }
                    else
                    {
                        Vector p = _B + _Bdir * _stdgapB;
                        ep = new int[1] {
                            vl.Count
                        };
                        vl.Add(new VectorLine(p, _B, VectorLine.LineType.InfB));
                        //vl.Add(new VectorLine(p, p + _Bdir, VectorLine.LineType.AInf));
                        //vl.Add(new VectorLine(p, p + _Bdir.vrot90(), VectorLine.LineType.AInf));
                        //vl.Add(new VectorLine(p, p + _Bdir.vrot270(), VectorLine.LineType.AInf));
                    }
                    if (_VA.nonZero)
                    {
                        // Add four Lines surrounding the rectangle
                        vl.Add(_VA.LineAbove(_stdgapA));
                        vl.Add(_VA.LineBelow(_stdgapA));
                        vl.Add(_VA.LineLeft(_stdgapA));
                        vl.Add(_VA.LineRight(_stdgapA));
                    }
                    if (_VB.nonZero && (_VB == _VA))
                    {
                        _VB = new VectorRect();
                    }
                    if (_VB.nonZero)
                    {
                        // Add four Lines surrounding the rectangle
                        vl.Add(_VB.LineAbove(_stdgapB));
                        vl.Add(_VB.LineBelow(_stdgapB));
                        vl.Add(_VB.LineLeft(_stdgapB));
                        vl.Add(_VB.LineRight(_stdgapB));
                    }

                    /*
                     * for (int i=0;i<vl.Count;i++)
                     * {
                     *  vl[i].draw(g, q);
                     * }
                     * for (int i=0;i<vl.Count-1;i++)
                     *  for (int j=i+1;j<vl.Count;j++)
                     *  {
                     *      Vector vi = Vector.Zero;
                     *      if (VectorLine.intersect(vl[i],vl[j],ref vi))
                     *      {
                     *          g.DrawEllipse(q, VectorRect.FromCenterSize(vi, Vector.V(6, 6)).rectangle);
                     *      }
                     *  }
                     */

                    VectorPath vp = findPath(sp, ep, vl);
                    if (vp != null)
                    {
                        pointlist = vp;
                        valid     = true;
                    }
                    else
                    {
                        fallback();
                    }
                }
                catch (Exception e)
                {
                    fallback();
                }
            }