* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package droid.geom;
import droid.misc.Angle;
import android.graphics.PointF;
/**
* flash.geom.Point implementation
* @author Mj Mendoza IV
*
* The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
*/
public class Point {
/**
* Creates a new point.
*/
public Point() {
setX(0);
setY(0);
}
/**
* Creates a new point.
*/
public Point(double x) {
setX(x);
setY(0);
}
/**
* Creates a new point.
*/
public Point(double x, double y) {
setX(x);
setY(y);
}
/**
* Not to be used for manual/direct manipulation.
* @see droid.geom.Point.setX()
* @see droid.geom.Point.getX()
*/
public double x;
/**
* Returns he horizontal coordinate of the point.
*/
public double getX() {
setX(x);
return x;
}
/**
* Sets the horizontal coordinate of the point.
*/
public void setX(double x) {
this.x = x;
getLength();
}
/**
* Not to be used for manual/direct manipulation.
* @see droid.geom.Point.setY()
* @see droid.geom.Point.getY()
*/
public double y;
/**
* Returns the vertical coordinate of the point.
*/
public double getY() {
setY(y);
return y;
}
/**
* Sets the vertical coordinate of the point.
*/
public void setY(double y) {
this.y = y;
getLength();
}
/**
* Not to be used for manual/direct manipulation.
* @see droid.geom.Point.setLength()
* @see droid.geom.Point.getLength()
*/
public double length;
/**
* Sets the length of the line segment from (0,0) to this point.
* @param length
*/
public void setLength(double length) {
Point tmp = Point.polar(length, Angle.getAngleByRadians(getX(), getY()));
this.setX(tmp.x);
this.setY(tmp.y);
}
/**
* Returns the length of the line segment from (0,0) to this point.
*/
public double getLength() {
length = PointF.length((float) x, (float) y);
return length;
}
/**
* Adds the coordinates of another point to the coordinates of this point to create a new point.
* @param v
* @return
*/
public Point add(Point v) {
return new Point(x + v.x, y + v.y);
}
/**
* Creates a copy of the Point object.
*/
public Point clone() {
return new Point(x, y);
}
/**
* Returns the distance between pt1 and pt2.
* @param pt1
* @param pt2
* @return
*/
public static double distance(Point pt1, Point pt2) {