public bool CheckFeatureIntersection(
     float2 a1, float2 s1, FeatureType2D s1t, float2 b1,
     float2 a2, float2 s2, FeatureType2D s2t, float2 b2)
 {
     //This checks if the 2D feature triangles overlap
     //(except for triangle base overlaps which should not happen by definition of the MS cases)
     return(CheckLineIntersection(a1.x, a1.y, s1.x, s1.y, a2.x, a2.y, s2.x, s2.y) ||
            CheckLineIntersection(a1.x, a1.y, s1.x, s1.y, b2.x, b2.y, s2.x, s2.y) ||
            CheckLineIntersection(b1.x, b1.y, s1.x, s1.y, a2.x, a2.y, s2.x, s2.y) ||
            CheckLineIntersection(b1.x, b1.y, s1.x, s1.y, b2.x, b2.y, s2.x, s2.y) ||
            CheckLineIntersection(a1.x, a1.y, b1.x, b1.y, a2.x, a2.y, s2.x, s2.y) ||
            CheckLineIntersection(a1.x, a1.y, b1.x, b1.y, b2.x, b2.y, s2.x, s2.y) ||
            CheckLineIntersection(a1.x, a1.y, s1.x, s1.y, a2.x, a2.y, b2.x, b2.y) ||
            CheckLineIntersection(b1.x, b1.y, s1.x, s1.y, a2.x, a2.y, b2.x, b2.y));
 }
        public void Solve(
            TCell cell, int cellFace,
            float2 pos1, float2 normal1, float2 pos2, float2 normal2, float featureAngle3D,
            float width, float height, out float2 feature, out FeatureType2D type)
        {
            //There is a sharp feature, lines need to be intersected
            if (FindLineIntersection(pos1.x, pos1.y, pos1.x + normal1.y, pos1.y - normal1.x, pos2.x, pos2.y, pos2.x + normal2.y, pos2.y - normal2.x, out feature))
            {
                //Lines successfully intersected, potentially sharp feature found.
                type = (feature.x <0 || feature.x> width || feature.y <0 || feature.y> height) ? FeatureType2D.SHARP_OUT_OF_BOUNDS : FeatureType2D.SHARP;
                return;
            }
            else
            {
                type = FeatureType2D.INVALID;
            }

            //Lines couldn't be intersected properly, assume a direct line between vertices
            //and place the feature in the middle between the two vertices.
            feature = new float2((pos1.x + pos2.x) / 2.0F, (pos1.y + pos2.y) / 2.0F);
        }