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