/**
         * Linearizes arcs and circles.
         *
         * @param arcOrdinates
         *            arc or circle coordinates
         * @param dim
         *            coordinate dimension
         * @param lrs
         *            whether this is an lrs geometry
         * @param entireCirlce
         *            whether the whole arc should be linearized
         * @return linearized interpolation of arcs or circle
         */
        private ICoordinate[] Linearize(Double[] arcOrdinates, int dim, bool lrs,
                                        bool entireCirlce)
        {
            ICoordinate[] linearizedCoords = new ICoordinate[0];
            // CoordDim is the dimension that includes only non-measure (X,Y,Z)
            // ordinates in its value
            int coordDim = lrs ? dim - 1 : dim;

            // this only works with 2-Dimensional geometries, since we use
            // JGeometry linearization;
            if (coordDim != 2)
            {
                throw new ArgumentException(
                          "Can only linearize 2D arc segments, but geometry is "
                          + dim + "D.");
            }
            int numOrd = dim;

            while (numOrd < arcOrdinates.Length)
            {
                numOrd = numOrd - dim;
                double x1 = arcOrdinates[numOrd++];
                double y1 = arcOrdinates[numOrd++];
                double m1 = lrs ? arcOrdinates[numOrd++] : Double.NaN;
                double x2 = arcOrdinates[numOrd++];
                double y2 = arcOrdinates[numOrd++];
                double m2 = lrs ? arcOrdinates[numOrd++] : Double.NaN;
                double x3 = arcOrdinates[numOrd++];
                double y3 = arcOrdinates[numOrd++];
                double m3 = lrs ? arcOrdinates[numOrd++] : Double.NaN;

                ICoordinate[] coords;
                if (entireCirlce)
                {
                    coords = Circle.LinearizeCircle(x1, y1, x2, y2, x3, y3);
                }
                else
                {
                    coords = Circle.LinearizeArc(x1, y1, x2, y2, x3, y3);
                }

                // if this is an LRS geometry, fill the measure values into
                // the linearized array
                if (lrs)
                {
                    ICoordinate[] mcoord    = new ICoordinate[coords.Length];
                    int           lastIndex = coords.Length - 1;
                    mcoord[0]         = MCoordinate.Create2dWithMeasure(x1, y1, m1);
                    mcoord[lastIndex] = MCoordinate.Create2dWithMeasure(x3, y3, m3);
                    // convert the middle coordinates to MCoordinate
                    for (int i = 1; i < lastIndex; i++)
                    {
                        mcoord[i] = MCoordinate.ConvertCoordinate(coords[i]);
                        // if we happen to split on the middle measure, then
                        // assign it
                        if (mcoord[i].X == x2 &&
                            mcoord[i].Y == y2)
                        {
                            ((MCoordinate)mcoord[i]).M = m2;
                        }
                    }
                    coords = mcoord;
                }

                // if this is not the first arcsegment, the first linearized
                // point is already in linearizedArc, so disregard this.
                int resultBegin = 1;
                if (linearizedCoords.Length == 0)
                {
                    resultBegin = 0;
                }

                int           destPos   = linearizedCoords.Length;
                ICoordinate[] tmpCoords = new Coordinate[linearizedCoords.Length
                                                         + coords.Length - resultBegin];
                Array.Copy(linearizedCoords, 0, tmpCoords, 0, linearizedCoords.Length);
                Array.Copy(coords, resultBegin, tmpCoords, destPos, coords.Length - resultBegin);

                linearizedCoords = tmpCoords;
            }
            return(linearizedCoords);
        }