Example #1
0
        /// <summary>
        /// Appends points from another MultiVertexGeometryImpl at the end of this
        /// one.
        /// </summary>
        /// <param name="src">The source MultiVertexGeometryImpl</param>
        public void Add(com.epl.geometry.MultiVertexGeometryImpl src, int beginIndex, int endIndex)
        {
            int endIndexC = endIndex < 0 ? src.GetPointCount() : endIndex;

            if (beginIndex < 0 || beginIndex > src.GetPointCount() || endIndexC < beginIndex)
            {
                throw new System.ArgumentException();
            }
            if (beginIndex == endIndexC)
            {
                return;
            }
            MergeVertexDescription(src.GetDescription());
            int count         = endIndexC - beginIndex;
            int oldPointCount = m_pointCount;

            Resize(m_pointCount + count);
            _verifyAllStreams();
            for (int iattrib = 0, nattrib = src.GetDescription().GetAttributeCount(); iattrib < nattrib; iattrib++)
            {
                int semantics = src.GetDescription()._getSemanticsImpl(iattrib);
                int ncomps    = com.epl.geometry.VertexDescription.GetComponentCount(semantics);
                com.epl.geometry.AttributeStreamBase stream    = GetAttributeStreamRef(semantics);
                com.epl.geometry.AttributeStreamBase srcStream = src.GetAttributeStreamRef(semantics);
                stream.InsertRange(oldPointCount * ncomps, srcStream, beginIndex * ncomps, count * ncomps, true, 1, oldPointCount * ncomps);
            }
        }
        // Checked vs. Jan 11, 2011
        public override bool Equals(object other)
        {
            // Java checks
            if (other == this)
            {
                return(true);
            }
            if (!(other is com.epl.geometry.MultiVertexGeometryImpl))
            {
                return(false);
            }
            com.epl.geometry.MultiVertexGeometryImpl otherMulti = (com.epl.geometry.MultiVertexGeometryImpl)other;
            if (!(m_description.Equals(otherMulti.m_description)))
            {
                return(false);
            }
            if (IsEmptyImpl() != otherMulti.IsEmptyImpl())
            {
                return(false);
            }
            if (IsEmptyImpl())
            {
                return(true);
            }
            // both geometries are empty
            int pointCount      = GetPointCount();
            int pointCountOther = otherMulti.GetPointCount();

            if (pointCount != pointCountOther)
            {
                return(false);
            }
            for (int i = 0; i < m_description.GetAttributeCount(); i++)
            {
                int semantics = m_description.GetSemantics(i);
                com.epl.geometry.AttributeStreamBase stream      = GetAttributeStreamRef(semantics);
                com.epl.geometry.AttributeStreamBase streamOther = otherMulti.GetAttributeStreamRef(semantics);
                int components = com.epl.geometry.VertexDescription.GetComponentCount(semantics);
                if (!stream.Equals(streamOther, 0, pointCount * components))
                {
                    return(false);
                }
            }
            return(true);
        }
        /// <summary>Static method to construct the convex hull of a Multi_vertex_geometry.</summary>
        /// <remarks>
        /// Static method to construct the convex hull of a Multi_vertex_geometry.
        /// Returns a Geometry.
        /// \param mvg The geometry used to create the convex hull.
        /// </remarks>
        internal static com.epl.geometry.Geometry Construct(com.epl.geometry.MultiVertexGeometry mvg)
        {
            if (mvg.IsEmpty())
            {
                return(new com.epl.geometry.Polygon(mvg.GetDescription()));
            }
            com.epl.geometry.MultiVertexGeometryImpl mvg_impl = (com.epl.geometry.MultiVertexGeometryImpl)mvg._getImpl();
            int N = mvg_impl.GetPointCount();

            if (N <= 2)
            {
                if (N == 1 || mvg_impl.GetXY(0).Equals(mvg_impl.GetXY(1)))
                {
                    com.epl.geometry.Point point = new com.epl.geometry.Point(mvg_impl.GetDescription());
                    mvg_impl.GetPointByVal(0, point);
                    return(point);
                }
                else
                {
                    com.epl.geometry.Point    pt       = new com.epl.geometry.Point();
                    com.epl.geometry.Polyline polyline = new com.epl.geometry.Polyline(mvg_impl.GetDescription());
                    mvg_impl.GetPointByVal(0, pt);
                    polyline.StartPath(pt);
                    mvg_impl.GetPointByVal(1, pt);
                    polyline.LineTo(pt);
                    return(polyline);
                }
            }
            com.epl.geometry.AttributeStreamOfDbl stream      = (com.epl.geometry.AttributeStreamOfDbl)mvg_impl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION);
            com.epl.geometry.ConvexHull           convex_hull = new com.epl.geometry.ConvexHull(stream, N);
            int t0 = 0;
            int tm = 1;

            com.epl.geometry.Point2D pt_0 = new com.epl.geometry.Point2D();
            com.epl.geometry.Point2D pt_m = new com.epl.geometry.Point2D();
            com.epl.geometry.Point2D pt_p = new com.epl.geometry.Point2D();
            stream.Read(t0 << 1, pt_0);
            while (true)
            {
                if (tm >= N)
                {
                    break;
                }
                stream.Read(tm << 1, pt_m);
                if (!pt_m.IsEqual(pt_0, com.epl.geometry.NumberUtils.DoubleEps()))
                {
                    break;
                }
                tm++;
            }
            // We don't want to close the gap between t0 and tm.
            convex_hull.m_tree_hull.AddElement(t0, -1);
            if (tm < N)
            {
                convex_hull.m_tree_hull.AddBiggestElement(tm, -1);
                for (int tp = tm + 1; tp < mvg_impl.GetPointCount(); tp++)
                {
                    // Dynamically insert into the current convex hull
                    stream.Read(tp << 1, pt_p);
                    int p = convex_hull.TreeHull_(pt_p);
                    if (p != -1)
                    {
                        convex_hull.m_tree_hull.SetElement(p, tp);
                    }
                }
            }
            // reset the place holder to the point index.
            // Extracts the convex hull from the tree. Reading the tree in order from first to last is the resulting convex hull.
            com.epl.geometry.VertexDescription description = mvg_impl.GetDescription();
            bool b_has_attributes = (description.GetAttributeCount() > 1);
            int  point_count      = convex_hull.m_tree_hull.Size(-1);

            com.epl.geometry.Geometry hull;
            if (point_count >= 2)
            {
                if (point_count >= 3)
                {
                    hull = new com.epl.geometry.Polygon(description);
                }
                else
                {
                    hull = new com.epl.geometry.Polyline(description);
                }
                com.epl.geometry.MultiPathImpl hull_impl = (com.epl.geometry.MultiPathImpl)hull._getImpl();
                hull_impl.AddPath((com.epl.geometry.Point2D[])null, 0, true);
                com.epl.geometry.Point point = null;
                if (b_has_attributes)
                {
                    point = new com.epl.geometry.Point();
                }
                for (int i = convex_hull.m_tree_hull.GetFirst(-1); i != -1; i = convex_hull.m_tree_hull.GetNext(i))
                {
                    if (b_has_attributes)
                    {
                        mvg_impl.GetPointByVal(convex_hull.m_tree_hull.GetElement(i), point);
                        hull_impl.InsertPoint(0, -1, point);
                    }
                    else
                    {
                        stream.Read(convex_hull.m_tree_hull.GetElement(i) << 1, pt_p);
                        hull_impl.InsertPoint(0, -1, pt_p);
                    }
                }
            }
            else
            {
                System.Diagnostics.Debug.Assert((point_count == 1));
                if (b_has_attributes)
                {
                    com.epl.geometry.Point point = new com.epl.geometry.Point(description);
                    mvg_impl.GetPointByVal(convex_hull.m_tree_hull.GetElement(convex_hull.m_tree_hull.GetFirst(-1)), point);
                    hull = point;
                }
                else
                {
                    stream.Read(convex_hull.m_tree_hull.GetElement(convex_hull.m_tree_hull.GetFirst(-1)) << 1, pt_p);
                    hull = new com.epl.geometry.Point(pt_p);
                }
            }
            return(hull);
        }