Esempio n. 1
0
 public virtual void TestCopy()
 {
     com.epl.geometry.Point pt     = new com.epl.geometry.Point();
     com.epl.geometry.Point copyPt = (com.epl.geometry.Point)pt.Copy();
     NUnit.Framework.Assert.IsTrue(copyPt.Equals(pt));
     pt.SetXY(11, 13);
     copyPt = (com.epl.geometry.Point)pt.Copy();
     NUnit.Framework.Assert.IsTrue(copyPt.Equals(pt));
     NUnit.Framework.Assert.IsTrue(copyPt.GetXY().IsEqual(new com.epl.geometry.Point2D(11, 13)));
     NUnit.Framework.Assert.IsTrue(copyPt.GetXY().Equals((object)new com.epl.geometry.Point2D(11, 13)));
 }
Esempio n. 2
0
        internal virtual com.epl.geometry.Proximity2DResult PointGetNearestVertex(com.epl.geometry.Point geom, com.epl.geometry.Point2D input_point)
        {
            com.epl.geometry.Point2D pt = geom.GetXY();
            double distance             = com.epl.geometry.Point2D.Distance(pt, input_point);

            return(new com.epl.geometry.Proximity2DResult(pt, 0, distance));
        }
Esempio n. 3
0
        internal virtual com.epl.geometry.Proximity2DResult[] PointGetNearestVertices(com.epl.geometry.Point geom, com.epl.geometry.Point2D inputPoint, double searchRadius, int maxVertexCountToReturn)
        {
            com.epl.geometry.Proximity2DResult[] resultArray;
            if (maxVertexCountToReturn == 0)
            {
                resultArray = new com.epl.geometry.Proximity2DResult[] {  };
                return(resultArray);
            }
            double searchRadiusSq = searchRadius * searchRadius;

            com.epl.geometry.Point2D pt = geom.GetXY();
            double distanceSq           = com.epl.geometry.Point2D.SqrDistance(pt, inputPoint);

            if (distanceSq <= searchRadiusSq)
            {
                resultArray = new com.epl.geometry.Proximity2DResult[1];
                com.epl.geometry.Proximity2DResult result = new com.epl.geometry.Proximity2DResult();
                result._setParams(pt.x, pt.y, 0, System.Math.Sqrt(distanceSq));
                resultArray[0] = result;
            }
            else
            {
                resultArray = new com.epl.geometry.Proximity2DResult[0];
            }
            return(resultArray);
        }
Esempio n. 4
0
        // recalculate coordinates of the vertices by averaging them using weights.
        // return true if the coordinates has changed.
        internal static bool MergeVertices(com.epl.geometry.Point pt_1, com.epl.geometry.Point pt_2, double w_1, int rank_1, double w_2, int rank_2, com.epl.geometry.Point pt_res, double[] w_res, int[] rank_res)
        {
            System.Diagnostics.Debug.Assert((!pt_1.IsEmpty() && !pt_2.IsEmpty()));
            bool res = pt_1.Equals(pt_2);

            if (rank_1 > rank_2)
            {
                pt_res = pt_1;
                if (w_res != null)
                {
                    rank_res[0] = rank_1;
                    w_res[0]    = w_1;
                }
                return(res);
            }
            else
            {
                if (rank_2 > rank_1)
                {
                    pt_res = pt_2;
                    if (w_res != null)
                    {
                        rank_res[0] = rank_1;
                        w_res[0]    = w_1;
                    }
                    return(res);
                }
            }
            pt_res = pt_1;
            com.epl.geometry.Point2D pt2d = new com.epl.geometry.Point2D();
            MergeVertices2D(pt_1.GetXY(), pt_2.GetXY(), w_1, rank_1, w_2, rank_2, pt2d, w_res, rank_res);
            pt_res.SetXY(pt2d);
            return(res);
        }
