001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2007, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * -----------
028: * Vector.java
029: * -----------
030: * (C) Copyright 2007, by Object Refinery Limited.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: Vector.java,v 1.1.2.1 2007/05/25 14:44:38 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 30-Jan-2007 : Version 1 (DG);
040: * 24-May-2007 : Added getLength() and getAngle() methods, thanks to
041: * matinh (DG);
042: * 25-May-2007 : Moved from experimental to the main source tree (DG);
043: *
044: */
045:
046: package org.jfree.data.xy;
047:
048: import java.io.Serializable;
049:
050: /**
051: * A vector.
052: *
053: * @since 1.0.6
054: */
055: public class Vector implements Serializable {
056:
057: /** The vector x. */
058: private double x;
059:
060: /** The vector y. */
061: private double y;
062:
063: /**
064: * Creates a new instance of <code>Vector</code>.
065: *
066: * @param x the x-component.
067: * @param y the y-component.
068: */
069: public Vector(double x, double y) {
070: this .x = x;
071: this .y = y;
072: }
073:
074: /**
075: * Returns the x-value.
076: *
077: * @return The x-value.
078: */
079: public double getX() {
080: return this .x;
081: }
082:
083: /**
084: * Returns the y-value.
085: *
086: * @return The y-value.
087: */
088: public double getY() {
089: return this .y;
090: }
091:
092: /**
093: * Returns the length of the vector.
094: *
095: * @return The vector length.
096: */
097: public double getLength() {
098: return Math.sqrt((this .x * this .x) + (this .y * this .y));
099: }
100:
101: /**
102: * Returns the angle of the vector.
103: *
104: * @return The angle of the vector.
105: */
106: public double getAngle() {
107: return Math.atan2(this .y, this .x);
108: }
109:
110: /**
111: * Tests this vector for equality with an arbitrary object.
112: *
113: * @param obj the object (<code>null</code> not permitted).
114: *
115: * @return A boolean.
116: */
117: public boolean equals(Object obj) {
118: if (obj == this ) {
119: return true;
120: }
121: if (!(obj instanceof Vector)) {
122: return false;
123: }
124: Vector that = (Vector) obj;
125: if (this .x != that.x) {
126: return false;
127: }
128: if (this .y != that.y) {
129: return false;
130: }
131: return true;
132: }
133:
134: /**
135: * Returns a hash code for this instance.
136: *
137: * @return A hash code.
138: */
139: public int hashCode() {
140: int result = 193;
141: long temp = Double.doubleToLongBits(this .x);
142: result = 37 * result + (int) (temp ^ (temp >>> 32));
143: temp = Double.doubleToLongBits(this .y);
144: result = 37 * result + (int) (temp ^ (temp >>> 32));
145: return result;
146: }
147:
148: }
|