Beispiel #1
0
        public static Vector FromPointToCoordinate(Size canvasSize, CoordinateSystemData data, Vector point)
        {
            double w = canvasSize.Width;
            double h = canvasSize.Height;

            if (h == 0 || w == 0 || double.IsNaN(w) || double.IsNaN(h))
            {
                throw new Exception("Invalid canvas size");
            }

            // Calculate the size of a single (unit) cell while considering the canvas size
            Size cellSize = new Size {
                Width  = w / data.GetCellSize().Width,
                Height = h / data.GetCellSize().Height,
            };

            // TODO: Make sure that this makes sense
            return(new Vector(CalculateCoordinateX(data.MinX, data.MaxX, (point.X / cellSize.Width)),
                              CalculateCoordinateY(data.MinY, data.MaxY, (point.Y / cellSize.Height))));
        }
Beispiel #2
0
        public static Vector FromCoordinateToPoint(Size canvasSize, CoordinateSystemData data, Vector coordinate)
        {
            // Converts a Coordinate into a Point on a canvas considering the canvas size

            double w = canvasSize.Width;
            double h = canvasSize.Height;

            if (h == 0 || w == 0 || double.IsNaN(w) || double.IsNaN(h))
            {
                throw new Exception("Invalid canvas size");
            }

            // Calculate the size of a single (unit) cell while considering the canvas size
            Size cellSize = new Size {
                Width  = w / data.GetCellSize().Width,
                Height = h / data.GetCellSize().Height,
            };

            return(new Vector(CalculatePointX(data.MinX, data.MaxX, coordinate.X) * cellSize.Width,
                              CalculatePointY(data.MinY, data.MaxY, coordinate.Y) * cellSize.Height));
        }