Point.java revision 9066cfe9886ac131c34d59ed0e2d287b0e3c0087
1/* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package android.graphics; 18 19 20/** 21 * Point holds two integer coordinates 22 */ 23public class Point { 24 public int x; 25 public int y; 26 27 public Point() {} 28 29 public Point(int x, int y) { 30 this.x = x; 31 this.y = y; 32 } 33 34 public Point(Point src) { 35 this.x = src.x; 36 this.y = src.y; 37 } 38 39 /** 40 * Set the point's x and y coordinates 41 */ 42 public void set(int x, int y) { 43 this.x = x; 44 this.y = y; 45 } 46 47 /** 48 * Negate the point's coordinates 49 */ 50 public final void negate() { 51 x = -x; 52 y = -y; 53 } 54 55 /** 56 * Offset the point's coordinates by dx, dy 57 */ 58 public final void offset(int dx, int dy) { 59 x += dx; 60 y += dy; 61 } 62 63 /** 64 * Returns true if the point's coordinates equal (x,y) 65 */ 66 public final boolean equals(int x, int y) { 67 return this.x == x && this.y == y; 68 } 69 70 @Override public boolean equals(Object o) { 71 if (o instanceof Point) { 72 Point p = (Point) o; 73 return this.x == p.x && this.y == p.y; 74 } 75 return false; 76 } 77 78 @Override public int hashCode() { 79 return x * 32713 + y; 80 } 81 82 @Override public String toString() { 83 return "Point(" + x + ", " + y+ ")"; 84 } 85} 86