// p0 and p1 have to be on left/right boundary of fullRange2D (since this
        // fuction can be called recursively, p0 or p1 can also be fullRange2D
        // corners)
        internal static int AddPointsToArray(com.epl.geometry.Point2D p0In, com.epl.geometry.Point2D p1In, com.epl.geometry.Point2D[] pointsArray, int idx, com.epl.geometry.Envelope2D fullRange2D, bool clockwise, double densifyDist)
        {
            // PointerOfArrayOf(Point2D)
            // pointsArray, int idx,
            // Envelope2D fullRange2D,
            // boolean clockwise, double
            // densifyDist)
            com.epl.geometry.Point2D p0 = new com.epl.geometry.Point2D();
            p0.SetCoords(p0In);
            com.epl.geometry.Point2D p1 = new com.epl.geometry.Point2D();
            p1.SetCoords(p1In);
            fullRange2D._snapToBoundary(p0);
            fullRange2D._snapToBoundary(p1);
            // //_ASSERT((p0.x == fullRange2D.xmin || p0.x == fullRange2D.xmax) &&
            // (p1.x == fullRange2D.xmin || p1.x == fullRange2D.xmax));
            double boundDist0 = fullRange2D._boundaryDistance(p0);
            double boundDist1 = fullRange2D._boundaryDistance(p1);

            if (boundDist1 == 0.0)
            {
                boundDist1 = fullRange2D.GetLength();
            }
            if ((p0.x == p1.x || p0.y == p1.y && (p0.y == fullRange2D.ymin || p0.y == fullRange2D.ymax)) && (boundDist1 > boundDist0) == clockwise)
            {
                com.epl.geometry.Point2D delta = new com.epl.geometry.Point2D();
                delta.SetCoords(p1.x - p0.x, p1.y - p0.y);
                if (densifyDist != 0)
                {
                    // if (densifyDist)
                    long cPoints = (long)(delta._norm(0) / densifyDist);
                    if (cPoints > 0)
                    {
                        // if (cPoints)
                        delta.Scale(1.0 / (cPoints + 1));
                        for (long i = 0; i < cPoints; i++)
                        {
                            p0.Add(delta);
                            pointsArray[idx++].SetCoords(p0.x, p0.y);
                        }
                    }
                }
            }
            else
            {
                // ARRAYELEMENT(pointsArray,
                // idx++).setCoords(p0.x,
                // p0.y);
                int side0 = fullRange2D._envelopeSide(p0);
                int side1 = fullRange2D._envelopeSide(p1);
                // create up to four corner points; the order depends on boolean
                // clockwise
                com.epl.geometry.Point2D corner;
                int deltaSide = clockwise ? 1 : 3;
                do
                {
                    // 3 is equivalent to -1
                    side0  = (side0 + deltaSide) & 3;
                    corner = fullRange2D.QueryCorner(side0);
                    if (densifyDist != 0)
                    {
                        // if (densifyDist)
                        idx = AddPointsToArray(p0, corner, pointsArray, idx, fullRange2D, clockwise, densifyDist);
                    }
                    pointsArray[idx++].SetCoords(corner.x, corner.y);
                    // ARRAYELEMENT(pointsArray,
                    // idx++).setCoords(corner.x,
                    // corner.y);
                    p0 = corner;
                }while ((side0 & 3) != side1);
                if (densifyDist != 0)
                {
                    // if (densifyDist)
                    idx = AddPointsToArray(p0, p1, pointsArray, idx, fullRange2D, clockwise, densifyDist);
                }
            }
            return(idx);
        }