/// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public virtual IntersectionMatrix ComputeIM()
        {
            IntersectionMatrix im = new IntersectionMatrix();
            // since Geometries are finite and embedded in a 2-D space, the EE element must always be 2
            im.Set(Locations.Exterior, Locations.Exterior, Dimensions.Surface);

            // if the Geometries don't overlap there is nothing to do
            if (!arg[0].Geometry.EnvelopeInternal.Intersects(arg[1].Geometry.EnvelopeInternal))
            {
                ComputeDisjointIM(im);
                return im;
            }
            arg[0].ComputeSelfNodes(li, false);
            arg[1].ComputeSelfNodes(li, false);

            // compute intersections between edges of the two input geometries
            SegmentIntersector intersector = arg[0].ComputeEdgeIntersections(arg[1], li, false);           
            ComputeIntersectionNodes(0);
            ComputeIntersectionNodes(1);

            /*
             * Copy the labelling for the nodes in the parent Geometries.  These override
             * any labels determined by intersections between the geometries.
             */
            CopyNodesAndLabels(0);
            CopyNodesAndLabels(1);

            // complete the labelling for any nodes which only have a label for a single point
            LabelIsolatedNodes();

            // If a proper intersection was found, we can set a lower bound on the IM.
            ComputeProperIntersectionIM(intersector, im);

            /*
             * Now process improper intersections
             * (eg where one or other of the geometries has a vertex at the intersection point)
             * We need to compute the edge graph at all nodes to determine the IM.
             */

            // build EdgeEnds for all intersections
            EdgeEndBuilder eeBuilder = new EdgeEndBuilder();
            IList ee0 = eeBuilder.ComputeEdgeEnds(arg[0].GetEdgeEnumerator());
            InsertEdgeEnds(ee0);
            IList ee1 = eeBuilder.ComputeEdgeEnds(arg[1].GetEdgeEnumerator());
            InsertEdgeEnds(ee1);

            LabelNodeEdges();

            /*
             * Compute the labeling for isolated components
             * <br>
             * Isolated components are components that do not touch any other components in the graph.
             * They can be identified by the fact that they will
             * contain labels containing ONLY a single element, the one for their parent point.
             * We only need to check components contained in the input graphs, since
             * isolated components will not have been replaced by new components formed by intersections.
             */           
            LabelIsolatedEdges(0, 1);            
            LabelIsolatedEdges(1, 0);

            // update the IM from all components
            UpdateIM(im);
            return im;
        }
 /// <summary>
 /// If the Geometries are disjoint, we need to enter their dimension and
 /// boundary dimension in the Ext rows in the IM
 /// </summary>
 /// <param name="im"></param>
 private void ComputeDisjointIM(IntersectionMatrix im)
 {
     IGeometry ga = arg[0].Geometry;
     if (!ga.IsEmpty)
     {
         im.Set(Locations.Interior, Locations.Exterior, ga.Dimension);
         im.Set(Locations.Boundary, Locations.Exterior, ga.BoundaryDimension);
     }
     IGeometry gb = arg[1].Geometry;
     if (!gb.IsEmpty)
     {
         im.Set(Locations.Exterior, Locations.Interior, gb.Dimension);
         im.Set(Locations.Exterior, Locations.Boundary, gb.BoundaryDimension);    
     }
 }