示例#1
0
 internal EdgeEnumerable(WeVertex vtx)
 {
     _vtx = vtx;
 }
示例#2
0
        private bool FCheckDoublyInfinite(List <Vector> ptsBox, out IEnumerable <Vector> ptsToBeClipped)
        {
            ptsToBeClipped = null;

            // This case will always have exactly three vertices - one finite and two infinite
            if (Vertices.Count() != 3)
            {
                return(false);
            }

            // Get the finite vertex
            WeVertex vtx       = null;
            var      vtxs      = Vertices.ToArray();
            var      ptTailDir = new Vector(0, 0);
            var      ptHeadDir = new Vector(0, 0);

            for (var ivtx = 0; ivtx < 3; ivtx++)
            {
                if (vtxs[ivtx].FAtInfinity)
                {
                    continue;
                }

                ptTailDir = vtxs[(ivtx + 1) % 3].Pt;
                ptHeadDir = vtxs[(ivtx + 2) % 3].Pt;
                vtx       = vtxs[ivtx];
                break;
            }

            // If it's only got two edges emanating from it (a doubly infinite line)
            // ReSharper disable once PossibleNullReferenceException
            if (vtx.Edges.Count() == 2)
            {
                // TODO: We should probably do this manually rather than relying on ConvexPolyIntersection

                // Figure out a satisfactory distance for our ray length
                var maxDist = 2.0 * Math.Sqrt(ptsBox.Select(pt => DistanceSq(pt, vtx.Pt)).Max());
                var ptTail  = vtx.Pt + ptTailDir * maxDist;
                var ptHead  = vtx.Pt + ptHeadDir * maxDist;

                // For every point in the box
                //
                // We have to include the points to the left of the line in our rectangle we want clipped
                // So find the max distance and extend a rect that length to the side of our line
                // segment.  We double the offset just to be safe.

                var leftDistances = ptsBox.
                                    // Get the distance to our line
                                    Select(p => PtToLineDistance(p, ptHead, ptTail)).
                                    // Keep only the ones to the left of the line
                                    Where(d => d > 0);

                // If there were no points to the left
                var leftDistancesArray = leftDistances as double[] ?? leftDistances.ToArray();
                if (!leftDistancesArray.Any())
                {
                    // return an empty array
                    ptsToBeClipped = new List <Vector>();
                    return(true);
                }

                // Our rect width will be twice the largest of the left distances
                var maxLineDist = 2 * leftDistancesArray.Max();

                // Return the rectangle formed from our line segment extended out by maxLineDist
                var vcOffset = (ptTail - ptHead).Normalize().Flip90Ccw() * maxLineDist;
                //var vcOffset = (ptHead - ptTail).Normalize().Flip90Ccw() * maxLineDist;
                ptsToBeClipped = new List <Vector>
                {
                    ptHead,
                    ptTail,
                    ptTail + vcOffset,
                    ptHead + vcOffset
                };
                return(true);
            }

            return(false);
        }
示例#3
0
            private readonly WeVertex _vtx;             // The vertex we're enumerating around
            #endregion

            #region Constructor
            internal EdgeEnumerator(WeVertex vtx)
            {
                _vtx = vtx;
            }