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

SbBox2i32.h

00001 #ifndef COIN_SBBOX2I32_H
00002 #define COIN_SBBOX2I32_H
00003 
00004 /**************************************************************************\
00005  *
00006  *  This file is part of the Coin 3D visualization library.
00007  *  Copyright (C) 1998-2007 by Systems in Motion.  All rights reserved.
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 Systems in Motion about acquiring
00018  *  a Coin Professional Edition License.
00019  *
00020  *  See http://www.coin3d.org/ for more information.
00021  *
00022  *  Systems in Motion, Postboks 1283, Pirsenteret, 7462 Trondheim, NORWAY.
00023  *  http://www.sim.no/  sales@sim.no  coin-support@coin3d.org
00024  *
00025 \**************************************************************************/
00026 
00027 #include <Inventor/SbVec2i32.h>
00028 #include <Inventor/SbVec2f.h>
00029 
00030 class SbBox2s;
00031 class SbBox2f;
00032 class SbBox2d;
00033 
00034 class COIN_DLL_API SbBox2i32 {
00035 public:
00036   SbBox2i32(void) { makeEmpty(); }
00037   SbBox2i32(int32_t xmin, int32_t ymin, int32_t xmax, int32_t ymax)
00038     : minpt(xmin, ymin), maxpt(xmax, ymax) { }
00039   SbBox2i32(const SbVec2i32 & minpoint, const SbVec2i32 & maxpoint)
00040     : minpt(minpoint), maxpt(maxpoint) { }
00041   explicit SbBox2i32(const SbBox2s & box) { setBounds(box); }
00042   explicit SbBox2i32(const SbBox2f & box) { setBounds(box); }
00043   explicit SbBox2i32(const SbBox2d & box) { setBounds(box); }
00044 
00045   SbBox2i32 & setBounds(int32_t xmin, int32_t ymin, int32_t xmax, int32_t ymax)
00046     { minpt.setValue(xmin, ymin); maxpt.setValue(xmax, ymax); return *this; }
00047   SbBox2i32 & setBounds(const SbVec2i32 & minpoint, const SbVec2i32 & maxpoint)
00048     { minpt = minpoint; maxpt = maxpoint; return *this; }
00049   SbBox2i32 & setBounds(const SbBox2s & box);
00050   SbBox2i32 & setBounds(const SbBox2f & box);
00051   SbBox2i32 & setBounds(const SbBox2d & box);
00052 
00053   void getBounds(int32_t & xmin, int32_t & ymin, int32_t & xmax, int32_t & ymax) const
00054     { minpt.getValue(xmin, ymin); maxpt.getValue(xmax, ymax); }
00055   void getBounds(SbVec2i32 & minpoint, SbVec2i32 & maxpoint) const
00056     { minpoint = minpt; maxpoint = maxpt; }
00057 
00058   const SbVec2i32 & getMin(void) const { return minpt; }
00059   SbVec2i32 & getMin(void) { return minpt; }
00060   const SbVec2i32 & getMax(void) const { return maxpt; }
00061   SbVec2i32 & getMax(void) { return maxpt; }
00062 
00063   void extendBy(const SbVec2i32 & point);
00064   void extendBy(const SbBox2i32 & box);
00065   void makeEmpty(void);
00066   SbBool isEmpty(void) const { return (maxpt[0] < minpt[0]); }
00067   SbBool hasArea(void) const { return ((maxpt[0] > minpt[0]) && (maxpt[1] > minpt[1])); }
00068 
00069   SbBool intersect(const SbVec2i32 & point) const;
00070   SbBool intersect(const SbBox2i32 & box) const;
00071 
00072   SbVec2f getCenter(void) const { return SbVec2f((minpt[0] + maxpt[0]) * 0.5f, (minpt[0] + maxpt[0]) * 0.5f); }
00073   void getOrigin(int32_t & originX, int32_t & originY) const
00074     { minpt.getValue(originX, originY); }
00075   void getSize(int32_t & sizeX, int32_t & sizeY) const
00076     { if (isEmpty()) { sizeX = sizeY = 0; }
00077       else { sizeX = maxpt[0] - minpt[0]; sizeY = maxpt[1] - minpt[1]; } }
00078   float getAspectRatio(void) const
00079     { SbDividerChk("SbBox2i32::getAspectRatio()", maxpt[1] - minpt[1]);
00080       return float(maxpt[0] - minpt[0]) / float(maxpt[1] - minpt[1]); }
00081 
00082 private:
00083   SbVec2i32 minpt, maxpt;
00084 
00085 }; // SbBox2i32
00086 
00087 COIN_DLL_API inline int operator == (const SbBox2i32 & b1, const SbBox2i32 & b2) {
00088   return ((b1.getMin() == b2.getMin()) && (b1.getMax() == b2.getMax()));
00089 }
00090 
00091 COIN_DLL_API inline int operator != (const SbBox2i32 & b1, const SbBox2i32 & b2) {
00092   return !(b1 == b2);
00093 }
00094 
00095 #endif // !COIN_SBBOX2I32_H

Copyright © 1998-2007 by Systems in Motion AS. All rights reserved.

Generated on Mon Feb 23 16:33:07 2009 for Coin by Doxygen. 1.5.8