private static int QuickTest2DMVEnvelopeRasterOnly(com.epl.geometry.MultiVertexGeometry geomA, com.epl.geometry.Envelope2D geomBEnv, double tolerance)
 {
     // Use rasterized Geometry only:
     com.epl.geometry.RasterizedGeometry2D    rgeomA;
     com.epl.geometry.MultiVertexGeometryImpl mpImpl = (com.epl.geometry.MultiVertexGeometryImpl)geomA._getImpl();
     com.epl.geometry.GeometryAccelerators    gaccel = mpImpl._getAccelerators();
     if (gaccel != null)
     {
         rgeomA = gaccel.GetRasterizedGeometry();
     }
     else
     {
         return(-1);
     }
     if (rgeomA != null)
     {
         com.epl.geometry.RasterizedGeometry2D.HitType hitres = rgeomA.QueryEnvelopeInGeometry(geomBEnv);
         if (hitres == com.epl.geometry.RasterizedGeometry2D.HitType.Outside)
         {
             return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Disjoint);
         }
         if (hitres == com.epl.geometry.RasterizedGeometry2D.HitType.Inside)
         {
             return((int)com.epl.geometry.OperatorInternalRelationUtils.Relation.Contains);
         }
     }
     else
     {
         return(-1);
     }
     return(0);
 }
