Beispiel #1
0
        /// <summary>
        /// Get projection from certain point
        /// </summary>
        /// <param name="p"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public int ProjectFrom(GeoPoint p, out GeoPoint result, out int segIdx)
        {
            int      type      = -1;
            double   minDist   = double.PositiveInfinity;
            GeoPoint tmpResult = GeoPoint.INVALID;

            result = GeoPoint.INVALID;
            segIdx = 0;
            for (int i = 0; i < this.points.Count - 1; i++)
            {
                int    tmpType = Polyline.ProjectFrom(points[i], points[i + 1], p, out tmpResult);
                double tmpDist = GeoPoint.GetDistance2(tmpResult, p);

                if (tmpDist <= minDist)
                {
                    if (tmpType == 0 || type != 0)
                    {
                        //good projection is true or tmpType==0
                        type    = tmpType;
                        minDist = tmpDist;
                        result  = tmpResult;
                        segIdx  = i;
                    }
                }
                //break;
            }
            return(type);
        }
Beispiel #2
0
        public double Dist2From(GeoPoint p, out int type)
        {
            GeoPoint projection;
            int      segIdx;

            type = ProjectFrom(p, out projection, out segIdx);
            return(GeoPoint.GetDistance2(projection, p));
        }