예제 #1
0
        private void Init()
        {
            int[] firstTriIdxs;
            var   pts    = D.Points;
            var   ptsCnt = pts.Length;

            m_Origin = CalcOrigin(out firstTriIdxs);
            Func <float, int> keyHash;
            var thetaGroups = Frontier.ThetaGroup.BuildThetaGroups(ptsCnt, out keyHash);
            var grpsCnt     = thetaGroups.Length;

            m_PolPos      = new PolartPt[ptsCnt]; //TODO make this dynamic to save memory?
            m_VertIdxsByR = new int[ptsCnt - 3];
            var idxOffset = 0;

            for (var pIdx = 0; pIdx < ptsCnt; ++pIdx)
            {
                //Store polar position
                var polPos = new PolartPt(pts[pIdx], m_Origin);
                m_PolPos[pIdx] = polPos;
                var theta = polPos.Theta;

                //Reference theta group
                var grpIdx = keyHash(theta);
                if (grpIdx >= grpsCnt) //Floating point error check TODO
                {
                    grpIdx--;
                }

                polPos.thetaGroup = thetaGroups[grpIdx];

                //Prepare r index reference (to be sorted later)
                if (firstTriIdxs.Contains(pIdx))
                {
                    idxOffset++;
                    continue;
                }

                m_VertIdxsByR[pIdx - idxOffset] = pIdx;
            }

            //Sort points by distance to origin
            //Array.Sort(m_VertIdxsByR, (_a, _b) => m_PolPos[_a].r.CompareTo(m_PolPos[_b].r));
            Array.Sort(m_VertIdxsByR, (_a, _b) => ComparePol(m_PolPos[_a], m_PolPos[_b]));

            //Init Frontier
            var firstTri = new Delaunay.Triangle(firstTriIdxs[0], firstTriIdxs[1], firstTriIdxs[2], D);

            m_Frontier = new Frontier(firstTri, this);
        }
예제 #2
0
            public Frontier(Delaunay.Triangle _firstTri, CircleSweep _cs)
            {
                CS = _cs;

                var ftPts = new List <FrontierPt>
                {
                    new FrontierPt(_firstTri.Edge0, CS),
                    new FrontierPt(_firstTri.Edge1, CS),
                    new FrontierPt(_firstTri.Edge2, CS)
                };

                ftPts[0].Right = ftPts[1];
                ftPts[0].Left  = ftPts[2];
                ftPts[1].Right = ftPts[2];
                ftPts[1].Left  = ftPts[0];
                ftPts[2].Right = ftPts[0];
                ftPts[2].Left  = ftPts[1];

                CS.m_PolPos[ftPts[0].VertIdx].thetaGroup.Add(ftPts[0]);
                CS.m_PolPos[ftPts[1].VertIdx].thetaGroup.Add(ftPts[1]);
                CS.m_PolPos[ftPts[2].VertIdx].thetaGroup.Add(ftPts[2]);
            }