001/* ===========================================================
002 * Orson Charts : a 3D chart library for the Java(tm) platform
003 * ===========================================================
004 * 
005 * (C)opyright 2013-2022, by David Gilbert.  All rights reserved.
006 * 
007 * https://github.com/jfree/orson-charts
008 * 
009 * This program is free software: you can redistribute it and/or modify
010 * it under the terms of the GNU General Public License as published by
011 * the Free Software Foundation, either version 3 of the License, or
012 * (at your option) any later version.
013 *
014 * This program is distributed in the hope that it will be useful,
015 * but WITHOUT ANY WARRANTY; without even the implied warranty of
016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017 * GNU General Public License for more details.
018 *
019 * You should have received a copy of the GNU General Public License
020 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
021 * 
022 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 
023 * Other names may be trademarks of their respective owners.]
024 * 
025 * If you do not wish to be bound by the terms of the GPL, an alternative
026 * commercial license can be purchased.  For details, please see visit the
027 * Orson Charts home page:
028 * 
029 * http://www.object-refinery.com/orsoncharts/index.html
030 * 
031 */
032
033package org.jfree.chart3d.graphics3d;
034
035import java.io.Serializable;
036
037/**
038 * An offset {@code (dx, dy, dz)} in three dimensional space.  Instances 
039 * of this class are immutable.
040 * <br><br>
041 * NOTE: This class is serializable, but the serialization format is subject 
042 * to change in future releases and should not be relied upon for persisting 
043 * instances of this class. 
044 * 
045 * @since 1.3
046 */
047@SuppressWarnings("serial")
048public final class Offset3D implements Serializable {
049    
050    /** Zero offset. */
051    public static final Offset3D ZERO_OFFSET = new Offset3D(0, 0, 0);
052    
053    /** The x-offset. */
054    private double dx;
055    
056    /** The y-offset. */
057    private double dy;
058    
059    /** The z-offset. */
060    private double dz;
061    
062    /**
063     * Default constructor ({@code (0, 0)}).
064     */
065    public Offset3D() {
066        this(0.0, 0.0, 0.0);
067    }
068    
069    /**
070     * Creates a new instance.
071     * 
072     * @param dx  the x-offset.
073     * @param dy  the y-offset.
074     * @param dz  the z-offset.
075     */
076    public Offset3D(double dx, double dy, double dz) {
077        this.dx = dx;
078        this.dy = dy;
079        this.dz = dz;
080    }
081    
082    /**
083     * Returns the x-offset.
084     * 
085     * @return The x-offset. 
086     */
087    public double getDX() {
088        return this.dx;
089    }
090    
091    /**
092     * Returns the y-offset.
093     * 
094     * @return The y-offset. 
095     */
096    public double getDY() {
097        return this.dy;
098    }
099    
100    /**
101     * Returns the z-offset.
102     * 
103     * @return The z-offset. 
104     */    
105    public double getDZ() {
106        return this.dz;
107    }
108    
109    /**
110     * Tests this instance for equality with an arbitrary object.
111     * 
112     * @param obj  the object ({@code null} permitted).
113     * 
114     * @return A boolean. 
115     */
116    @Override
117    public boolean equals(Object obj) {
118        if (obj == this) {
119            return true;
120        }
121        if (!(obj instanceof Offset3D)) {
122            return false;
123        }
124        Offset3D that = (Offset3D) obj;
125        if (this.dx != that.dx) {
126            return false;
127        }
128        if (this.dy != that.dy) {
129            return false;
130        }
131        if (this.dz != that.dz) {
132            return false;
133        }
134        return true;
135    }
136
137    @Override
138    public int hashCode() {
139        int hash = 7;
140        hash = 97 * hash + (int) (Double.doubleToLongBits(this.dx) 
141                ^ (Double.doubleToLongBits(this.dx) >>> 32));
142        hash = 97 * hash + (int) (Double.doubleToLongBits(this.dy) 
143                ^ (Double.doubleToLongBits(this.dy) >>> 32));
144        hash = 97 * hash + (int) (Double.doubleToLongBits(this.dz) 
145                ^ (Double.doubleToLongBits(this.dz) >>> 32));
146        return hash;
147    }
148
149    @Override
150    public String toString() {
151        return "[" + this.dx + ", " + this.dy + ", " + this.dz + "]";
152    }
153}