Exemplo n.º 2
0
 // Dynamically inserts each geometry into the convex hull.
 private void AddMultiVertexGeometry_(com.epl.geometry.MultiVertexGeometry mvg)
 {
     com.epl.geometry.Point   point = new com.epl.geometry.Point();
     com.epl.geometry.Point2D pt_p  = new com.epl.geometry.Point2D();
     for (int i = 0; i < mvg.GetPointCount(); i++)
     {
         mvg.GetXY(i, pt_p);
         int p = AddPoint_(pt_p);
         if (p != -1)
         {
             mvg.GetPointByVal(i, point);
             int tp = m_shape.AddPoint(m_path_handle, point);
             m_tree_hull.SetElement(p, tp);
         }
     }
 }
        private static int QuickTest2DMVMVRasterOnly(com.epl.geometry.MultiVertexGeometry geomA, com.epl.geometry.MultiVertexGeometry geomB, double tolerance)
        {
            com.epl.geometry.Envelope2D geomBEnv = new com.epl.geometry.Envelope2D();
            geomB.QueryEnvelope2D(geomBEnv);
            int res = QuickTest2DMVEnvelopeRasterOnly(geomA, geomBEnv, tolerance);

            if (res > 0)
            {
                return(res);
            }
            if (res == -1)
            {
                com.epl.geometry.Envelope2D geomAEnv = new com.epl.geometry.Envelope2D();
                geomA.QueryEnvelope2D(geomAEnv);
                res = QuickTest2DMVEnvelopeRasterOnly(geomB, geomAEnv, tolerance);
                if (res > 0)
                {
                    return(ReverseResult(res));
                }
            }
            // TODO: implement me
            return(0);
        }
        public static void CompareGeometryContent(com.epl.geometry.MultiVertexGeometry geom1, com.epl.geometry.MultiVertexGeometry geom2)
        {
            // Geometry types
            NUnit.Framework.Assert.IsTrue(geom1.GetType().Value() == geom2.GetType().Value());
            // Envelopes
            com.epl.geometry.Envelope2D env1 = new com.epl.geometry.Envelope2D();
            geom1.QueryEnvelope2D(env1);
            com.epl.geometry.Envelope2D env2 = new com.epl.geometry.Envelope2D();
            geom2.QueryEnvelope2D(env2);
            NUnit.Framework.Assert.IsTrue(env1.xmin == env2.xmin && env1.xmax == env2.xmax && env1.ymin == env2.ymin && env1.ymax == env2.ymax);
            int type = geom1.GetType().Value();

            if (type == com.epl.geometry.Geometry.GeometryType.Polyline || type == com.epl.geometry.Geometry.GeometryType.Polygon)
            {
                // Part Count
                int partCount1 = ((com.epl.geometry.MultiPath)geom1).GetPathCount();
                int partCount2 = ((com.epl.geometry.MultiPath)geom2).GetPathCount();
                NUnit.Framework.Assert.IsTrue(partCount1 == partCount2);
                // Part indices
                for (int i = 0; i < partCount1; i++)
                {
                    int start1 = ((com.epl.geometry.MultiPath)geom1).GetPathStart(i);
                    int start2 = ((com.epl.geometry.MultiPath)geom2).GetPathStart(i);
                    NUnit.Framework.Assert.IsTrue(start1 == start2);
                    int end1 = ((com.epl.geometry.MultiPath)geom1).GetPathEnd(i);
                    int end2 = ((com.epl.geometry.MultiPath)geom2).GetPathEnd(i);
                    NUnit.Framework.Assert.IsTrue(end1 == end2);
                }
            }
            // Point count
            int pointCount1 = geom1.GetPointCount();
            int pointCount2 = geom2.GetPointCount();

            NUnit.Framework.Assert.IsTrue(pointCount1 == pointCount2);
            if (type == com.epl.geometry.Geometry.GeometryType.MultiPoint || type == com.epl.geometry.Geometry.GeometryType.Polyline || type == com.epl.geometry.Geometry.GeometryType.Polygon)
            {
                // POSITION
                com.epl.geometry.AttributeStreamBase  positionStream1 = ((com.epl.geometry.MultiVertexGeometryImpl)geom1._getImpl()).GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION);
                com.epl.geometry.AttributeStreamOfDbl position1       = (com.epl.geometry.AttributeStreamOfDbl)(positionStream1);
                com.epl.geometry.AttributeStreamBase  positionStream2 = ((com.epl.geometry.MultiVertexGeometryImpl)geom2._getImpl()).GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION);
                com.epl.geometry.AttributeStreamOfDbl position2       = (com.epl.geometry.AttributeStreamOfDbl)(positionStream2);
                for (int i = 0; i < pointCount1; i++)
                {
                    double x1 = position1.Read(2 * i);
                    double x2 = position2.Read(2 * i);
                    NUnit.Framework.Assert.IsTrue(x1 == x2);
                    double y1 = position1.Read(2 * i + 1);
                    double y2 = position2.Read(2 * i + 1);
                    NUnit.Framework.Assert.IsTrue(y1 == y2);
                }
                // Zs
                bool bHasZs1 = geom1.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z);
                bool bHasZs2 = geom2.HasAttribute(com.epl.geometry.VertexDescription.Semantics.Z);
                NUnit.Framework.Assert.IsTrue(bHasZs1 == bHasZs2);
                if (bHasZs1)
                {
                    com.epl.geometry.AttributeStreamBase  zStream1 = ((com.epl.geometry.MultiVertexGeometryImpl)geom1._getImpl()).GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.Z);
                    com.epl.geometry.AttributeStreamOfDbl zs1      = (com.epl.geometry.AttributeStreamOfDbl)(zStream1);
                    com.epl.geometry.AttributeStreamBase  zStream2 = ((com.epl.geometry.MultiVertexGeometryImpl)geom2._getImpl()).GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.Z);
                    com.epl.geometry.AttributeStreamOfDbl zs2      = (com.epl.geometry.AttributeStreamOfDbl)(zStream2);
                    for (int i_1 = 0; i_1 < pointCount1; i_1++)
                    {
                        double z1 = zs1.Read(i_1);
                        double z2 = zs2.Read(i_1);
                        NUnit.Framework.Assert.IsTrue(z1 == z2);
                    }
                }
                // Ms
                bool bHasMs1 = geom1.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M);
                bool bHasMs2 = geom2.HasAttribute(com.epl.geometry.VertexDescription.Semantics.M);
                NUnit.Framework.Assert.IsTrue(bHasMs1 == bHasMs2);
                if (bHasMs1)
                {
                    com.epl.geometry.AttributeStreamBase  mStream1 = ((com.epl.geometry.MultiVertexGeometryImpl)geom1._getImpl()).GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.M);
                    com.epl.geometry.AttributeStreamOfDbl ms1      = (com.epl.geometry.AttributeStreamOfDbl)(mStream1);
                    com.epl.geometry.AttributeStreamBase  mStream2 = ((com.epl.geometry.MultiVertexGeometryImpl)geom2._getImpl()).GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.M);
                    com.epl.geometry.AttributeStreamOfDbl ms2      = (com.epl.geometry.AttributeStreamOfDbl)(mStream2);
                    for (int i_1 = 0; i_1 < pointCount1; i_1++)
                    {
                        double m1 = ms1.Read(i_1);
                        double m2 = ms2.Read(i_1);
                        NUnit.Framework.Assert.IsTrue(m1 == m2);
                    }
                }
                // IDs
                bool bHasIDs1 = geom1.HasAttribute(com.epl.geometry.VertexDescription.Semantics.ID);
                bool bHasIDs2 = geom2.HasAttribute(com.epl.geometry.VertexDescription.Semantics.ID);
                NUnit.Framework.Assert.IsTrue(bHasIDs1 == bHasIDs2);
                if (bHasIDs1)
                {
                    com.epl.geometry.AttributeStreamBase    idStream1 = ((com.epl.geometry.MultiVertexGeometryImpl)geom1._getImpl()).GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.ID);
                    com.epl.geometry.AttributeStreamOfInt32 ids1      = (com.epl.geometry.AttributeStreamOfInt32)(idStream1);
                    com.epl.geometry.AttributeStreamBase    idStream2 = ((com.epl.geometry.MultiVertexGeometryImpl)geom2._getImpl()).GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.ID);
                    com.epl.geometry.AttributeStreamOfInt32 ids2      = (com.epl.geometry.AttributeStreamOfInt32)(idStream2);
                    for (int i_1 = 0; i_1 < pointCount1; i_1++)
                    {
                        int id1 = ids1.Read(i_1);
                        int id2 = ids2.Read(i_1);
                        NUnit.Framework.Assert.IsTrue(id1 == id2);
                    }
                }
            }
        }
