Mercurial > projects > dwt-mac
comparison dwt/graphics/Point.d @ 0:380af2bdd8e5
Upload of whole dwt tree
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Sat, 09 Aug 2008 17:00:02 +0200 |
parents | |
children | ab8b5765e3d1 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:380af2bdd8e5 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2005 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 *******************************************************************************/ | |
11 module dwt.graphics.Point; | |
12 | |
13 import dwt.dwthelper.utils; | |
14 | |
15 import dwt.internal.SerializableCompatibility; | |
16 | |
17 /** | |
18 * Instances of this class represent places on the (x, y) | |
19 * coordinate plane. | |
20 * <p> | |
21 * The coordinate space for rectangles and points is considered | |
22 * to have increasing values downward and to the right from its | |
23 * origin making this the normal, computer graphics oriented notion | |
24 * of (x, y) coordinates rather than the strict mathematical one. | |
25 * </p> | |
26 * <p> | |
27 * The hashCode() method in this class uses the values of the public | |
28 * fields to compute the hash value. When storing instances of the | |
29 * class in hashed collections, do not modify these fields after the | |
30 * object has been inserted. | |
31 * </p> | |
32 * <p> | |
33 * Application code does <em>not</em> need to explicitly release the | |
34 * resources managed by each instance when those instances are no longer | |
35 * required, and thus no <code>dispose()</code> method is provided. | |
36 * </p> | |
37 * | |
38 * @see Rectangle | |
39 */ | |
40 | |
41 public final class Point implements SerializableCompatibility { | |
42 | |
43 /** | |
44 * the x coordinate of the point | |
45 */ | |
46 public int x; | |
47 | |
48 /** | |
49 * the y coordinate of the point | |
50 */ | |
51 public int y; | |
52 | |
53 static final long serialVersionUID = 3257002163938146354L; | |
54 | |
55 /** | |
56 * Constructs a new point with the given x and y coordinates. | |
57 * | |
58 * @param x the x coordinate of the new point | |
59 * @param y the y coordinate of the new point | |
60 */ | |
61 public Point (int x, int y) { | |
62 this.x = x; | |
63 this.y = y; | |
64 } | |
65 | |
66 /** | |
67 * Compares the argument to the receiver, and returns true | |
68 * if they represent the <em>same</em> object using a class | |
69 * specific comparison. | |
70 * | |
71 * @param object the object to compare with this object | |
72 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise | |
73 * | |
74 * @see #hashCode() | |
75 */ | |
76 public bool equals (Object object) { | |
77 if (object is this) return true; | |
78 if (!(object instanceof Point)) return false; | |
79 Point p = (Point)object; | |
80 return (p.x is this.x) && (p.y is this.y); | |
81 } | |
82 | |
83 /** | |
84 * Returns an integer hash code for the receiver. Any two | |
85 * objects that return <code>true</code> when passed to | |
86 * <code>equals</code> must return the same value for this | |
87 * method. | |
88 * | |
89 * @return the receiver's hash | |
90 * | |
91 * @see #equals(Object) | |
92 */ | |
93 public int hashCode () { | |
94 return x ^ y; | |
95 } | |
96 | |
97 /** | |
98 * Returns a string containing a concise, human-readable | |
99 * description of the receiver. | |
100 * | |
101 * @return a string representation of the point | |
102 */ | |
103 public String toString () { | |
104 return "Point {" + x + ", " + y + "}"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
105 } | |
106 | |
107 } | |
108 |