1 /******************************************************************************* 2 * Copyright (c) 2000, 2008 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 org.eclipse.swt.graphics.Point; 14 15 import java.lang.all; 16 17 18 public import org.eclipse.swt.internal.SerializableCompatibility; 19 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 43 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> 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 equals_t 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 */ 99 override public hash_t toHash () { 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 */ 109 override public String toString () { 110 return Format( "Point {{{}, {}}", x, y ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ 111 } 112 113 } 114