Esempio n. 5
0
 /// <summary>Merges this envelope with the point.</summary>
 /// <remarks>
 /// Merges this envelope with the point. The boundary of the envelope is
 /// increased to include the point. If the envelope is empty, the coordinates
 /// of the point to merge are assigned. If the point is empty, the original
 /// envelope is unchanged.
 /// </remarks>
 /// <param name="point">The point to be merged.</param>
 public virtual void Merge(com.epl.geometry.Point point)
 {
     _touch();
     if (point.IsEmptyImpl())
     {
         return;
     }
     com.epl.geometry.VertexDescription pointVD = point.m_description;
     if (m_description != pointVD)
     {
         MergeVertexDescription(pointVD);
     }
     if (IsEmpty())
     {
         _setFromPoint(point);
         return;
     }
     m_envelope.Merge(point.GetXY());
     for (int iattrib = 1, nattrib = pointVD.GetAttributeCount(); iattrib < nattrib; iattrib++)
     {
         int semantics = pointVD._getSemanticsImpl(iattrib);
         int ncomps    = com.epl.geometry.VertexDescription.GetComponentCount(semantics);
         for (int iord = 0; iord < ncomps; iord++)
         {
             double v = point.GetAttributeAsDbl(semantics, iord);
             com.epl.geometry.Envelope1D interval = QueryInterval(semantics, iord);
             interval.Merge(v);
             SetInterval(semantics, iord, interval);
         }
     }
 }
 private static int QuickTest2DEnvelopePoint(com.epl.geometry.Envelope geomA, com.epl.geometry.Point geomB, double tolerance)
 {
     com.epl.geometry.Envelope2D geomAEnv = new com.epl.geometry.Envelope2D();
     geomA.QueryEnvelope2D(geomAEnv);
     com.epl.geometry.Point2D ptB;
     ptB = geomB.GetXY();
     return(QuickTest2DEnvelopePoint(geomAEnv, ptB, tolerance));
 }
 public static int IsPointInPolygon(com.epl.geometry.Polygon inputPolygon, com.epl.geometry.Point inputPoint, double tolerance)
 {
     if (inputPoint.IsEmpty())
     {
         return(0);
     }
     return(IsPointInPolygon(inputPolygon, inputPoint.GetXY(), tolerance));
 }
        internal static com.epl.geometry.Geometry MultiPointSymDiffPoint_(com.epl.geometry.MultiPoint multi_point, com.epl.geometry.Point point, double tolerance, com.epl.geometry.ProgressTracker progress_tracker)
        {
            com.epl.geometry.MultiPointImpl       multipointImpl = (com.epl.geometry.MultiPointImpl)(multi_point._getImpl());
            com.epl.geometry.AttributeStreamOfDbl position       = (com.epl.geometry.AttributeStreamOfDbl)(multipointImpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION));
            int point_count = multi_point.GetPointCount();

            com.epl.geometry.Point2D    point2D        = point.GetXY();
            com.epl.geometry.MultiPoint new_multipoint = (com.epl.geometry.MultiPoint)(multi_point.CreateInstance());
            double tolerance_cluster = tolerance * System.Math.Sqrt(2.0) * 1.00001;

            com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D();
            multi_point.QueryEnvelope2D(env);
            env.Inflate(tolerance_cluster, tolerance_cluster);
            if (env.Contains(point2D))
            {
                double tolerance_cluster_sq = tolerance_cluster * tolerance_cluster;
                bool   b_found_covered      = false;
                bool[] covered = new bool[point_count];
                for (int i = 0; i < point_count; i++)
                {
                    covered[i] = false;
                }
                for (int i_1 = 0; i_1 < point_count; i_1++)
                {
                    double x  = position.Read(2 * i_1);
                    double y  = position.Read(2 * i_1 + 1);
                    double dx = x - point2D.x;
                    double dy = y - point2D.y;
                    if (dx * dx + dy * dy <= tolerance_cluster_sq)
                    {
                        b_found_covered = true;
                        covered[i_1]    = true;
                    }
                }
                if (!b_found_covered)
                {
                    new_multipoint.Add(multi_point, 0, point_count);
                    new_multipoint.Add(point);
                }
                else
                {
                    for (int i_2 = 0; i_2 < point_count; i_2++)
                    {
                        if (!covered[i_2])
                        {
                            new_multipoint.Add(multi_point, i_2, i_2 + 1);
                        }
                    }
                }
            }
            else
            {
                new_multipoint.Add(multi_point, 0, point_count);
                new_multipoint.Add(point);
            }
            return(new_multipoint);
        }
