Пример #1
0
 public void Add(Edge2D e)
 {
     if (!Contains(e))
     {
         edgeSet.Add(e);
     }
 }
Пример #2
0
        private void setColor(Edge2D e, int col)
        {
            int c;

            if (edgeColor.TryGetValue(e, out c))
            {
                edgeColor.Remove(e);
            }
            edgeColor.Add(e, col);
        }
Пример #3
0
        private int getColor(Edge2D e)
        {
            int col;

            if (edgeColor.TryGetValue(e, out col))
            {
                return(col);
            }
            return(-1);
        }
Пример #4
0
        public override object Clone()
        {
            Vertex2D v1 = (Vertex2D)V1.Clone();
            Vertex2D v2 = (Vertex2D)V2.Clone();

            Edge2D e = new Edge2D(v1, v2);

            e.extID = extID;

            return(e);
        }
Пример #5
0
        private List <Edge2D> Connected(Edge2D e, double prec)
        {
            List <Edge2D> lst = new List <Edge2D>();

            foreach (var e0 in edgeSet)
            {
                if (IsConnected(e, e0, prec))
                {
                    lst.Add(e0);
                }
            }
            return(lst);
        }
Пример #6
0
        private void Coloring(Edge2D e, double prec)
        {
            int           col = getColor(e);
            List <Edge2D> lst = Connected(e, prec);

            foreach (var ex in lst)
            {
                if (getColor(ex) != col)
                {
                    setColor(ex, col);
                    Coloring(ex, prec);
                }
            }
        }
Пример #7
0
        public double LinearCut(Edge2D e)
        {
            double x0 = e.V1.X;
            double y0 = e.V1.Y;

            double x1 = e.V2.X;
            double y1 = e.V2.Y;

            Func <double, double> Lin = (t) =>
            {
                Vertex2D v = e.Verteces2LinCut(t);
                return(Calc(v.X, v.Y));
            };

            return(Dihotomy(Lin, 0.0, 1.0, 1e-3));
        }
Пример #8
0
        private Edge2D AddEdgeIfNotExist(Vertex2D v1, Vertex2D v2)
        {
            Edge2D e1 = _edge.Find(item => (item.V1.ID == v1.ID) & (item.V2.ID == v2.ID));
            Edge2D e2 = _edge.Find(item => (item.V1.ID == v2.ID) & (item.V2.ID == v1.ID));

            if (e1 != null)
            {
                return(e1);
            }

            if (e2 != null)
            {
                return(e2);
            }

            Edge2D e = new Edge2D(v1, v2);

            _edge.Add(e);
            return(e);
        }
Пример #9
0
        private bool IsConnected(Edge2D e1, Edge2D e2, double prec)
        {
            if (e1 == e2)
            {
                return(false);
            }

            Func <Vertex2D, Vertex2D, double> SqrDist = (V1, V2) =>
            {
                double dx = V2.X - V1.X;
                double dy = V2.Y - V1.Y;
                return(dx * dx + dy * dy);
            };

            double prec2 = prec * prec;

            if (SqrDist(e1.V1, e2.V1) < prec2)
            {
                return(true);
            }

            if (SqrDist(e1.V2, e2.V2) < prec2)
            {
                return(true);
            }

            if (SqrDist(e1.V1, e2.V2) < prec2)
            {
                return(true);
            }

            if (SqrDist(e1.V2, e2.V1) < prec2)
            {
                return(true);
            }

            return(false);
        }
Пример #10
0
        public void Coloring()
        {
            double prec = 0.0;

            foreach (var e in edgeSet)
            {
                prec += e.Length();
            }
            prec /= edgeSet.Count;
            prec /= 100.0;

            while (true)
            {
                Edge2D e = firstUnColored();
                if (e == null)
                {
                    return;
                }
                int col = nextColor();
                setColor(e, col);
                Coloring(e, prec);
            }
        }
Пример #11
0
        public void CutLine(Triangle2D triangle, CurveLine curve, bool CalcAreaRelations)
        {
            double t1 = curve.LinearCut(triangle.E1);
            double t2 = curve.LinearCut(triangle.E2);
            double t3 = curve.LinearCut(triangle.E3);

            if (!double.IsNaN(t1))
            {
                T1 = t1;
            }
            if (!double.IsNaN(t2))
            {
                T2 = t2;
            }
            if (!double.IsNaN(t3))
            {
                T3 = t3;
            }

            if ((T1 > 0.0) & (T2 > 0.0))
            {
                Vertex2D v1 = triangle.E1.Verteces2LinCut(T1);
                Vertex2D v2 = triangle.E2.Verteces2LinCut(T2);
                Cut = new Edge2D(v1, v2);
            }

            if ((T2 > 0.0) & (T3 > 0.0))
            {
                Vertex2D v2 = triangle.E2.Verteces2LinCut(T2);
                Vertex2D v3 = triangle.E3.Verteces2LinCut(T3);
                Cut = new Edge2D(v2, v3);
            }
            if ((T3 > 0.0) & (T1 > 0.0))
            {
                Vertex2D v3 = triangle.E3.Verteces2LinCut(T3);
                Vertex2D v1 = triangle.E1.Verteces2LinCut(T1);
                Cut = new Edge2D(v3, v1);
            }

            if (T1 == 0.0)
            {
                Vertex2D v2 = triangle.E2.Verteces2LinCut(T2);
                Vertex2D v0 = (Vertex2D)triangle.V1.Clone();
                Cut = new Edge2D(v2, v0);
            }
            if (T2 == 0.0)
            {
                Vertex2D v3 = triangle.E3.Verteces2LinCut(T3);
                Vertex2D v0 = (Vertex2D)triangle.V2.Clone();
                Cut = new Edge2D(v3, v0);
            }
            if (T3 == 0.0)
            {
                Vertex2D v1 = triangle.E1.Verteces2LinCut(T1);
                Vertex2D v0 = (Vertex2D)triangle.V3.Clone();
                Cut = new Edge2D(v1, v0);
            }

            if (CalcAreaRelations)
            {
                AreaRelationCalculate(triangle, curve);
            }
        }
Пример #12
0
 public ElementCutParameters()
 {
     Cut = null;
 }
Пример #13
0
 private bool Contains(Edge2D e)
 {
     return(edgeSet.Contains(e));
 }