Ejemplo n.º 1
0
        private bool FindIntersects(List <ITrajectory> A, List <ITrajectory> B, bool isClockWise, int skip)
        {
            for (var x = isClockWise ? A.Count - 1 : 0; isClockWise?x >= 0 : x < A.Count; x += isClockWise ? -1 : 1)
            {
                var xPart = new StraightTrajectory(A[x]);
                for (var y = isClockWise ? skip : B.Count - 1 - skip; isClockWise?y < B.Count : y >= 0; y += isClockWise ? 1 : -1)
                {
                    var yPart     = new StraightTrajectory(B[y]);
                    var intersect = Intersection.CalculateSingle(xPart, yPart);
                    if (intersect.IsIntersect)
                    {
                        if (isClockWise)
                        {
                            A[x] = xPart.Cut(0f, intersect.FirstT);
                            B[y] = yPart.Cut(intersect.SecondT, 1f);
                            B.RemoveRange(0, y);
                        }
                        else
                        {
                            A[x] = xPart.Cut(intersect.FirstT, 1f);
                            B[y] = yPart.Cut(0f, intersect.SecondT);
                            B.RemoveRange(y + 1, B.Count - (y + 1));
                        }

                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        private bool FindIntersects(List <ITrajectory> A, List <ITrajectory> B, bool invert)
        {
            var x     = !invert ? A.Count - 1 : 0;
            var xPart = new StraightTrajectory(A[x]);

            for (var y = !invert ? 1 : B.Count - 2; !invert ? y < B.Count : y >= 0; y += !invert ? 1 : -1)
            {
                var yPart     = new StraightTrajectory(B[y]);
                var intersect = MarkupIntersect.CalculateSingle(xPart, yPart);
                if (intersect.IsIntersect)
                {
                    if (!invert)
                    {
                        A[x] = xPart.Cut(0f, intersect.FirstT);
                        B[y] = yPart.Cut(intersect.SecondT, 1f);
                        B.RemoveRange(0, y);
                    }
                    else
                    {
                        A[x] = xPart.Cut(intersect.FirstT, 1f);
                        B[y] = yPart.Cut(0f, intersect.SecondT);
                        B.RemoveRange(y + 1, B.Count - (y + 1));
                    }

                    return(true);
                }
            }

            return(false);
        }