PointF.java revision 54b6cfa9a9e5b861a9930af873580d6dc20f773c
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 19import android.util.FloatMath; 20 21 22/** 23 * PointF holds two float coordinates 24 */ 25public class PointF { 26 public float x; 27 public float y; 28 29 public PointF() {} 30 31 public PointF(float x, float y) { 32 this.x = x; 33 this.y = y; 34 } 35 36 public PointF(Point p) { 37 this.x = p.x; 38 this.y = p.y; 39 } 40 41 /** 42 * Set the point's x and y coordinates 43 */ 44 public final void set(float x, float y) { 45 this.x = x; 46 this.y = y; 47 } 48 49 /** 50 * Set the point's x and y coordinates to the coordinates of p 51 */ 52 public final void set(PointF p) { 53 this.x = p.x; 54 this.y = p.y; 55 } 56 57 public final void negate() { 58 x = -x; 59 y = -y; 60 } 61 62 public final void offset(float dx, float dy) { 63 x += dx; 64 y += dy; 65 } 66 67 /** 68 * Returns true if the point's coordinates equal (x,y) 69 */ 70 public final boolean equals(float x, float y) { 71 return this.x == x && this.y == y; 72 } 73 74 /** 75 * Return the euclidian distance from (0,0) to the point 76 */ 77 public final float length() { 78 return length(x, y); 79 } 80 81 /** 82 * Returns the euclidian distance from (0,0) to (x,y) 83 */ 84 public static float length(float x, float y) { 85 return FloatMath.sqrt(x * x + y * y); 86 } 87} 88 89