Esempio n. 9
0
        // reset the place holder to
        // tp
        private void AddPoint_(com.epl.geometry.Point point)
        {
            com.epl.geometry.Point2D pt_p = point.GetXY();
            int p = AddPoint_(pt_p);

            if (p != -1)
            {
                int tp = m_shape.AddPoint(m_path_handle, point);
                m_tree_hull.SetElement(p, tp);
            }
        }
 // return the input point
 internal static com.epl.geometry.Geometry PointMinusEnvelope_(com.epl.geometry.Point point, com.epl.geometry.Envelope envelope, double tolerance, com.epl.geometry.ProgressTracker progress_tracker)
 {
     com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D();
     envelope.QueryEnvelope2D(env);
     env.Inflate(tolerance, tolerance);
     com.epl.geometry.Point2D pt = point.GetXY();
     if (!env.Contains(pt))
     {
         return(point);
     }
     return(point.CreateInstance());
 }
        internal static com.epl.geometry.Geometry PointMinusPoint_(com.epl.geometry.Point point_a, com.epl.geometry.Point point_b, double tolerance, com.epl.geometry.ProgressTracker progress_tracker)
        {
            double tolerance_cluster    = tolerance * System.Math.Sqrt(2.0) * 1.00001;
            double tolerance_cluster_sq = tolerance_cluster * tolerance_cluster;

            com.epl.geometry.Point2D pt_a = point_a.GetXY();
            com.epl.geometry.Point2D pt_b = point_b.GetXY();
            if (com.epl.geometry.Point2D.SqrDistance(pt_a, pt_b) <= tolerance_cluster_sq)
            {
                return(point_a.CreateInstance());
            }
            // return empty point
            return(point_a);
        }
        internal static com.epl.geometry.Geometry PointSymDiffPoint_(com.epl.geometry.Point point_a, com.epl.geometry.Point point_b, double tolerance, com.epl.geometry.ProgressTracker progress_tracker)
        {
            double tolerance_cluster    = tolerance * System.Math.Sqrt(2.0) * 1.00001;
            double tolerance_cluster_sq = tolerance_cluster * tolerance_cluster;

            com.epl.geometry.Point2D    pt_a        = point_a.GetXY();
            com.epl.geometry.Point2D    pt_b        = point_b.GetXY();
            com.epl.geometry.MultiPoint multi_point = new com.epl.geometry.MultiPoint(point_a.GetDescription());
            if (com.epl.geometry.Point2D.SqrDistance(pt_a, pt_b) > tolerance_cluster_sq)
            {
                multi_point.Add(point_a);
                multi_point.Add(point_b);
            }
            return(multi_point);
        }
