Esempio n. 1
0
        void SplitSegment(Segment2D s)
        {
            Vertex2D a = s.a, b = s.b;
            var      mv = new Vertex2D(s.Midpoint());

            // add mv to V
            // the index is between a and b.
            var idxA = V.IndexOf(a);
            var idxB = V.IndexOf(b);

            if (Mathf.Abs(idxA - idxB) == 1)
            {
                var idx = (idxA > idxB) ? idxA : idxB;
                V.Insert(idx, mv);
            }
            else
            {
                V.Add(mv);
            }

            UpdateTriangulation(mv.Coordinate);

            // Add two halves to S
            var sidx = S.IndexOf(s);

            S.RemoveAt(sidx);

            S.Add(new Segment2D(s.a, mv));
            S.Add(new Segment2D(mv, s.b));
        }
Esempio n. 2
0
 public bool ContainsInExternalCircle(Vertex2D v)
 {
     if (circum == null)
     {
         circum = Circle2D.GetCircumscribedCircle(this);
     }
     return(circum.Contains(v.Coordinate));
 }
Esempio n. 3
0
 public Triangle2D(Segment2D s0, Segment2D s1, Segment2D s2)
 {
     this.s0 = s0;
     this.s1 = s1;
     this.s2 = s2;
     this.a  = s0.a;
     this.b  = s0.b;
     this.c  = (s2.b == this.a || s2.b == this.b) ? s2.a : s2.b;
 }
Esempio n. 4
0
        public Triangle2D AddTriangle(Vertex2D a, Vertex2D b, Vertex2D c)
        {
            var s0 = CheckAndAddSegment(a, b);
            var s1 = CheckAndAddSegment(b, c);
            var s2 = CheckAndAddSegment(c, a);
            var t  = new Triangle2D(s0, s1, s2);

            T.Add(t);
            return(t);
        }
Esempio n. 5
0
 public Segment2D CommonSegment(Vertex2D v0, Vertex2D v1)
 {
     if (s0.HasPoint(v0) && s0.HasPoint(v1))
     {
         return(s0);
     }
     else if (s1.HasPoint(v0) && s1.HasPoint(v1))
     {
         return(s1);
     }
     return(s2);
 }
Esempio n. 6
0
 public Segment2D[] CommonSegments(Vertex2D v)
 {
     if (s0.HasPoint(v) && s1.HasPoint(v))
     {
         return(new [] { s0, s1 });
     }
     else if (s1.HasPoint(v) && s2.HasPoint(v))
     {
         return(new [] { s1, s2 });
     }
     return(new [] { s0, s2 });
 }
Esempio n. 7
0
        public Vertex2D CheckAndAddVertex(Vector2 coord)
        {
            var idx = FindVertex(coord, P);

            if (idx < 0)
            {
                var v = new Vertex2D(coord);
                P.Add(v);
                return(v);
            }
            return(P[idx]);
        }
Esempio n. 8
0
        public Segment2D CheckAndAddSegment(Vertex2D a, Vertex2D b)
        {
            var       idx = FindSegment(a, b, E);
            Segment2D s;

            if (idx < 0)
            {
                s = new Segment2D(a, b);
                E.Add(s);
            }
            else
            {
                s = E[idx];
            }
            s.Increment();
            return(s);
        }
Esempio n. 9
0
 public bool HasPoint(Vertex2D v)
 {
     return((a == v) || (b == v));
 }
Esempio n. 10
0
 public Segment2D(Vertex2D a, Vertex2D b)
 {
     this.a = a;
     this.b = b;
 }
Esempio n. 11
0
 public static bool CheckEqual(Vertex2D v0, Vertex2D v1)
 {
     return(v0.Coordinate == v1.Coordinate);
 }
Esempio n. 12
0
 public bool HasPoint(Vertex2D p)
 {
     return((a == p) || (b == p) || (c == p));
 }
Esempio n. 13
0
 public float Distance(Vertex2D v)
 {
     return(Distance(v.Coordinate));
 }
Esempio n. 14
0
 public bool On(Vertex2D v)
 {
     return(On(v.Coordinate));
 }
Esempio n. 15
0
 int FindSegment(Vertex2D a, Vertex2D b, List <Segment2D> Segments)
 {
     return(Segments.FindIndex(s => (s.a == a && s.b == b) || (s.a == b && s.b == a)));
 }