/* * Moonlight|3D Copyright (C) 2005 The Moonlight|3D team * * This library is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 2.1 of the License, or (at your option) * any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public License * along with this library; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * Created on Jan 5, 2005 */ package ml.math; /** * A class representing an axis alligned bounding box * * @author gregor */ public class AxisAlignedBoundingBox { public Vector3D min; public Vector3D max; /** * Simple constructor. */ public AxisAlignedBoundingBox() { min = new Vector3D(); max = new Vector3D(); } /** * Generate a bounding box that contains this one and the given * one. * * @param b the bounding box to be merged with this one * @return the bounding box enclosing both boxes. */ public AxisAlignedBoundingBox merge(AxisAlignedBoundingBox b) { AxisAlignedBoundingBox res = new AxisAlignedBoundingBox(); if (min.X1 < b.min.X1) { res.min.X1 = min.X1; } else { res.min.X1 = b.min.X1; } if (max.X1 > b.max.X1) { res.max.X1 = max.X1; } else { res.max.X1 = b.max.X1; } if (min.X2 < b.min.X2) { res.min.X2 = min.X2; } else { res.min.X2 = b.min.X2; } if (max.X2 > b.max.X2) { res.max.X2 = max.X2; } else { res.max.X2 = b.max.X2; } if (min.X3 < b.min.X3) { res.min.X3 = min.X3; } else { res.min.X3 = b.min.X3; } if (max.X3 > b.max.X3) { res.max.X3 = max.X3; } else { res.max.X3 = b.max.X3; } return res; } }