Exemplo n.º 1
0
        public void SetUsed()
        {
            isUsed = true;
            CrossPointInfo info = GetCrossSideCrossPointInfo();

            info.isUsed = true;
        }
Exemplo n.º 2
0
        public CrossPointInfo Copy()
        {
            CrossPointInfo info = new CrossPointInfo();

            info.isUsed            = isUsed;
            info.type              = type;
            info.pt                = pt;
            info.dist              = dist;
            info.inoutType         = inoutType;
            info.selfSide          = selfSide;
            info.pointIdx          = pointIdx;
            info.crossSide         = crossSide;
            info.crossSidePointIdx = crossSidePointIdx;
            return(info);
        }
        /// <summary>
        /// 为多边形生成端点的交点信息
        /// </summary>
        /// <param name="poly"></param>
        void CreatePolyEndPointInfo(Poly poly)
        {
            CrossPointInfo    crossPtInfo;
            List <PolySide[]> sidesList = poly.sidesList;

            for (int i = 0; i < sidesList.Count; i++)
            {
                PolySide[] sides = sidesList[i];
                for (int j = 0; j < sides.Length; j++)
                {
                    if (sides[j].crossPointInfoList == null)
                    {
                        sides[j].crossPointInfoList = new List <CrossPointInfo>();
                    }

                    sides[j].crossPointInfoList = new List <CrossPointInfo>();

                    crossPtInfo                   = new CrossPointInfo();
                    crossPtInfo.type              = PointType.EndPoint;
                    crossPtInfo.selfSide          = sides[j];
                    crossPtInfo.crossSide         = null;
                    crossPtInfo.pt                = sides[j].startpos;
                    crossPtInfo.pointIdx          = 0;
                    crossPtInfo.crossSidePointIdx = 1;
                    crossPtInfo.dist              = 0 - 0.0001f;
                    sides[j].crossPointInfoList.Add(crossPtInfo);

                    crossPtInfo                   = new CrossPointInfo();
                    crossPtInfo.type              = PointType.EndPoint;
                    crossPtInfo.selfSide          = sides[j];
                    crossPtInfo.crossSide         = null;
                    crossPtInfo.pt                = sides[j].startpos + sides[j].dir * sides[j].step;
                    crossPtInfo.pointIdx          = 1;
                    crossPtInfo.crossSidePointIdx = 0;
                    crossPtInfo.dist              = sides[j].step + 0.0001f;
                    sides[j].crossPointInfoList.Add(crossPtInfo);
                }
            }
        }
        /// <summary>
        /// 差集
        /// </summary>
        void SubOp()
        {
            List <Vector3d> newPolyVertList = new List <Vector3d>();
            CrossPointInfo  firstPtInfo;
            CrossPointInfo  ptInfo = null, ptInfo2;
            bool            wiseFlag;
            bool            isPolyANull = false;

            while (true)
            {
                wiseFlag    = true;
                firstPtInfo = null;

                if (!isPolyANull)
                {
                    ptInfo = firstPtInfo = polyA.GetOneUnUsedEndPointInfo(0);
                }

                if (firstPtInfo == null)
                {
                    isPolyANull = true;
                    ptInfo      = firstPtInfo = polyB.GetOneUnUsedEndPointInfo(0);
                    if (firstPtInfo == null)
                    {
                        break;
                    }
                }

                while (true)
                {
                    ptInfo.SetUsed();
                    newPolyVertList.Add(ptInfo.pt);

                    if (wiseFlag)
                    {
                        ptInfo2 = ptInfo.GetSelfSideNextCrossPointInfo();
                        if (ptInfo2 != null)
                        {
                            ptInfo = ptInfo2;
                        }
                        else
                        {
                            ptInfo = ptInfo.GetCrossSideCrossPointInfo();
                            ptInfo = ptInfo.GetSelfSideNextCrossPointInfo();
                        }
                    }
                    else
                    {
                        ptInfo2 = ptInfo.GetSelfSidePrevCrossPointInfo();

                        if (ptInfo2 != null)
                        {
                            ptInfo = ptInfo2;
                        }
                        else
                        {
                            ptInfo = ptInfo.GetCrossSideCrossPointInfo();
                            ptInfo = ptInfo.GetSelfSidePrevCrossPointInfo();
                        }
                    }

                    if (ptInfo.type != PointType.EndPoint)
                    {
                        ptInfo   = ptInfo.GetCrossSideCrossPointInfo();
                        wiseFlag = !wiseFlag;
                    }
                    else
                    {
                        if (ptInfo == firstPtInfo ||
                            ptInfo.GetCrossSideCrossPointInfo() == firstPtInfo)
                        {
                            break;
                        }
                    }
                }

                if (newPolyVertList.Count > 0)
                {
                    resultPolyVertsList.Add(newPolyVertList.ToArray());
                    newPolyVertList.Clear();
                }
            }

            if (resultPolyVertsList.Count != 0)
            {
                return;
            }

            //
            int inoutA = polyA.sidesList[0][0].crossPointInfoList[0].inoutType;
            int inoutB = polyB.sidesList[0][0].crossPointInfoList[0].inoutType;

            if (inoutA == 0 && inoutB == 0)
            {
                for (int i = 0; i < polyA.vertexsList.Count; i++)
                {
                    resultPolyVertsList.Add(polyA.vertexsList[i]);
                }

                for (int i = 0; i < polyB.vertexsList.Count; i++)
                {
                    resultPolyVertsList.Add(polyB.vertexsList[i]);
                }

                return;
            }

            if (inoutA == 0 && inoutB == 1)
            {
                CreateInoutTypeVertesxToResult(polyA, polyB);
                return;
            }

            if (inoutA == 1 && inoutB == 0)
            {
                CreateInoutTypeVertesxToResult(polyB, polyA);
                return;
            }
        }
        /// <summary>
        /// 生成多边形之间的边相交交点信息
        /// </summary>
        void CreatePolysCrossPointInfo()
        {
            List <PolySide[]> sidesListA = polyA.sidesList;
            List <PolySide[]> sidesListB = polyB.sidesList;
            Vector3d          crossPt;
            int crossPtCount;

            for (int i = 0; i < sidesListA.Count; i++)
            {
                PolySide[] sidesA = sidesListA[i];
                for (int j = 0; j < sidesA.Length; j++)
                {
                    for (int i2 = 0; i2 < sidesListB.Count; i2++)
                    {
                        PolySide[] sidesB = sidesListB[i2];
                        for (int j2 = 0; j2 < sidesB.Length; j2++)
                        {
                            crossPtCount = geoAlgor.SolvePolySideCrossPoint(sidesA[j], sidesB[j2], polyA.faceNormal, out crossPt);
                            if (crossPtCount == 0)
                            {
                                continue;
                            }

                            CrossPointInfo crossPtInfoA;
                            CrossPointInfo crossPtInfoB;

                            if (sidesA[j].crossPointInfoList == null)
                            {
                                sidesA[j].crossPointInfoList = new List <CrossPointInfo>();
                            }

                            if (sidesB[j2].crossPointInfoList == null)
                            {
                                sidesB[j2].crossPointInfoList = new List <CrossPointInfo>();
                            }

                            crossPtInfoA                   = new CrossPointInfo();
                            crossPtInfoA.selfSide          = sidesA[j];
                            crossPtInfoA.crossSide         = sidesB[j2];
                            crossPtInfoA.pt                = crossPt;
                            crossPtInfoA.pointIdx          = sidesA[j].crossPointInfoList.Count;
                            crossPtInfoA.crossSidePointIdx = sidesB[j2].crossPointInfoList.Count;
                            Vector3d v = crossPt - crossPtInfoA.selfSide.startpos;
                            crossPtInfoA.dist = geoAlgor.GetScale(v, crossPtInfoA.selfSide.dir);
                            sidesA[j].crossPointInfoList.Add(crossPtInfoA);

                            //
                            crossPtInfoB                   = new CrossPointInfo();
                            crossPtInfoB.selfSide          = sidesB[j2];
                            crossPtInfoB.crossSide         = sidesA[j];
                            crossPtInfoB.pt                = crossPt;
                            crossPtInfoB.pointIdx          = sidesB[j2].crossPointInfoList.Count;
                            crossPtInfoB.crossSidePointIdx = sidesA[j].crossPointInfoList.Count;
                            v = crossPt - crossPtInfoB.selfSide.startpos;
                            crossPtInfoB.dist = geoAlgor.GetScale(v, crossPtInfoB.selfSide.dir);
                            sidesB[j2].crossPointInfoList.Add(crossPtInfoB);
                        }
                    }
                }
            }
        }