Пример #1
0
        /// <summary>
        /// Generate a CurveArray by eliminating all cross points of the given Array and inserting
        /// new curves.
        /// </summary>
        /// <returns>CurveArray</returns>
        public CurveArray ToNetWork()
        {
            CurveArray result = new CurveArray();
            CrossList  CL     = getCrossList(this, true);
            int        k      = 0;

            for (int i = 0; i < CL.Count; i++)
            {
                CrossItem CI = CL[i];
                while (k < Utils.trunc(CI.Param1))
                {
                    Curve C = this[k];
                    result.Add(C.Clone());
                    k++;
                }
                double From = 0;
                while (k == Utils.trunc(CI.Param1))
                {
                    double Param = CI.Param1;
                    Param = System.Math.Round(Param, 8);
                    if (System.Math.Abs(From - Param - k) > 0.00001)
                    {
                        Curve C = this[k].Clone();
                        C.Slice(From, Param - k);
                        result.Add(C);
                    }
                    From = CI.Param1 - k;
                    if ((i + 1 < CL.Count) && (Utils.trunc(CL[i + 1].Param1) == k))
                    {
                        i++;
                        CI = CL[i];
                    }
                    else
                    {
                        if (System.Math.Abs(System.Math.Round(From, 8) - 1) > 0.00001)
                        {
                            Curve C1 = this[k].Clone();

                            double F = System.Math.Round(From, 8);
                            C1.Slice(F, 1);
                            result.Add(C1);
                        }
                        break;
                    }
                }
                k++;
            }

            while (k < Count)
            {
                Curve C = this[k];
                result.Add(C.Clone());
                k++;
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// Inserts a <see cref="CrossItem"/> to the CrossList and overrides the standard method
        /// </summary>
        public override void Insert(int index, object value)
        {
            CrossItem c = (CrossItem)value;

            c.CrossList = this;
            int i = 0;

            while ((i < Count) && (this[i].Param1 < c.Param1))
            {
                i++;
            }

            base.Insert(i, value);
        }
Пример #3
0
        /// <summary>
        /// Get a <see cref="CrossList"/>, which contains the crossing points with
        /// another curve?. The parameter param1 and param2 in <see cref="CrossItem"/> are converted to
        /// a curve parameter.
        /// </summary>
        /// <param name="Curve"></param>
        /// <returns></returns>
        public CrossList GetCrossList(Curve Curve)
        {
            xyArray xyArray1 = new xyArray(this.Resolution + 1);
            xyArray xyArray2 = new xyArray(Curve.Resolution + 1);

            this.ToArray(xyArray1, 0);
            Curve.ToArray(xyArray2, 0);
            CrossList Result = xyArray1.getCrossList(xyArray2, true);

            for (int i = 0; i < Result.Count; i++)
            {
                CrossItem C = Result[i];
                C.Param1 = C.Param1 / this.Resolution;
                C.Param2 = C.Param2 / Curve.Resolution;
            }
            return(Result);
        }
Пример #4
0
        /// <summary>
        /// Calucalates a <see cref="CrossList"/> for this CurveArray with an other <see cref="Loca"/>.
        /// The CrossItemparameter <see cref="CrossItem.Param1"/> is relative to this CurveArray.
        /// <br/>
        /// The parameter <see cref="CrossItem.Param2"/>  relative to the "value"-Loca.
        /// If (<see cref="CrossItem.Param2"/> greater Loca[0].Count the take id =<see cref="CrossItem.Param2"/> - Loca[0].count,
        /// If (<see cref="CrossItem.Param2"/> greater Loca[1].Count the take id =<see cref="CrossItem.Param2"/> - Loca[1].count,
        /// and so on.
        /// </summary>
        /// <param name="value">A Loca</param>
        /// <param name="TangentialPoints">Respect curves, who are tangential an intersection.</param>
        /// <returns>A CrossList</returns>
        public CrossList getCrossList(Loca value, bool TangentialPoints)
        {
            CrossList Result = new CrossList();
            int       ct     = 0;

            for (int i = 0; i < value.Count; i++)
            {
                CrossList CL = getCrossList(value[i], TangentialPoints);
                for (int j = 0; j < CL.Count; j++)
                {
                    CrossItem CI = CL[j];
                    CI.Param2 = CI.Param2 + ct;
                    Result.Add(CI);
                    CI.CrossList = CL;
                }
                ct += value[i].Count;
            }

            return(Result);
        }
Пример #5
0
        static void ToSortedParams(List <CrossItem> SortedParams, CrossItem CP)
        {
            int id = -1;

            for (int i = 0; i < SortedParams.Count; i++)
            {
                if (SortedParams[i].Param2 >= CP.Param2)
                {
                    id = i;
                    break;
                }
            }
            if (id < 0)
            {
                SortedParams.Add(CP);
            }
            else
            {
                SortedParams.Insert(id, CP);
            }
        }
Пример #6
0
        /// <summary>
        /// It`s the same as the overloaded method, but you can set, whether Tangential points
        /// should be taken or not.
        /// </summary>
        /// <param name="value">An other CurveArray</param>
        /// <param name="TangentialPoints">True, if the tangential points are taken</param>
        /// <returns>A Crosslist</returns>
        public CrossList getCrossList(CurveArray value, bool TangentialPoints)
        {
            ArrayList L1 = GetConnections();
            ArrayList L2 = value.GetConnections();

            int       StartJ;
            CrossList CL;
            CrossList Result = new CrossList();

            Result.AllowMultiCross = TangentialPoints;// for instant
            int AIndex = 0;

            for (int i = 0; i < L1.Count; i++)
            {
                CurveArray CA     = (CurveArray)L1[i];
                xyArray    A      = CA.getxyArray();
                int        BIndex = 0;
                StartJ = 0;
                for (int j = StartJ; j < L2.Count; j++)
                {
                    CurveArray CB = (CurveArray)L2[j];
                    xyArray    B  = CB.getxyArray();
                    CL = A.getCrossList(B, TangentialPoints);
                    for (int k = 0; k < CL.Count; k++)
                    {
                        CrossItem CI  = CL[k];
                        double    aID = CA.xyArrayIndexToCurveArrayIndex(CI.Param1);
                        double    bID = CB.xyArrayIndexToCurveArrayIndex(CI.Param2);



                        CI.Param1 = (float)AIndex + CA.xyArrayIndexToCurveArrayIndex(CI.Param1);
                        CI.Param2 = (float)BIndex + CB.xyArrayIndexToCurveArrayIndex(CI.Param2);
                        Curve  C1  = CA[Utils.trunc(aID)];
                        Curve  C2  = CB[Utils.trunc(bID)];
                        double Lam = CI.Param1 - Utils.trunc(CI.Param1);
                        double Mue = CI.Param2 - Utils.trunc(CI.Param2);

                        CI.Param1 = IndexOf(C1) + Lam;
                        CI.Param2 = value.IndexOf(C2) + Mue;
                        Mue       = CI.Param2 - Utils.trunc(CI.Param2);

                        Lam = CI.Param1 - Utils.trunc(CI.Param1);

                        if (C1.Cross(C2, Lam, Mue, out Lam, out Mue))
                        {
                            if ((Lam < 0) && ((System.Math.Abs(Lam) < 0.000001)))
                            {
                                Lam = 0;
                            }
                            if (System.Math.Abs(Lam - 1) < 0.00001)
                            {
                                Lam = 0.999999;
                            }
                            CI.Param1 = Utils.trunc(CI.Param1) + Lam;

                            if ((Mue < 0) && ((System.Math.Abs(Mue) < 0.000001)))
                            {
                                Mue = 0;
                            }
                            if (System.Math.Abs(Mue - 1) < 0.00001)
                            {
                                Mue = 0.999999;
                            }
                            CI.Param2 = Utils.trunc(CI.Param2) + Mue;
                        }

                        else
                        {
                            Lam = 0;
                            if (C1.Equals(C2))
                            {
                                Lam = 1;
                            }
                        }


                        if ((Utils.trunc(CI.Param1) < 0) && (System.Math.Abs(CI.Param1) < 0.00001))
                        {
                            CI.Param1 = 0;
                        }
                        if ((Utils.trunc(CI.Param2) < 0) && (System.Math.Abs(CI.Param2) < 0.00001))
                        {
                            CI.Param2 = 0;
                        }



                        //if (((Utils.trunc(System.Math.Round(CI.Param1,3)) !=System.Math.Round(CI.Param1,3)))
                        //    ||
                        //    ((Utils.trunc(System.Math.Round(CI.Param1,3)) !=System.Math.Round(CI.Param1,3))))
                        Result.Add(CI);
                    }
                    BIndex += CB.Count;
                }
                AIndex += CA.Count;
            }
            return(Result);
        }
Пример #7
0
        static CrossList CrossWithLine(xy A, xy B, xyArray Array, EdgeLoop E)
        {
            CrossList Result = new CrossList();
            double    Lam    = -1;
            double    Mue    = -1;

            _Array1 = Array;
            xy Last = Array[Array.Count - 1];

            for (int i = 0; i < Array.Count - 1; i++)
            {
                if (i < Array.Count - 1)
                {
                    if (Array[i].dist(Array[i + 1]) < LuckyEpsilon)
                    {
                        continue;
                    }
                }
                int Nexti = Succ(i);

                xy Next = Array[Nexti];
                if (!(TwoLines(A, B, Array[i], Next, ref Lam, ref Mue)))
                {
                    continue;
                }
                Lam = System.Math.Round(Lam, 8);
                Mue = System.Math.Round(Mue, 8);

                double D1  = Distance(Next, A, B);
                double D2  = Distance(Array[i], A, B);
                int    Prv = Prev(i);
                double D3  = Distance(Array[Prv], A, B);

                if ((System.Math.Abs(D1) < EdgeTolerance) &&
                    (System.Math.Abs(D2) < EdgeTolerance))
                {
                    Last = Array[i];
                    continue;
                }
                if ((System.Math.Abs(D1) >= EdgeTolerance) &&
                    (System.Math.Abs(D2) < EdgeTolerance))
                {
                    if ((System.Math.Abs(D3) < EdgeTolerance))
                    {
                        CrossItem CI = new CrossItem(i + LuckyEpsilon, Lam, -1);// FromBorder
                        if (D1 > 0)
                        {
                            CI.CrossKind = 1;
                        }
                        else
                        {
                            CI.CrossKind = -1;
                        }

                        CI.Border1 = BorderBehavior.BorderEnd;
                        Result.Add(CI);
                        continue;
                    }
                }
                if ((System.Math.Abs(D1) < EdgeTolerance) &&
                    (System.Math.Abs(D2) >= EdgeTolerance))
                {
                    int    succ         = Succ(Nexti);
                    double SuccDistance = System.Math.Abs(Distance(Array[succ], A, B));
                    if (SuccDistance <= EdgeTolerance)
                    {
                        // ToBorder
                        CrossItem CI = new CrossItem(i + (1 - LuckyEpsilon), Lam, -1);// ToBorder
                        CI.CrossKind = 1;
                        if (D2 < 0)
                        {
                            CI.CrossKind = 1;
                        }
                        else
                        {
                            CI.CrossKind = -1;
                        }
                        CI.Border1 = BorderBehavior.BorderBegin;
                        Result.Add(CI);
                        Last = Array[i];
                    }

                    continue;
                }


                if ((System.Math.Abs(D2) < EdgeTolerance) && (D1 * D3 < 0))
                {
                    // Mue ==0 Durchgehend
                    int kk = ToSide;
                    if (D1 < 0)
                    {
                        kk = -ToSide;
                    }


                    CrossItem CI = new CrossItem(i - Mue - 0.000000001, Lam, -1);
                    CI.CrossKind = 1;
                    if (D1 < 0)
                    {
                        CI.CrossKind = -1;
                    }

                    Result.Add(CI);
                    Last = Array[i];
                    continue;
                }
                else
                //else // neu------------------------------------------------------------
                if ((System.Math.Abs(D2) < EdgeTolerance) && (D1 * D3 > 0))
                {
                    if ((Mue >= -LuckyEpsilon) && ((Mue < 1 - LuckyEpsilon) &&
                                                   (Lam >= -LuckyEpsilon) && ((Lam <= 1 + LuckyEpsilon))))
                    {
                        xy     v1 = Array[i] - Array[Prv];
                        xy     v2 = Next - Array[i];
                        double kk = v1 & v2;
                        if (kk * D1 < 0)
                        {
                        }
                        //D1 = v1 & v2;
                        //D1 = -D1;


                        CrossItem CI = null;    // new CrossItem(i + Mue, Lam, -1);// ToBorder
                        if (D1 > 0)
                        {
                            CI = new CrossItem(i + Mue - LuckyEpsilon, Lam + LuckyEpsilon, -1);    // FromBorder
                        }
                        else
                        {
                            CI = new CrossItem(i + Mue - LuckyEpsilon, Lam - LuckyEpsilon, -1);    // FromBorder
                        }
                        if (D1 < 0)
                        {
                            CI.CrossKind = 1;
                        }
                        else
                        {
                            CI.CrossKind = -1;
                        }

                        CI.Border1 = BorderBehavior.BorderBegin;
                        Result.Add(CI);
                        if (D1 < 0)
                        {
                            CI = new CrossItem(i + Mue + LuckyEpsilon, Lam + LuckyEpsilon, -1);    // FromBorder
                        }
                        else
                        {
                            CI = new CrossItem(i + Mue + LuckyEpsilon, Lam - LuckyEpsilon, -1);    // FromBorder
                        }
                        if (D1 > 0)
                        {
                            CI.CrossKind = 1;
                        }
                        else
                        {
                            CI.CrossKind = -1;
                        }

                        CI.Border1 = BorderBehavior.BorderEnd;
                        Result.Add(CI);
                        continue;
                    }
                }
                if (D1 * D2 < 0)
                {
                    CrossItem CI = new CrossItem(i + Mue, Lam, -1);
                    CI.CrossKind = 1;
                    if (D1 < 0)
                    {
                        CI.CrossKind = -1;
                    }
                    Result.Add(CI);
                    Last = Array[i];
                    continue;
                }
            }

            return(Result);
        }