]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/gfx/PhysicalDimension.java
Sync git svn branch with SVN repository r33269.
[simantics/platform.git] / bundles / org.simantics.utils.ui / src / org / simantics / utils / ui / gfx / PhysicalDimension.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 /*\r
13  * 10.10.2006\r
14  */\r
15 package org.simantics.utils.ui.gfx;\r
16 \r
17 \r
18 /**\r
19  * PhysicalDimension\r
20  * @author Toni Kalajainen\r
21  */\r
22 public class PhysicalDimension {\r
23 \r
24     /** Width in meters */\r
25     public final double width;\r
26 \r
27     /** height in meters */\r
28     public final double height;\r
29     \r
30     private final int hash;\r
31 \r
32     public PhysicalDimension(double width, double height) {\r
33         this.width = width;\r
34         this.height = height;\r
35         this.hash = makeHash(width, height);\r
36     }\r
37 \r
38     public PhysicalDimension(PixelDimension d) {\r
39         this(d.width, d.height);\r
40     }\r
41     \r
42     public double getHeight() {\r
43         return height;\r
44     }\r
45 \r
46     public double getWidth() {\r
47         return width;\r
48     }\r
49 \r
50     public boolean equals(Object obj) {\r
51         if (!(obj instanceof PixelDimension))\r
52             return false;\r
53         PixelDimension d = (PixelDimension) obj;\r
54         return (width == d.width) && (height == d.height);\r
55     }\r
56 \r
57     public int hashCode() {        \r
58         return hash;\r
59     }\r
60 \r
61     private static int makeHash(Double w, Double h) {\r
62         return w.hashCode() ^ (h.hashCode()*7);\r
63     }\r
64     \r
65     @Override\r
66     public String toString() {\r
67         return "PhysicalDimension [w=" + width + ", h=" + height + "]";\r
68     }\r
69     \r
70     /**\r
71      * returns aspect ratio (width / height)\r
72      * @return returns aspect ratio (width / height)\r
73      */\r
74     public double getAspectRatio()\r
75     {\r
76         return width / height;\r
77     }\r
78     \r
79 }\r