KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jcckit > util > Point


1 /*
2  * Copyright 2003-2004, Franz-Josef Elmer, All rights reserved
3  *
4  * This library is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation; either version 2.1 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details
13  * (http://www.gnu.org/copyleft/lesser.html).
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package jcckit.util;
20
21 /**
22  * Immutable class of a two-dimensional point with floating point
23  * coordinates.
24  *
25  * @author Franz-Josef Elmer
26  */

27 public class Point {
28   private final double _x;
29   private final double _y;
30
31   /**
32    * Creates an instance for the specified vector. The value of the
33    * first/second element of <tt>vector</tt> denotes the x/y value.
34    * If <tt>vector</tt> is <tt>null</tt> or not long enough 0 will be used
35    * as default values.
36    */

37   public Point(double[] vector) {
38     double x = 0;
39     double y = 0;
40     if (vector != null && vector.length > 0) {
41       x = vector[0];
42       if (vector.length > 1) {
43         y = vector[1];
44       }
45     }
46     _x = x;
47     _y = y;
48   }
49
50   /** Creates an instance for the specified coordinates. */
51   public Point(double x, double y) {
52     _x = x;
53     _y = y;
54   }
55
56   /** Returns the x-coordinate of the point. */
57   public double getX() {
58     return _x;
59   }
60
61   /** Returns the y-coordinate of the point. */
62   public double getY() {
63     return _y;
64   }
65 }
66
Popular Tags