Coin Logo http://www.sim.no/
http://www.coin3d.org/

SbBox2d.h
00001 #ifndef COIN_SBBOX2D_H
00002 #define COIN_SBBOX2D_H
00003 
00004 /**************************************************************************\
00005  *
00006  *  This file is part of the Coin 3D visualization library.
00007  *  Copyright (C) by Kongsberg Oil & Gas Technologies.
00008  *
00009  *  This library is free software; you can redistribute it and/or
00010  *  modify it under the terms of the GNU General Public License
00011  *  ("GPL") version 2 as published by the Free Software Foundation.
00012  *  See the file LICENSE.GPL at the root directory of this source
00013  *  distribution for additional information about the GNU GPL.
00014  *
00015  *  For using Coin with software that can not be combined with the GNU
00016  *  GPL, and for taking advantage of the additional benefits of our
00017  *  support services, please contact Kongsberg Oil & Gas Technologies
00018  *  about acquiring a Coin Professional Edition License.
00019  *
00020  *  See http://www.coin3d.org/ for more information.
00021  *
00022  *  Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
00023  *  http://www.sim.no/  sales@sim.no  coin-support@coin3d.org
00024  *
00025 \**************************************************************************/
00026 
00027 #include <Inventor/SbVec2d.h>
00028 
00029 class SbBox2f;
00030 class SbBox2s;
00031 class SbBox2i32;
00032 
00033 class COIN_DLL_API SbBox2d {
00034 public:
00035   SbBox2d(void) { makeEmpty(); }
00036   SbBox2d(double xmin, double ymin, double xmax, double ymax)
00037     : minpt(xmin, ymin), maxpt(xmax, ymax) { }
00038   SbBox2d(const SbVec2d & minpoint, const SbVec2d & maxpoint)
00039     : minpt(minpoint), maxpt(maxpoint) { }
00040   explicit SbBox2d(const SbBox2f & box) { setBounds(box); }
00041   explicit SbBox2d(const SbBox2s & box) { setBounds(box); }
00042   explicit SbBox2d(const SbBox2i32 & box) { setBounds(box); }
00043 
00044   SbBox2d & setBounds(double xmin, double ymin, double xmax, double ymax)
00045     { minpt.setValue(xmin, ymin); maxpt.setValue(xmax, ymax); return *this; }
00046   SbBox2d & setBounds(const SbVec2d & minpoint, const SbVec2d & maxpoint)
00047     { minpt = minpoint; maxpt = maxpoint; return *this; }
00048   SbBox2d & setBounds(const SbBox2f & box);
00049   SbBox2d & setBounds(const SbBox2s & box);
00050   SbBox2d & setBounds(const SbBox2i32 & box);
00051 
00052   void getBounds(double & xmin, double & ymin, double & xmax, double & ymax) const
00053     { minpt.getValue(xmin, ymin); maxpt.getValue(xmax, ymax); }
00054   void getBounds(SbVec2d & minpoint, SbVec2d & maxpoint) const
00055     { minpoint = minpt; maxpoint = maxpt; }
00056 
00057   const SbVec2d & getMin(void) const { return minpt; }
00058   SbVec2d & getMin(void) { return minpt; }
00059   const SbVec2d & getMax(void) const { return maxpt; }
00060   SbVec2d & getMax(void) { return maxpt; }
00061 
00062   void extendBy(const SbVec2d & point);
00063   void extendBy(const SbBox2d & box);
00064   void makeEmpty(void);
00065   SbBool isEmpty(void) const { return (maxpt[0] < minpt[0]); }
00066   SbBool hasArea(void) const { return ((maxpt[0] > minpt[0]) && (maxpt[1] > minpt[1])); }
00067 
00068   SbBool intersect(const SbVec2d & point) const;
00069   SbBool intersect(const SbBox2d & box) const;
00070   SbVec2d getClosestPoint(const SbVec2d & p) const;
00071   SbBool findIntersection(const SbVec2d & a, const SbVec2d & b, SbVec2d & ia, SbVec2d & ib) const;
00072 
00073   SbVec2d getCenter(void) const { return (minpt + maxpt) * 0.5; }
00074   void getOrigin(double & originX, double & originY) const
00075     { minpt.getValue(originX, originY); }
00076   void getSize(double & sizeX, double & sizeY) const
00077     { if (isEmpty()) { sizeX = sizeY = 0.0; }
00078       else { sizeX = maxpt[0] - minpt[0]; sizeY = maxpt[1] - minpt[1]; } }
00079   double getAspectRatio(void) const
00080     { SbDividerChk("SbBox2d::getAspectRatio()", maxpt[1] - minpt[1]);
00081       return (maxpt[0] - minpt[0]) / (maxpt[1] - minpt[1]); }
00082 
00083 private:
00084   SbVec2d minpt, maxpt;
00085 
00086 }; // SbBox2d
00087 
00088 COIN_DLL_API inline int operator == (const SbBox2d & b1, const SbBox2d & b2) {
00089   return ((b1.getMin() == b2.getMin()) && (b1.getMax() == b2.getMax()));
00090 }
00091 
00092 COIN_DLL_API inline int operator != (const SbBox2d & b1, const SbBox2d & b2) {
00093   return !(b1 == b2);
00094 }
00095 
00096 #endif // !COIN_SBBOX2D_H

Copyright © 1998-2010 by Kongsberg Oil & Gas Technologies. All rights reserved.

Generated on Fri Dec 11 2015 03:24:52 for Coin by Doxygen 1.7.6.1.