Neco/LandView/LandViewUtils.cs
/// <summary>Calclates if L1 and L2 intersect</summary>
/// <param name="L1"></param>
/// <param name="L2"></param>
/// <returns></returns>
Calclates if L1 and L2 intersect
Calclates if L1 and L2 intersect
public static bool Intersects(LandViewItem L1, LandViewItem L2) {
            foreach (Point P in L2.GraphicalPoints) {
                if (ContainsPoint(L1, P)) { return true; }
            }
            Rectangle R1 = LandviewItemBoundingRectangle(L1);
            Rectangle R2 = LandviewItemBoundingRectangle(L2);
            if (!R1.IntersectsWith(R2)) { return false; }
            for (int i = 0; i < L1.GraphicalPoints.Length-1; i++) {
                PointF P1 = L1.GraphicalPoints[i];
                PointF P2 = L1.GraphicalPoints[i+1];
                for (int j = 0; j < L2.GraphicalPoints.Length-1; j++) {
                    PointF P3 = L2.GraphicalPoints[j];
                    PointF P4 = L2.GraphicalPoints[j + 1];
                    if (LinesIntersect(P1, P2, P3, P4)) { return true; } 
                }
            }
            return false;
        }
public static bool Intersects ( LandViewItem L1 , LandViewItem L2 ) { foreach ( Point P in L2 . GraphicalPoints ) { if ( ContainsPoint ( L1 , P ) ) { return true ; } } Rectangle R1 = LandviewItemBoundingRectangle ( L1 ) ; Rectangle R2 = LandviewItemBoundingRectangle ( L2 ) ; if ( ! R1 . IntersectsWith ( R2 ) ) { return false ; } for ( int i = 0 ; i < L1 . GraphicalPoints . Length - 1 ; i ++ ) { PointF P1 = L1 . GraphicalPoints [ i ] ; PointF P2 = L1 . GraphicalPoints [ i + 1 ] ; for ( int j = 0 ; j < L2 . GraphicalPoints . Length - 1 ; j ++ ) { PointF P3 = L2 . GraphicalPoints [ j ] ; PointF P4 = L2 . GraphicalPoints [ j + 1 ] ; if ( LinesIntersect ( P1 , P2 , P3 , P4 ) ) { return true ; } } } return false ; }
Calclates if L1 and L2 intersect
Calclates if L1 and L2 intersect
//First find if it is contained //Actually FastContains does nothing for us. If it's fast contained we can't say its contained, and if it isn't fastcontained (IE if we can say it //isn't contained), that doesn't mean it doesn't intersect //Something similar to Deepcontains can help us determine if it *does* intersect: //Instead of normal deepcontains, let's check if *any* points land in the first landview item's area: //Now do a fast calculation: //If the rectangles do not intersect, then we can be sure that this does not intersect //If they do we need to do the nitty gritty //For each line in L1 //The line is GraphicalPOints[i] to GraphicalPoints[i+1] //For each line in L2 //if any lines intersect then we intersect
None
L1
LandViewItem
None
L2
LandViewItem
None