package com.javaranch.common ; import java.io.* ; /** A very lean serialized point type where X and Y are of type double.
Should the day ever arise that everyone supports Java 1.2 or higher, this class should inherit Point2D.Double.
- - - - - - - - - - - - - - - - -
Copyright (c) 1998-2000 Paul Wheaton
You are welcome to do whatever you want to with this source file provided that you maintain this comment fragment (between the dashed lines). Modify it, change the package name, change the class name ... personal or business use ... sell it, share it ... add a copyright for the portions you add ...
My goal in giving this away and maintaining the copyright is to hopefully direct developers back to JavaRanch.
The original source can be found at JavaRanch
- - - - - - - - - - - - - - - - -
@author Paul Wheaton */ public class DPoint implements Serializable { private double x ; private double y ; /** Create a double point object initialized to 0.0,0.0.
*/ public DPoint() { // already set to 0.0, 0.0 } /** Create a double point object initialized to x,y.
@param x The x coordinate.
@param y The y coordinate.
*/ public DPoint( double x , double y ) { this.x = x ; this.y = y ; } public void setX( double x ) { this.x = x ; } public double getX() { return x ; } public void setY( double y ) { this.y = y ; } public double getY() { return y ; } public void set( double x , double y ) { this.x = x ; this.y = y ; } /** Increment x (negative numbers decrement x).
@param inc The amount to adjust x.
*/ public void incX( double inc ) { x += inc ; } /** Increment y (negative numbers decrement y).
@param inc The amount to adjust y.
*/ public void incY( double inc ) { y += inc ; } /** returns something like "(35.8765,20.0042)".
*/ public String toString() { return "(" + x + "," + y + ")" ; } public boolean equals( Object obj ) { boolean returnVal = false ; if ( obj instanceof DPoint ) { DPoint p = (DPoint) obj ; if ( ( p.x == x ) && ( p.y == y ) ) { returnVal = true ; } } return returnVal ; } /** Provided for testing purposes only.
*/ public static void unitTest( TestLog log ) { // xxx need tests } }