public PolyhedralUpperEnvelope(PolyhedralDistanceFunction distfunc, double[] p1, double[] p2)
    {
        this.distfunc = distfunc;
        this.p1       = p1;
        this.p2       = p2;

        sortedfacets = new List <FacetList>();

        for (int i = 0; i < distfunc.getComplexity(); i++)
        {
            sortedfacets.Add(new FacetList(i, p1, p2, distfunc));
        }

//		IComparer myComparer = new sortClass();
        sortedfacets.Sort();         // myComparer );
    }
    //   @Override
    public void add(int i, double[] P1, double[] P2, double[] Q)
    {
        //     assert P1 == p1;
        //   assert P2 == p2;

        for (int f = 0; f < distfunc.getComplexity(); f++)
        {
            FacetList fl = sortedfacets[f];

            FacetListElement fle = new FacetListElement();
            fle.index  = i;
            fle.slope  = fl.slope;
            fle.height = distfunc.getFacetDistance(VectorUtil.subtract(p1, Q), fl.facet);

            while (fl.getSize() > 0 && fl.getFirst().height <= fle.height)
            {
                fl.removeFirst();
            }
            fl.addFirst(fle);
        }
    }