Changeset 1234 for trunk/sources/HeuristicLab.Visualization/Transform.cs
- Timestamp:
- 02/28/09 23:12:10 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Visualization/Transform.cs
r931 r1234 2 2 3 3 namespace HeuristicLab.Visualization { 4 /// <summary> 5 /// GDI (or screen) coordinate system 6 /// The GDI coordinate system is specified in pixels. X goes from left to right 7 /// and Y goes from top to bottom. 8 /// 9 /// World coordinate system 10 /// A world coordinate system can be freely specified. X goes from left to 11 /// right and Y goes from bottom to top. 12 /// 13 /// The transformation between world- and screen-coordinate systems is done using 14 /// a view port and a clipping area. 15 /// </summary> 4 16 public static class Transform { 5 6 17 /// <summary> 7 /// Screen to world transformations18 /// Transforms a rectangle in screen coordinates to world coordinates 8 19 /// </summary> 9 /// <param name="rect"> </param>10 /// <param name="viewport"> </param>11 /// <param name="clippingArea"> </param>12 /// <returns> </returns>20 /// <param name="rect">The rectangle in screen coordinates that should be transformed</param> 21 /// <param name="viewport">The target view port</param> 22 /// <param name="clippingArea">The target clipping area</param> 23 /// <returns>The rectangle rect transformed to world coordinates</returns> 13 24 public static RectangleD ToWorld(Rectangle rect, Rectangle viewport, RectangleD clippingArea) { 14 25 double x1 = ToWorldX(rect.Left, viewport, clippingArea); … … 19 30 } 20 31 32 /// <summary> 33 /// Transforms a 2d point in screen coordinates to world coordinates 34 /// </summary> 35 /// <param name="point">The point in screen coordinates that should be transformed</param> 36 /// <param name="viewport">The target view port</param> 37 /// <param name="clippingArea">The target clipping area</param> 38 /// <returns>The point transformed to world coordinates</returns> 21 39 public static PointD ToWorld(Point point, Rectangle viewport, RectangleD clippingArea) { 22 40 double x = ToWorldX(point.X, viewport, clippingArea); … … 25 43 } 26 44 45 /// <summary> 46 /// Transforms a point on the X-axis in screen coordinates to world coordinates 47 /// </summary> 48 /// <param name="x">The point on the X-axis in screen coordinates that should be transformed</param> 49 /// <param name="viewport">The target view port</param> 50 /// <param name="clippingArea">The target clipping area</param> 51 /// <returns>The point transformed to world coordinates</returns> 27 52 public static double ToWorldX(int x, Rectangle viewport, RectangleD clippingArea) { 28 53 return clippingArea.X1 + clippingArea.Width/viewport.Width*(x - viewport.Left); 29 54 } 30 55 56 /// <summary> 57 /// Transforms a point on the Y-axis in screen coordinates to world coordinates 58 /// </summary> 59 /// <param name="y">The point on the Y-axis in screen coordinates that should be transformed</param> 60 /// <param name="viewport">The target view port</param> 61 /// <param name="clippingArea">The target clipping area</param> 62 /// <returns>The point transformed to world coordinates</returns> 31 63 public static double ToWorldY(int y, Rectangle viewport, RectangleD clippingArea) { 32 64 return clippingArea.Y1 - clippingArea.Height/viewport.Height*(y - viewport.Bottom); … … 34 66 35 67 /// <summary> 36 /// World to screen transformations68 /// Transforms a rectangle in world coordinates to screen coordinates 37 69 /// </summary> 38 /// <param name="rect"> </param>39 /// <param name="viewport"> </param>40 /// <param name="clippingArea"> </param>41 /// <returns> </returns>70 /// <param name="rect">The rectangle in world coordinates that should be transformed</param> 71 /// <param name="viewport">The target view port</param> 72 /// <param name="clippingArea">The target clipping area</param> 73 /// <returns>The rectangle rect transformed to screen coordinates</returns> 42 74 public static Rectangle ToScreen(RectangleD rect, Rectangle viewport, RectangleD clippingArea) { 43 75 int left = ToScreenX(rect.X1, viewport, clippingArea); … … 48 80 } 49 81 82 /// <summary> 83 /// Transforms a 2d point in world coordinates to screen coordinates 84 /// </summary> 85 /// <param name="point">The point in world coordinates that should be transformed</param> 86 /// <param name="viewport">The target view port</param> 87 /// <param name="clippingArea">The target clipping area</param> 88 /// <returns>The point transformed to screen coordinates</returns> 50 89 public static Point ToScreen(PointD point, Rectangle viewport, RectangleD clippingArea) { 51 90 int x = ToScreenX(point.X, viewport, clippingArea); … … 54 93 } 55 94 95 /// <summary> 96 /// Transforms a point on the X-axis in world coordinates to screen coordinates 97 /// </summary> 98 /// <param name="x">The point on the X-axis in world coordinates that should be transformed</param> 99 /// <param name="viewport">The target view port</param> 100 /// <param name="clippingArea">The target clipping area</param> 101 /// <returns>The point transformed to screen coordinates</returns> 56 102 public static int ToScreenX(double x, Rectangle viewport, RectangleD clippingArea) { 57 103 return (int)(viewport.Left + viewport.Width/clippingArea.Width*(x - clippingArea.X1)); 58 104 } 59 105 106 /// <summary> 107 /// Transforms a point on the Y-axis in world coordinates to screen coordinates 108 /// </summary> 109 /// <param name="y">The point on the Y-axis in world coordinates that should be transformed</param> 110 /// <param name="viewport">The target view port</param> 111 /// <param name="clippingArea">The target clipping area</param> 112 /// <returns>The point transformed to screen coordinates</returns> 60 113 public static int ToScreenY(double y, Rectangle viewport, RectangleD clippingArea) { 61 114 return (int)(viewport.Bottom - viewport.Height/clippingArea.Height*(y - clippingArea.Y1));
Note: See TracChangeset
for help on using the changeset viewer.