コード例 #1
0
 public virtual void TestEnvelope2D_corners()
 {
     com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D(0, 1, 2, 3);
     NUnit.Framework.Assert.IsFalse(env.Equals(null));
     NUnit.Framework.Assert.IsTrue(env.Equals((object)new com.epl.geometry.Envelope2D(0, 1, 2, 3)));
     com.epl.geometry.Point2D pt2D = env.GetLowerLeft();
     NUnit.Framework.Assert.IsTrue(pt2D.Equals(com.epl.geometry.Point2D.Construct(0, 1)));
     pt2D = env.GetUpperLeft();
     NUnit.Framework.Assert.IsTrue(pt2D.Equals(com.epl.geometry.Point2D.Construct(0, 3)));
     pt2D = env.GetUpperRight();
     NUnit.Framework.Assert.IsTrue(pt2D.Equals(com.epl.geometry.Point2D.Construct(2, 3)));
     pt2D = env.GetLowerRight();
     NUnit.Framework.Assert.IsTrue(pt2D.Equals(com.epl.geometry.Point2D.Construct(2, 1)));
     {
         com.epl.geometry.Point2D[] corners = new com.epl.geometry.Point2D[4];
         env.QueryCorners(corners);
         NUnit.Framework.Assert.IsTrue(corners[0].Equals(com.epl.geometry.Point2D.Construct(0, 1)));
         NUnit.Framework.Assert.IsTrue(corners[1].Equals(com.epl.geometry.Point2D.Construct(0, 3)));
         NUnit.Framework.Assert.IsTrue(corners[2].Equals(com.epl.geometry.Point2D.Construct(2, 3)));
         NUnit.Framework.Assert.IsTrue(corners[3].Equals(com.epl.geometry.Point2D.Construct(2, 1)));
         env.QueryCorners(corners);
         NUnit.Framework.Assert.IsTrue(corners[0].Equals(env.QueryCorner(0)));
         NUnit.Framework.Assert.IsTrue(corners[1].Equals(env.QueryCorner(1)));
         NUnit.Framework.Assert.IsTrue(corners[2].Equals(env.QueryCorner(2)));
         NUnit.Framework.Assert.IsTrue(corners[3].Equals(env.QueryCorner(3)));
     }
     {
         com.epl.geometry.Point2D[] corners = new com.epl.geometry.Point2D[4];
         env.QueryCornersReversed(corners);
         NUnit.Framework.Assert.IsTrue(corners[0].Equals(com.epl.geometry.Point2D.Construct(0, 1)));
         NUnit.Framework.Assert.IsTrue(corners[1].Equals(com.epl.geometry.Point2D.Construct(2, 1)));
         NUnit.Framework.Assert.IsTrue(corners[2].Equals(com.epl.geometry.Point2D.Construct(2, 3)));
         NUnit.Framework.Assert.IsTrue(corners[3].Equals(com.epl.geometry.Point2D.Construct(0, 3)));
         env.QueryCornersReversed(corners);
         NUnit.Framework.Assert.IsTrue(corners[0].Equals(env.QueryCorner(0)));
         NUnit.Framework.Assert.IsTrue(corners[1].Equals(env.QueryCorner(3)));
         NUnit.Framework.Assert.IsTrue(corners[2].Equals(env.QueryCorner(2)));
         NUnit.Framework.Assert.IsTrue(corners[3].Equals(env.QueryCorner(1)));
     }
     NUnit.Framework.Assert.IsTrue(env.GetCenter().Equals(com.epl.geometry.Point2D.Construct(1, 2)));
     NUnit.Framework.Assert.IsFalse(env.ContainsExclusive(env.GetUpperLeft()));
     NUnit.Framework.Assert.IsTrue(env.Contains(env.GetUpperLeft()));
     NUnit.Framework.Assert.IsTrue(env.ContainsExclusive(env.GetCenter()));
 }
