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