    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 * A dimension in 3D (width, height and depth).  Instances of this class
    039 * 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 Dimension3D implements Serializable {
    047
    048    /** The width. */
    049    private final double width;
    050
    051    /** The height. */
    052    private final double height;
    053
    054    /** The depth. */
    055    private final double depth;
    056
    057    /**
    058     * Creates a new {@code Dimension3D} instance.  Instances of this
    059     * class are immutable.
    060     *
    061     * @param width  the width.
    062     * @param height  the height.
    063     * @param depth   the depth.
    064     */
    065    public Dimension3D(double width, double height, double depth) {
    066        this.width = width;
    067        this.height = height;
    068        this.depth = depth;
    069    }
    070
    071    /**
    072     * Returns the width.
    073     *
    074     * @return The width.
    075     */
    076    public double getWidth() {
    077        return this.width;
    078    }
    079
    080    /**
    081     * Returns the height.
    082     *
    083     * @return The height.
    084     */
    085    public double getHeight() {
    086        return this.height;
    087    }
    088
    089    /**
    090     * Returns the depth.
    091     *
    092     * @return The depth.
    093     */
    094    public double getDepth() {
    095        return this.depth;
    096    }
    097
    098    /**
    099     * Returns the length of a diagonal from one corner of the box to another.
    100     *
    101     * @return The length.
    102     */
    103    public double getDiagonalLength() {
    104        return Math.sqrt(this.depth * this.depth + this.height * this.height
    105                + this.width * this.width);
    106    }
    107
    108    /**
    109     * Tests this instance for equality with an arbitrary object.
    110     *
    111     * @param obj  the object to test against ({@code null} permitted).
    112     *
    113     * @return A boolean.
    114     */
    115    @Override
    116    public boolean equals(Object obj) {
    117        if (obj == null) {
    118            return false;
    119        }
    120        if (getClass() != obj.getClass()) {
    121            return false;
    122        }
    123        final Dimension3D other = (Dimension3D) obj;
    124        if (Double.doubleToLongBits(this.width) != Double.doubleToLongBits(
    125                other.width)) {
    126            return false;
    127        }
    128        if (Double.doubleToLongBits(this.height) != Double.doubleToLongBits(
    129                other.height)) {
    130            return false;
    131        }
    132        if (Double.doubleToLongBits(this.depth) != Double.doubleToLongBits(
    133                other.depth)) {
    134            return false;
    135        }
    136        return true;
    137    }
    138
    139    /**
    140     * Returns a hash code for this instance.
    141     *
    142     * @return A hash code.
    143     */
    144    @Override
    145    public int hashCode() {
    146        int hash = 7;
    147        hash = 17 * hash + (int) (Double.doubleToLongBits(this.width)
    148                ^ (Double.doubleToLongBits(this.width) >>> 32));
    149        hash = 17 * hash + (int) (Double.doubleToLongBits(this.height)
    150                ^ (Double.doubleToLongBits(this.height) >>> 32));
    151        hash = 17 * hash + (int) (Double.doubleToLongBits(this.depth)
    152                ^ (Double.doubleToLongBits(this.depth) >>> 32));
    153        return hash;
    154    }
    155
    156    /**
    157     * Returns a string representation of this instance, primarily for
    158     * debugging purposes.
    159     *
    160     * @return A string.
    161     */
    162    @Override
    163    public String toString() {
    164        return "[" + this.width + ", " + this.height + ", " + this.depth + "]";
    165    }
    166}