001 //$HeadURL: $ 002 /*---------------- FILE HEADER ------------------------------------------ 003 This file is part of deegree. 004 Copyright (C) 2001-2008 by: 005 Department of Geography, University of Bonn 006 http://www.giub.uni-bonn.de/deegree/ 007 lat/lon GmbH 008 http://www.lat-lon.de 009 010 This library is free software; you can redistribute it and/or 011 modify it under the terms of the GNU Lesser General Public 012 License as published by the Free Software Foundation; either 013 version 2.1 of the License, or (at your option) any later version. 014 This library 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 GNU 017 Lesser General Public License for more details. 018 You should have received a copy of the GNU Lesser General Public 019 License along with this library; if not, write to the Free Software 020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 021 Contact: 022 023 Andreas Poth 024 lat/lon GmbH 025 Aennchenstr. 19 026 53177 Bonn 027 Germany 028 E-Mail: poth@lat-lon.de 029 030 Prof. Dr. Klaus Greve 031 Department of Geography 032 University of Bonn 033 Meckenheimer Allee 166 034 53115 Bonn 035 Germany 036 E-Mail: greve@giub.uni-bonn.de 037 ---------------------------------------------------------------------------*/ 038 039 package org.deegree.crs.utilities; 040 041 import javax.vecmath.Point2d; 042 import javax.vecmath.Point3d; 043 044 /** 045 * The <code>BBox</code> class TODO add documentation here 046 * 047 * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a> 048 * 049 * @author last edited by: $Author:$ 050 * 051 * @version $Revision:$, $Date:$ 052 * 053 */ 054 055 public class BBox { 056 057 private double[] min = null; 058 059 private double[] max = null; 060 061 private int dimension; 062 063 /** 064 * @param min 065 * the minimum of tis bbox 066 * @param max 067 * the maximum of this bbox 068 */ 069 public BBox( Point3d min, Point3d max ) { 070 this.min = new double[] { min.x, min.y, min.z }; 071 this.max = new double[] { max.x, max.y, max.z }; 072 dimension = 3; 073 } 074 075 /** 076 * @param min 077 * the minimum of tis bbox 078 * @param max 079 * the maximum of this bbox 080 */ 081 public BBox( Point2d min, Point2d max ) { 082 this.min = new double[] { min.x, min.y }; 083 this.max = new double[] { max.x, max.y }; 084 dimension = 2; 085 } 086 087 /** 088 * @return the distance between the min.x and the max.x 089 */ 090 public double getWidth() { 091 return max[0] - min[0]; 092 } 093 094 /** 095 * @return the distance between the min.y and the max.y 096 */ 097 public double getHeight() { 098 return max[1] - min[1]; 099 } 100 101 /** 102 * @return the distance between the min.z and the max.z (if any) else Double.NAN 103 */ 104 public double getDepth() { 105 if ( min.length == 2 ) { 106 return Double.NaN; 107 } 108 return max[2] - min[2]; 109 } 110 111 /** 112 * @param dimension 113 * to get the length for 114 * @return the length of given dimension. 115 */ 116 public double getLength( int dimension ) { 117 return max[dimension] - min[dimension]; 118 } 119 120 /** 121 * @return the max. 122 */ 123 public final double[] getMax() { 124 return max; 125 } 126 127 /** 128 * @return the min. 129 */ 130 public final double[] getMin() { 131 return min; 132 } 133 134 /** 135 * @param dimension 136 * to return the minimum value for. 137 * @return the minimal ordinate along the specified dimension. 138 */ 139 public double getMinimum( final int dimension ) { 140 return min[dimension]; 141 } 142 143 /** 144 * @param dimension 145 * to return the minimum value for. 146 * 147 * @return the maximal ordinate along the specified dimension. 148 */ 149 public double getMaximum( final int dimension ) { 150 return max[dimension]; 151 } 152 153 /** 154 * @return the dimension of this bbox. 155 */ 156 public int getDimension() { 157 return dimension; 158 } 159 160 }