Esempio n. 13
0
 internal virtual void _setFromPoint(com.epl.geometry.Point centerPoint, double width, double height)
 {
     m_envelope.SetCoords(centerPoint.GetXY(), width, height);
     com.epl.geometry.VertexDescription pointVD = centerPoint.m_description;
     for (int iattrib = 1, nattrib = pointVD.GetAttributeCount(); iattrib < nattrib; iattrib++)
     {
         int semantics = pointVD._getSemanticsImpl(iattrib);
         int ncomps    = com.epl.geometry.VertexDescription.GetComponentCount(semantics);
         for (int iord = 0; iord < ncomps; iord++)
         {
             double v = centerPoint.GetAttributeAsDbl(semantics, iord);
             SetInterval(semantics, iord, v, v);
         }
     }
 }
        internal static com.epl.geometry.Geometry MultiPointMinusPoint_(com.epl.geometry.MultiPoint multi_point, com.epl.geometry.Point point, double tolerance, com.epl.geometry.ProgressTracker progress_tracker)
        {
            com.epl.geometry.MultiPointImpl       multipointImpl = (com.epl.geometry.MultiPointImpl)(multi_point._getImpl());
            com.epl.geometry.AttributeStreamOfDbl position       = (com.epl.geometry.AttributeStreamOfDbl)(multipointImpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION));
            int point_count = multi_point.GetPointCount();

            com.epl.geometry.Point2D point2D = point.GetXY();
            com.epl.geometry.Point2D pt      = new com.epl.geometry.Point2D();
            bool b_found_covered             = false;

            bool[] covered = new bool[point_count];
            for (int i = 0; i < point_count; i++)
            {
                covered[i] = false;
            }
            double tolerance_cluster    = tolerance * System.Math.Sqrt(2.0) * 1.00001;
            double tolerance_cluster_sq = tolerance_cluster * tolerance_cluster;

            for (int i_1 = 0; i_1 < point_count; i_1++)
            {
                position.Read(2 * i_1, pt);
                double sqr_dist = com.epl.geometry.Point2D.SqrDistance(pt, point2D);
                if (sqr_dist <= tolerance_cluster_sq)
                {
                    b_found_covered = true;
                    covered[i_1]    = true;
                }
            }
            if (!b_found_covered)
            {
                return(multi_point);
            }
            com.epl.geometry.MultiPoint new_multipoint = (com.epl.geometry.MultiPoint)(multi_point.CreateInstance());
            for (int i_2 = 0; i_2 < point_count; i_2++)
            {
                if (!covered[i_2])
                {
                    new_multipoint.Add(multi_point, i_2, i_2 + 1);
                }
            }
            return(new_multipoint);
        }
Esempio n. 15
0
        public override com.epl.geometry.Proximity2DResult[] GetNearestVertices(com.epl.geometry.Geometry geom, com.epl.geometry.Point inputPoint, double searchRadius, int maxVertexCountToReturn)
        {
            if (maxVertexCountToReturn < 0)
            {
                throw new System.ArgumentException();
            }
            if (geom.IsEmpty())
            {
                return(new com.epl.geometry.Proximity2DResult[] {  });
            }
            com.epl.geometry.Point2D  inputPoint2D     = inputPoint.GetXY();
            com.epl.geometry.Geometry proxmityTestGeom = geom;
            int gt = geom.GetType().Value();

            if (gt == com.epl.geometry.Geometry.GeometryType.Envelope)
            {
                com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon();
                polygon.AddEnvelope((com.epl.geometry.Envelope)geom, false);
                proxmityTestGeom = polygon;
                gt = com.epl.geometry.Geometry.GeometryType.Polygon;
            }
            switch (gt)
            {
            case com.epl.geometry.Geometry.GeometryType.Point:
            {
                return(PointGetNearestVertices((com.epl.geometry.Point)proxmityTestGeom, inputPoint2D, searchRadius, maxVertexCountToReturn));
            }

            case com.epl.geometry.Geometry.GeometryType.MultiPoint:
            case com.epl.geometry.Geometry.GeometryType.Polyline:
            case com.epl.geometry.Geometry.GeometryType.Polygon:
            {
                return(MultiVertexGetNearestVertices((com.epl.geometry.MultiVertexGeometry)proxmityTestGeom, inputPoint2D, searchRadius, maxVertexCountToReturn));
            }

            default:
            {
                throw new com.epl.geometry.GeometryException("not implemented");
            }
            }
        }
