    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)} in two dimensional space.  Instances of
    039 * 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@SuppressWarnings("serial")
    046public final class Offset2D implements Serializable {
    047
    048    /** Zero offset. */
    049    public static final Offset2D ZERO_OFFSET = new Offset2D(0, 0);
    050
    051    /** The x-offset. */
    052    private double dx;
    053
    054    /** The y-offset. */
    055    private double dy;
    056
    057    /**
    058     * Default constructor ({@code (0, 0)}).
    059     */
    060    public Offset2D() {
    061        this(0.0, 0.0);
    062    }
    063
    064    /**
    065     * Creates a new instance.
    066     *
    067     * @param dx  the x-offset.
    068     * @param dy  the y-offset.
    069     */
    070    public Offset2D(double dx, double dy) {
    071        this.dx = dx;
    072        this.dy = dy;
    073    }
    074
    075    /**
    076     * Returns the x-offset.
    077     *
    078     * @return The x-offset.
    079     */
    080    public double getDX() {
    081        return this.dx;
    082    }
    083
    084    /**
    085     * Returns the y-offset.
    086     *
    087     * @return The y-offset.
    088     */
    089    public double getDY() {
    090        return this.dy;
    091    }
    092
    093    /**
    094     * Tests this instance for equality with an arbitrary object.
    095     *
    096     * @param obj  the object ({@code null} permitted).
    097     *
    098     * @return A boolean.
    099     */
    100    @Override
    101    public boolean equals(Object obj) {
    102        if (obj == this) {
    103            return true;
    104        }
    105        if (!(obj instanceof Offset2D)) {
    106            return false;
    107        }
    108        Offset2D that = (Offset2D) obj;
    109        if (this.dx != that.dx) {
    110            return false;
    111        }
    112        if (this.dy != that.dy) {
    113            return false;
    114        }
    115        return true;
    116    }
    117
    118    /**
    119     * Returns a hash code for this instance.
    120     *
    121     * @return A hash code.
    122     */
    123    @Override
    124    public int hashCode() {
    125        int hash = 3;
    126        hash = 59 * hash + (int) (Double.doubleToLongBits(this.dx)
    127                ^ (Double.doubleToLongBits(this.dx) >>> 32));
    128        hash = 59 * hash + (int) (Double.doubleToLongBits(this.dy)
    129                ^ (Double.doubleToLongBits(this.dy) >>> 32));
    130        return hash;
    131    }
    132}