1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php 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 17 package com.android.ide.common.api; 18 19 import com.google.common.annotations.Beta; 20 import com.android.annotations.NonNull; 21 22 23 /** 24 * Mutable point. 25 * <p> 26 * <b>NOTE: This is not a public or final API; if you rely on this be prepared 27 * to adjust your code for the next tools release.</b> 28 * </p> 29 */ 30 @Beta 31 public class Point { 32 public int x, y; 33 34 public Point(int x, int y) { 35 this.x = x; 36 this.y = y; 37 } 38 39 public Point(@NonNull Point p) { 40 x = p.x; 41 y = p.y; 42 } 43 44 /** Sets the point to the given coordinates. */ 45 public void set(int x, int y) { 46 this.x = x; 47 this.y = y; 48 } 49 50 /** Returns a new instance of a point with the same values. */ 51 @NonNull 52 public Point copy() { 53 return new Point(x, y); 54 } 55 56 /** 57 * Offsets this point by adding the given x,y deltas to the x,y coordinates. 58 * @return Returns self, for chaining. 59 */ 60 @NonNull 61 public Point offsetBy(int x, int y) { 62 this.x += x; 63 this.y += y; 64 return this; 65 } 66 67 @Override 68 public boolean equals(Object obj) { 69 if (obj instanceof Point) { 70 Point rhs = (Point) obj; 71 return this.x == rhs.x && this.y == rhs.y; 72 } 73 return false; 74 } 75 76 @Override 77 public int hashCode() { 78 int h = x ^ ((y >> 16) & 0x0FFFF) ^ ((y & 0x0FFFF) << 16); 79 return h; 80 } 81 82 @Override 83 public String toString() { 84 return String.format("Point [%dx%d]", x, y); 85 } 86 } 87