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