public void MergePoints(ref IndexedVector4 plane, float margin, IndexedVector3[] points, int point_count)
        {
            m_point_count       = 0;
            m_penetration_depth = -1000.0f;

            int _k;

            for (_k = 0; _k < point_count; _k++)
            {
                float _dist = -ClipPolygon.DistancePointPlane(ref plane, ref points[_k]) + margin;

                if (_dist >= 0.0f)
                {
                    if (_dist > m_penetration_depth)
                    {
                        m_penetration_depth = _dist;
                        point_indices[0]    = _k;
                        m_point_count       = 1;
                    }
                    else if ((_dist + MathUtil.SIMD_EPSILON) >= m_penetration_depth)
                    {
                        point_indices[m_point_count] = _k;
                        m_point_count++;
                    }
                }
            }

            for (_k = 0; _k < m_point_count; _k++)
            {
                m_points[_k] = points[point_indices[_k]];
            }
        }
        //! Test if triangles could collide
        public bool OverlapTestConservative(PrimitiveTriangle other)
        {
            float total_margin = m_margin + other.m_margin;
            // classify points on other triangle
            float dis0 = ClipPolygon.DistancePointPlane(ref m_plane, ref other.m_vertices[0]) - total_margin;

            float dis1 = ClipPolygon.DistancePointPlane(ref m_plane, ref other.m_vertices[1]) - total_margin;

            float dis2 = ClipPolygon.DistancePointPlane(ref m_plane, ref other.m_vertices[2]) - total_margin;

            if (dis0 > 0.0f && dis1 > 0.0f && dis2 > 0.0f)
            {
                return(false);
            }

            // classify points on this triangle
            dis0 = ClipPolygon.DistancePointPlane(ref other.m_plane, ref m_vertices[0]) - total_margin;

            dis1 = ClipPolygon.DistancePointPlane(ref other.m_plane, ref m_vertices[1]) - total_margin;

            dis2 = ClipPolygon.DistancePointPlane(ref other.m_plane, ref m_vertices[2]) - total_margin;

            if (dis0 > 0.0f && dis1 > 0.0f && dis2 > 0.0f)
            {
                return(false);
            }

            return(true);
        }
        public bool OverlapTestConservative(TriangleShapeEx other)
        {
            float total_margin = GetMargin() + other.GetMargin();

            IndexedVector4 plane0;

            BuildTriPlane(out plane0);
            IndexedVector4 plane1;

            other.BuildTriPlane(out plane1);

            // classify points on other triangle
            float dis0 = ClipPolygon.DistancePointPlane(ref plane0, ref other.m_vertices1[0]) - total_margin;

            float dis1 = ClipPolygon.DistancePointPlane(ref plane0, ref other.m_vertices1[1]) - total_margin;

            float dis2 = ClipPolygon.DistancePointPlane(ref plane0, ref other.m_vertices1[2]) - total_margin;

            if (dis0 > 0.0f && dis1 > 0.0f && dis2 > 0.0f)
            {
                return(false);
            }

            // classify points on this triangle
            dis0 = ClipPolygon.DistancePointPlane(ref plane1, ref m_vertices1[0]) - total_margin;

            dis1 = ClipPolygon.DistancePointPlane(ref plane1, ref m_vertices1[1]) - total_margin;

            dis2 = ClipPolygon.DistancePointPlane(ref plane1, ref m_vertices1[2]) - total_margin;

            if (dis0 > 0.0f && dis1 > 0.0f && dis2 > 0.0f)
            {
                return(false);
            }

            return(true);
        }