Esempio n. 16
0
        public override com.epl.geometry.Proximity2DResult GetNearestCoordinate(com.epl.geometry.Geometry geom, com.epl.geometry.Point inputPoint, bool bTestPolygonInterior, bool bCalculateLeftRightSide)
        {
            if (geom.IsEmpty())
            {
                return(new com.epl.geometry.Proximity2DResult());
            }
            com.epl.geometry.Point2D  inputPoint2D     = inputPoint.GetXY();
            com.epl.geometry.Geometry proxmityTestGeom = geom;
            int gt = geom.GetType().Value();

            if (gt == com.epl.geometry.Geometry.GeometryType.Envelope)
            {
                com.epl.geometry.Polygon polygon = new com.epl.geometry.Polygon();
                polygon.AddEnvelope((com.epl.geometry.Envelope)geom, false);
                proxmityTestGeom = polygon;
                gt = com.epl.geometry.Geometry.GeometryType.Polygon;
            }
            switch (gt)
            {
            case com.epl.geometry.Geometry.GeometryType.Point:
            {
                return(PointGetNearestVertex((com.epl.geometry.Point)proxmityTestGeom, inputPoint2D));
            }

            case com.epl.geometry.Geometry.GeometryType.MultiPoint:
            {
                return(MultiVertexGetNearestVertex((com.epl.geometry.MultiVertexGeometry)proxmityTestGeom, inputPoint2D));
            }

            case com.epl.geometry.Geometry.GeometryType.Polyline:
            case com.epl.geometry.Geometry.GeometryType.Polygon:
            {
                return(MultiPathGetNearestCoordinate((com.epl.geometry.MultiPath)proxmityTestGeom, inputPoint2D, bTestPolygonInterior, bCalculateLeftRightSide));
            }

            default:
            {
                throw new com.epl.geometry.GeometryException("not implemented");
            }
            }
        }
        internal static com.epl.geometry.Geometry PointMinusPolyline_(com.epl.geometry.Point point, com.epl.geometry.Polyline polyline, double tolerance, com.epl.geometry.ProgressTracker progress_tracker)
        {
            com.epl.geometry.Point2D         pt       = point.GetXY();
            com.epl.geometry.SegmentIterator seg_iter = polyline.QuerySegmentIterator();
            double tolerance_cluster    = tolerance * System.Math.Sqrt(2.0) * 1.00001;
            double tolerance_cluster_sq = tolerance_cluster * tolerance_cluster;

            com.epl.geometry.Envelope2D env = new com.epl.geometry.Envelope2D();
            while (seg_iter.NextPath())
            {
                while (seg_iter.HasNextSegment())
                {
                    com.epl.geometry.Segment segment = seg_iter.NextSegment();
                    segment.QueryEnvelope2D(env);
                    env.Inflate(tolerance_cluster, tolerance_cluster);
                    if (!env.Contains(pt))
                    {
                        continue;
                    }
                    if (segment.IsIntersecting(pt, tolerance))
                    {
                        return(point.CreateInstance());
                    }
                    // check segment end points to the cluster tolerance
                    com.epl.geometry.Point2D end_point = segment.GetStartXY();
                    if (com.epl.geometry.Point2D.SqrDistance(pt, end_point) <= tolerance_cluster_sq)
                    {
                        return(point.CreateInstance());
                    }
                    end_point = segment.GetEndXY();
                    if (com.epl.geometry.Point2D.SqrDistance(pt, end_point) <= tolerance_cluster_sq)
                    {
                        return(point.CreateInstance());
                    }
                }
            }
            return(point);
        }
        internal static com.epl.geometry.Geometry PointMinusMultiPoint_(com.epl.geometry.Point point, com.epl.geometry.MultiPoint multi_point, double tolerance, com.epl.geometry.ProgressTracker progress_tracker)
        {
            com.epl.geometry.MultiPointImpl       multipointImpl = (com.epl.geometry.MultiPointImpl)(multi_point._getImpl());
            com.epl.geometry.AttributeStreamOfDbl position       = (com.epl.geometry.AttributeStreamOfDbl)multipointImpl.GetAttributeStreamRef(com.epl.geometry.VertexDescription.Semantics.POSITION);
            int point_count = multi_point.GetPointCount();

            com.epl.geometry.Point2D point2D = point.GetXY();
            com.epl.geometry.Point2D pt      = new com.epl.geometry.Point2D();
            double tolerance_cluster         = tolerance * System.Math.Sqrt(2.0) * 1.00001;
            double tolerance_cluster_sq      = tolerance_cluster * tolerance_cluster;

            for (int i = 0; i < point_count; i++)
            {
                position.Read(2 * i, pt);
                double sqr_dist = com.epl.geometry.Point2D.SqrDistance(pt, point2D);
                if (sqr_dist <= tolerance_cluster_sq)
                {
                    return(point.CreateInstance());
                }
            }
            // return an empty point.
            return(point);
        }
 private static int QuickTest2DPolygonPoint(com.epl.geometry.Polygon geomA, com.epl.geometry.Point geomB, double tolerance)
 {
     com.epl.geometry.Point2D ptB;
     ptB = geomB.GetXY();
     return(QuickTest2DPolygonPoint(geomA, ptB, tolerance));
 }
 public virtual void Intersect(double tolerance, com.epl.geometry.Point pt_intersector_point, int point_rank, double point_weight, bool b_intersecting)
 {
     pt_intersector_point.CopyTo(m_point);
     if (m_input_segments.Count != 1)
     {
         throw com.epl.geometry.GeometryException.GeometryInternalError();
     }
     m_tolerance = tolerance;
     com.epl.geometry.SegmentIntersector.IntersectionPart part1 = m_input_segments[0];
     if (b_intersecting || part1.seg._isIntersectingPoint(pt_intersector_point.GetXY(), tolerance, true))
     {
         if (part1.seg.GetType().Value() == com.epl.geometry.Geometry.GeometryType.Line)
         {
             com.epl.geometry.Line line_1 = (com.epl.geometry.Line)(part1.seg);
             double t1 = line_1.GetClosestCoordinate(pt_intersector_point.GetXY(), false);
             m_param_1[0] = t1;
             // For each point of intersection, we calculate a weighted point
             // based on the ranks and weights of the endpoints and the
             // interior.
             int    rank1   = part1.rank_interior;
             double weight1 = 1.0;
             if (t1 == 0)
             {
                 rank1   = part1.rank_start;
                 weight1 = part1.weight_start;
             }
             else
             {
                 if (t1 == 1.0)
                 {
                     rank1   = part1.rank_end;
                     weight1 = part1.weight_end;
                 }
             }
             int    rank2   = point_rank;
             double weight2 = point_weight;
             double ptWeight;
             com.epl.geometry.Point2D pt = new com.epl.geometry.Point2D();
             if (rank1 == rank2)
             {
                 // for equal ranks use weighted sum
                 com.epl.geometry.Point2D pt_1 = new com.epl.geometry.Point2D();
                 line_1.GetCoord2D(t1, pt_1);
                 com.epl.geometry.Point2D pt_2 = pt_intersector_point.GetXY();
                 ptWeight = weight1 + weight2;
                 double t = weight2 / ptWeight;
                 com.epl.geometry.MathUtils.Lerp(pt_1, pt_2, t, pt);
             }
             else
             {
                 // for non-equal ranks, the higher rank wins
                 if (rank1 > rank2)
                 {
                     pt = new com.epl.geometry.Point2D();
                     line_1.GetCoord2D(t1, pt);
                     ptWeight = weight1;
                 }
                 else
                 {
                     pt       = pt_intersector_point.GetXY();
                     ptWeight = weight2;
                 }
             }
             // Split the line_1, making sure the endpoints are adusted to
             // the weighted
             double t0    = 0;
             int    i0    = -1;
             int    count = 1;
             for (int i = 0; i <= count; i++)
             {
                 double t = i < count ? m_param_1[i] : 1.0;
                 if (t != t0)
                 {
                     com.epl.geometry.SegmentBuffer seg_buffer = NewSegmentBuffer_();
                     line_1.Cut(t0, t, seg_buffer);
                     if (i0 != -1)
                     {
                         seg_buffer.Get().SetStartXY(pt);
                     }
                     if (i != count)
                     {
                         seg_buffer.Get().SetEndXY(pt);
                     }
                     t0 = t;
                     m_result_segments_1.Add(NewIntersectionPart_(seg_buffer.Get()));
                 }
                 i0 = i;
             }
             m_point.SetXY(pt);
             return;
         }
         throw com.epl.geometry.GeometryException.GeometryInternalError();
     }
 }