コード例 #2
0
        internal bool ClusterNonReciprocal_()
        {
            int point_count = m_shape.GetTotalPointCount();

            com.epl.geometry.Envelope2D env = m_shape.GetEnvelope2D();
            m_origin = env.GetLowerLeft();
            double dim     = System.Math.Max(env.GetHeight(), env.GetWidth());
            double mincell = dim / (com.epl.geometry.NumberUtils.IntMax() - 1);

            if (m_cell_size < mincell)
            {
                m_cell_size     = mincell;
                m_inv_cell_size = 1.0 / m_cell_size;
            }
            // This holds clusters.
            m_clusters = new com.epl.geometry.IndexMultiList();
            m_clusters.ReserveLists(m_shape.GetTotalPointCount() / 3 + 1);
            m_clusters.ReserveNodes(m_shape.GetTotalPointCount() / 3 + 1);
            m_hash_values  = m_shape.CreateUserIndex();
            m_new_clusters = m_shape.CreateUserIndex();
            // Make the hash table. It serves a purpose of fine grain grid.
            // Make it 25% larger than the 4 times point count to reduce the chance
            // of collision.
            // The 4 times comes from the fact that we check four neighbouring cells
            // in the grid for each point.
            m_hash_function = new com.epl.geometry.Clusterer.ClusterHashFunction(this, m_shape, m_origin, m_sqr_tolerance, m_inv_cell_size, m_hash_values);
            m_hash_table    = new com.epl.geometry.IndexHashTable(4 * point_count / 3, m_hash_function);
            m_hash_table.ReserveElements(m_shape.GetTotalPointCount());
            bool b_clustered = false;

            // Go through all vertices stored in the m_shape and put the handles of
            // the vertices into the clusters and the hash table.
            for (int geometry = m_shape.GetFirstGeometry(); geometry != -1; geometry = m_shape.GetNextGeometry(geometry))
            {
                for (int path = m_shape.GetFirstPath(geometry); path != -1; path = m_shape.GetNextPath(path))
                {
                    int vertex = m_shape.GetFirstVertex(path);
                    for (int index = 0, nindex = m_shape.GetPathSize(path); index < nindex; index++)
                    {
                        System.Diagnostics.Debug.Assert((vertex != -1));
                        int hash = m_hash_function.Calculate_hash_from_vertex(vertex);
                        m_shape.SetUserIndex(vertex, m_hash_values, hash);
                        m_hash_table.AddElement(vertex, hash);
                        // add cluster to the
                        // hash table
                        System.Diagnostics.Debug.Assert((m_shape.GetUserIndex(vertex, m_new_clusters) == -1));
                        vertex = m_shape.GetNextVertex(vertex);
                    }
                }
            }
            {
                // m_hash_table->dbg_print_bucket_histogram_();
                // scope for candidates array
                com.epl.geometry.AttributeStreamOfInt32 candidates = new com.epl.geometry.AttributeStreamOfInt32(0);
                candidates.Reserve(10);
                for (int geometry_1 = m_shape.GetFirstGeometry(); geometry_1 != -1; geometry_1 = m_shape.GetNextGeometry(geometry_1))
                {
                    for (int path = m_shape.GetFirstPath(geometry_1); path != -1; path = m_shape.GetNextPath(path))
                    {
                        int vertex = m_shape.GetFirstVertex(path);
                        for (int index = 0, nindex = m_shape.GetPathSize(path); index < nindex; index++)
                        {
                            if (m_shape.GetUserIndex(vertex, m_new_clusters) == com.epl.geometry.StridedIndexTypeCollection.ImpossibleIndex2())
                            {
                                vertex = m_shape.GetNextVertex(vertex);
                                continue;
                            }
                            // this vertex was merged with another
                            // cluster. It also was removed from the
                            // hash table.
                            int hash = m_shape.GetUserIndex(vertex, m_hash_values);
                            m_hash_table.DeleteElement(vertex, hash);
                            while (true)
                            {
                                CollectClusterCandidates_(vertex, candidates);
                                if (candidates.Size() == 0)
                                {
                                    // no candidate for
                                    // clustering has
                                    // been found for
                                    // the cluster_1.
                                    break;
                                }
                                bool clustered = false;
                                for (int candidate_index = 0, ncandidates = candidates.Size(); candidate_index < ncandidates; candidate_index++)
                                {
                                    int cluster_node = candidates.Get(candidate_index);
                                    int other_vertex = m_hash_table.GetElement(cluster_node);
                                    m_hash_table.DeleteNode(cluster_node);
                                    clustered |= MergeClusters_(vertex, other_vertex, candidate_index + 1 == ncandidates);
                                }
                                b_clustered |= clustered;
                                candidates.Clear(false);
                                // repeat search for the cluster candidates for
                                // cluster_1
                                if (!clustered)
                                {
                                    break;
                                }
                            }
                            // positions did not change
                            // m_shape->set_user_index(vertex, m_new_clusters,
                            // Strided_index_type_collection::impossible_index_2());
                            vertex = m_shape.GetNextVertex(vertex);
                        }
                    }
                }
            }
            if (b_clustered)
            {
                ApplyClusterPositions_();
            }
            m_hash_table    = null;
            m_hash_function = null;
            m_shape.RemoveUserIndex(m_hash_values);
            m_shape.RemoveUserIndex(m_new_clusters);
            // output_debug_printf("total: %d\n",m_shape->get_total_point_count());
            // output_debug_printf("clustered: %d\n",m_dbg_candidate_check_count);
            return(b_clustered);
        }
コード例 #3
0
 /// <summary>Returns the envelope's lower left corner point.</summary>
 /// <returns>Returns the lower left corner point.</returns>
 public virtual com.epl.geometry.Point GetLowerLeft()
 {
     return(new com.epl.geometry.Point(m_envelope.GetLowerLeft()));
 }