예제 #1
0
        private static string ToString(Point p)
        {
            if (p == null)
            {
                return("");
            }
            if (p.IsEmpty())
            {
                return("Empty");
            }

            return(string.Format("({0}, {1})", p.X, p.Y));
        }
예제 #2
0
        /// <summary>
        /// Transforms from world coordinate system (WCS) to image coordinates
        /// NOTE: This method DOES NOT take the MapTransform property into account (use SharpMap.Map.MapToWorld instead)
        /// </summary>
        /// <param name="p">Point in WCS</param>
        /// <param name="map">Map reference</param>
        /// <returns>Point in image coordinates</returns>
        public static PointF WorldtoMap(Point p, Map map)
        {
            //if (map.MapTransform != null && !map.MapTransform.IsIdentity)
            //	map.MapTransform.TransformPoints(new System.Drawing.PointF[] { p });
            PointF result = new System.Drawing.Point();
            if (p.IsEmpty() == true)
                return PointF.Empty;

            double height = (map.Zoom * map.Size.Height) / map.Size.Width;
            double left = map.Center.X - map.Zoom * 0.5;
            double top = map.Center.Y + height * 0.5 * map.PixelAspectRatio;
            result.X = (float)((p.X - left) / map.PixelWidth);
            result.Y = (float)((top - p.Y) / map.PixelHeight);
            if (double.IsNaN(result.X) || double.IsNaN(result.Y))
                result = PointF.Empty;
            return result;
        }
예제 #3
0
        /// <summary>
        /// Checks whether min values are actually smaller than max values and in that case swaps them.
        /// </summary>
        /// <returns>true if the bounding was changed</returns>
        public bool CheckMinMax()
        {
            bool wasSwapped = false;

            if (!_min.IsEmpty() && !_max.IsEmpty())
            {
                if (_min.X > _max.X)
                {
                    double tmp = _min.X;
                    _min.X     = _max.X;
                    _max.X     = tmp;
                    wasSwapped = true;
                }
                if (_min.Y > _max.Y)
                {
                    double tmp = _min.Y;
                    _min.Y     = _max.Y;
                    _max.Y     = tmp;
                    wasSwapped = true;
                }
            }
            return(wasSwapped);
        }
예제 #4
0
        /// <summary>
        /// Transforms from world coordinate system (WCS) to image coordinates
        /// NOTE: This method DOES NOT take the MapTransform property into account (use SharpMap.Map.MapToWorld instead)
        /// </summary>
        /// <param name="p">Point in WCS</param>
        /// <param name="map">Map reference</param>
        /// <returns>Point in image coordinates</returns>
        public static PointF WorldtoMap(Point p, Map map)
        {
            //if (map.MapTransform != null && !map.MapTransform.IsIdentity)
            //	map.MapTransform.TransformPoints(new System.Drawing.PointF[] { p });
            PointF result = new System.Drawing.Point();

            if (p.IsEmpty() == true)
            {
                return(PointF.Empty);
            }

            double height = (map.Zoom * map.Size.Height) / map.Size.Width;
            double left   = map.Center.X - map.Zoom * 0.5;
            double top    = map.Center.Y + height * 0.5 * map.PixelAspectRatio;

            result.X = (float)((p.X - left) / map.PixelWidth);
            result.Y = (float)((top - p.Y) / map.PixelHeight);
            if (double.IsNaN(result.X) || double.IsNaN(result.Y))
            {
                result = PointF.Empty;
            }
            return(result);
        }