Mercurial > projects > dwt-linux
annotate dwt/graphics/Point.d @ 10:63c023465156
moved from org.eclipse.swt to dwt
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 05 Jan 2008 17:58:37 +0100 |
parents | ad2b69216039 |
children | 8cec8f536af3 |
rev | line source |
---|---|
4 | 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 *******************************************************************************/ | |
10
63c023465156
moved from org.eclipse.swt to dwt
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
11 module dwt.graphics.Point; |
4 | 12 |
13 | |
10
63c023465156
moved from org.eclipse.swt to dwt
Frank Benoit <benoit@tionex.de>
parents:
9
diff
changeset
|
14 public import dwt.internal.SerializableCompatibility; |
4 | 15 |
16 import tango.text.convert.Format; | |
17 | |
18 /** | |
19 * Instances of this class represent places on the (x, y) | |
20 * coordinate plane. | |
21 * <p> | |
22 * The coordinate space for rectangles and points is considered | |
23 * to have increasing values downward and to the right from its | |
24 * origin making this the normal, computer graphics oriented notion | |
25 * of (x, y) coordinates rather than the strict mathematical one. | |
26 * </p> | |
27 * <p> | |
28 * The hashCode() method in this class uses the values of the public | |
29 * fields to compute the hash value. When storing instances of the | |
30 * class in hashed collections, do not modify these fields after the | |
31 * object has been inserted. | |
32 * </p> | |
33 * <p> | |
34 * Application code does <em>not</em> need to explicitly release the | |
35 * resources managed by each instance when those instances are no longer | |
36 * required, and thus no <code>dispose()</code> method is provided. | |
37 * </p> | |
38 * | |
39 * @see Rectangle | |
40 */ | |
41 | |
42 public final class Point : SerializableCompatibility { | |
43 | |
44 /** | |
45 * the x coordinate of the point | |
46 */ | |
47 public int x; | |
48 | |
49 /** | |
50 * the y coordinate of the point | |
51 */ | |
52 public int y; | |
53 | |
54 //static final long serialVersionUID = 3257002163938146354L; | |
55 | |
56 /** | |
57 * Constructs a new point with the given x and y coordinates. | |
58 * | |
59 * @param x the x coordinate of the new point | |
60 * @param y the y coordinate of the new point | |
61 */ | |
62 public this (int x, int y) { | |
63 this.x = x; | |
64 this.y = y; | |
65 } | |
66 | |
67 /** | |
68 * Compares the argument to the receiver, and returns true | |
69 * if they represent the <em>same</em> object using a class | |
70 * specific comparison. | |
71 * | |
72 * @param object the object to compare with this object | |
73 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise | |
74 * | |
75 * @see #hashCode() | |
76 */ | |
77 public override int opEquals (Object object) { | |
78 if (object is this) return true; | |
79 if ( auto p = cast(Point)object ){ | |
80 return (p.x == this.x) && (p.y == this.y); | |
81 } | |
82 return false; | |
83 } | |
84 | |
85 /** | |
86 * Returns an integer hash code for the receiver. Any two | |
87 * objects that return <code>true</code> when passed to | |
88 * <code>equals</code> must return the same value for this | |
89 * method. | |
90 * | |
91 * @return the receiver's hash | |
92 * | |
93 * @see #equals(Object) | |
94 */ | |
95 public hash_t toHash () { | |
96 return x ^ y; | |
97 } | |
98 | |
99 /** | |
100 * Returns a string containing a concise, human-readable | |
101 * description of the receiver. | |
102 * | |
103 * @return a string representation of the point | |
104 */ | |
105 public char[] toString () { | |
106 return Format( "Point {}, {}}", x, y );; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ | |
107 } | |
108 | |
109 } | |
110 |