Display.DiagramToControl() issue

Mar 13, 2013 at 11:10 AM
Edited Mar 13, 2013 at 11:19 AM
Hi,

Method Display.DiagramToControl() looks like this:
        /// <summary>
        /// Transformes diagram coordinates to control coordinates
        /// </summary>
        public void DiagramToControl(Rectangle dRect, out Rectangle cRect) {
            cRect = Rectangle.Empty;
            cRect.Offset(
                diagramPosX + (int)Math.Round((dRect.X - scrollPosX) * zoomfactor),
                diagramPosY + (int)Math.Round((dRect.Y - scrollPosY) * zoomfactor)
                );
            cRect.Width = (int)Math.Round(dRect.Width * zoomfactor);
            cRect.Height = (int)Math.Round(dRect.Height * zoomfactor);
        }
If, having zoomfactor = 1.0, we pass to this method a rectangle having Width (or Height) equal to int.MaxValue, the output rectangle will have Width (or Height) equal to int.MinValue. Try the following code:
var x = (int)Math.Round(int.MaxValue * 1f)
-- you'll see that x is equal to int.MinValue.

You may ask why do I need to pass such rectangle to this method? Well, this rectangle is a "cursor clipping rectangle", and if we suppose (just for example, and having zoom factor 1.0) that its Width is set to int.MaxValue, Height - to 120, X - to int.MinValue / 2 and Y - to 20 (in diagram coordinates!), it means that the cursor movement is restricted only along the vertical axis (from Y = 20 to Y = 140), and is NOT restricted along the horizontal axis. But trying to recalculate this clipping rectangle from diagram coordinates to Display ones - fails.

I would be glad to use some other values instead of int.MinValue and int.MaxValue (to denote that no clipping happens), but Diagram's location and size are not limited by the Display component boundaries - e.g. Diagram's location (X and Y) can obtain negative values! and these values seem to have no limits!

Besides, I can't just use int.MinValue and int.MaxValue because it's OK only with zoom factor = 1.0; for bigger values of the zoom factor I have to use smaller values.

Maybe I was not very clear, sorry.
Coordinator
Mar 14, 2013 at 10:24 AM
I'm not sure what you expect us to do in this case...
I would suggest to use short.MaxValue or ushort.MaxValue for the cursor clipping.
The value range should be large enough for this purpose.
Mar 14, 2013 at 10:27 AM
What about simply modifying the DiagramToControl() method so that it will (a) more accurately handle rounding, and (b) treat int.MinValue and int.MaxValue as "special values" which must be kept unchanged?
Mar 14, 2013 at 10:27 AM
What about simply modifying the DiagramToControl() method so that it will (a) more accurately handle rounding, and (b) treat int.MinValue and int.MaxValue as "special values" which must be kept unchanged?