Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HL-3.2-MonoMigration/HeuristicLab.Visualization/Transform.cs @ 4075

Last change on this file since 4075 was 635, checked in by mstoeger, 16 years ago

Imported charting framework sources into HeuristicLab.Visualization (#294)

File size: 2.3 KB
Line 
1using System.Drawing;
2
3namespace HeuristicLab.Visualization {
4  public static class Transform {
5    // Screen to world transformations
6    public static RectangleD ToWorld(Rectangle rect, Rectangle viewport, RectangleD clippingArea) {
7      double x1 = ToWorldX(rect.Left, viewport, clippingArea);
8      double y1 = ToWorldY(rect.Bottom, viewport, clippingArea);
9      double x2 = ToWorldX(rect.Right, viewport, clippingArea);
10      double y2 = ToWorldY(rect.Top, viewport, clippingArea);
11      return new RectangleD(x1, y1, x2, y2);
12    }
13
14    public static PointD ToWorld(Point point, Rectangle viewport, RectangleD clippingArea) {
15      double x = ToWorldX(point.X, viewport, clippingArea);
16      double y = ToWorldY(point.Y, viewport, clippingArea);
17      return new PointD(x, y);
18    }
19
20    public static double ToWorldX(int x, Rectangle viewport, RectangleD clippingArea) {
21      return clippingArea.X1 + clippingArea.Width/viewport.Width*(x - viewport.Left);
22    }
23
24    public static double ToWorldY(int y, Rectangle viewport, RectangleD clippingArea) {
25      return clippingArea.Y1 - clippingArea.Height/viewport.Height*(y - viewport.Bottom);
26    }
27
28    // World to screen transformations
29    public static Rectangle ToScreen(RectangleD rect, Rectangle viewport, RectangleD clippingArea) {
30      int left = ToScreenX(rect.X1, viewport, clippingArea);
31      int bottom = ToScreenY(rect.Y1, viewport, clippingArea);
32      int right = ToScreenX(rect.X2, viewport, clippingArea);
33      int top = ToScreenY(rect.Y2, viewport, clippingArea);
34      return new Rectangle(left, top, right - left + 1, bottom - top + 1);
35    }
36
37    public static Point ToScreen(PointD point, Rectangle viewport, RectangleD clippingArea) {
38      int x = ToScreenX(point.X, viewport, clippingArea);
39      int y = ToScreenY(point.Y, viewport, clippingArea);
40      return new Point(x, y);
41    }
42
43    public static int ToScreenX(double x, Rectangle viewport, RectangleD clippingArea) {
44      return (int)(viewport.Left + viewport.Width/clippingArea.Width*(x - clippingArea.X1));
45    }
46
47    public static int ToScreenY(double y, Rectangle viewport, RectangleD clippingArea) {
48      return (int)(viewport.Bottom - viewport.Height/clippingArea.Height*(y - clippingArea.Y1));
49    }
50  }
51}
Note: See TracBrowser for help on using the repository browser.