Exemplo n.º 5
0
        /// <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);
        }
Exemplo n.º 6
0
 internal static bool IsWeakSimple(com.epl.geometry.MultiVertexGeometry geom, double tol)
 {
     return(((com.epl.geometry.MultiVertexGeometryImpl)geom._getImpl()).GetIsSimple(tol) > 0);
 }
Exemplo n.º 7
0
        internal virtual com.epl.geometry.Proximity2DResult[] MultiVertexGetNearestVertices(com.epl.geometry.MultiVertexGeometry geom, com.epl.geometry.Point2D inputPoint, double searchRadius, int maxVertexCountToReturn)
        {
            com.epl.geometry.Proximity2DResult[] resultArray;
            if (maxVertexCountToReturn == 0)
            {
                resultArray = new com.epl.geometry.Proximity2DResult[0];
                return(resultArray);
            }
            com.epl.geometry.MultiVertexGeometryImpl mpImpl   = (com.epl.geometry.MultiVertexGeometryImpl)geom._getImpl();
            com.epl.geometry.AttributeStreamOfDbl    position = (com.epl.geometry.AttributeStreamOfDbl)mpImpl.GetAttributeStreamRef((com.epl.geometry.VertexDescription.Semantics.POSITION));
            int pointCount = geom.GetPointCount();

            System.Collections.Generic.List <com.epl.geometry.Proximity2DResult> v = new System.Collections.Generic.List <com.epl.geometry.Proximity2DResult>(maxVertexCountToReturn);
            int    count          = 0;
            double searchRadiusSq = searchRadius * searchRadius;

            for (int i = 0; i < pointCount; i++)
            {
                double x          = position.Read(2 * i);
                double y          = position.Read(2 * i + 1);
                double xDiff      = inputPoint.x - x;
                double yDiff      = inputPoint.y - y;
                double distanceSq = xDiff * xDiff + yDiff * yDiff;
                if (distanceSq <= searchRadiusSq)
                {
                    com.epl.geometry.Proximity2DResult result = new com.epl.geometry.Proximity2DResult();
                    result._setParams(x, y, i, System.Math.Sqrt(distanceSq));
                    count++;
                    v.Add(result);
                }
            }
            int vsize = v.Count;

            v.Sort(new com.epl.geometry.Proximity2DResultComparator());
            if (maxVertexCountToReturn >= vsize)
            {
                return(v.ToArray());
            }
            return(v.GetRange(0, maxVertexCountToReturn - 0).ToArray());
        }
Exemplo n.º 8
0
        internal virtual com.epl.geometry.Proximity2DResult MultiVertexGetNearestVertex(com.epl.geometry.MultiVertexGeometry geom, com.epl.geometry.Point2D inputPoint)
        {
            com.epl.geometry.MultiVertexGeometryImpl mpImpl   = (com.epl.geometry.MultiVertexGeometryImpl)geom._getImpl();
            com.epl.geometry.AttributeStreamOfDbl    position = (com.epl.geometry.AttributeStreamOfDbl)mpImpl.GetAttributeStreamRef((com.epl.geometry.VertexDescription.Semantics.POSITION));
            int    pointCount        = geom.GetPointCount();
            int    closestIndex      = 0;
            double closestx          = 0.0;
            double closesty          = 0.0;
            double closestDistanceSq = com.epl.geometry.NumberUtils.DoubleMax();

            for (int i = 0; i < pointCount; i++)
            {
                com.epl.geometry.Point2D pt = new com.epl.geometry.Point2D();
                position.Read(2 * i, pt);
                double distanceSq = com.epl.geometry.Point2D.SqrDistance(pt, inputPoint);
                if (distanceSq < closestDistanceSq)
                {
                    closestx          = pt.x;
                    closesty          = pt.y;
                    closestIndex      = i;
                    closestDistanceSq = distanceSq;
                }
            }
            com.epl.geometry.Proximity2DResult result = new com.epl.geometry.Proximity2DResult();
            result._setParams(closestx, closesty, closestIndex, System.Math.Sqrt(closestDistanceSq));
            return(result);
        }
Exemplo n.º 9
0
 /// <summary>Appends points from another multipoint at the end of this multipoint.</summary>
 /// <param name="src">The mulitpoint to append to this multipoint.</param>
 /// <param name="srcFrom">
 /// The start index in the source multipoint from which to start
 /// appending points.
 /// </param>
 /// <param name="srcTo">
 /// The end index in the source multipoint right after the last
 /// point to be appended. Use -1 to indicate the rest of the
 /// source multipoint.
 /// </param>
 public virtual void Add(com.epl.geometry.MultiVertexGeometry src, int srcFrom, int srcTo)
 {
     m_impl.Add((com.epl.geometry.MultiVertexGeometryImpl)src._getImpl(), srcFrom, srcTo);
 }