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

SbBox2i32.h
1 #ifndef COIN_SBBOX2I32_H
2 #define COIN_SBBOX2I32_H
3 
4 /**************************************************************************\
5  *
6  * This file is part of the Coin 3D visualization library.
7  * Copyright (C) 1998-2007 by Systems in Motion. All rights reserved.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * ("GPL") version 2 as published by the Free Software Foundation.
12  * See the file LICENSE.GPL at the root directory of this source
13  * distribution for additional information about the GNU GPL.
14  *
15  * For using Coin with software that can not be combined with the GNU
16  * GPL, and for taking advantage of the additional benefits of our
17  * support services, please contact Systems in Motion about acquiring
18  * a Coin Professional Edition License.
19  *
20  * See http://www.coin3d.org/ for more information.
21  *
22  * Systems in Motion, Postboks 1283, Pirsenteret, 7462 Trondheim, NORWAY.
23  * http://www.sim.no/ sales@sim.no coin-support@coin3d.org
24  *
25 \**************************************************************************/
26 
27 #include <Inventor/SbVec2i32.h>
28 #include <Inventor/SbVec2f.h>
29 
30 class SbBox2s;
31 class SbBox2f;
32 class SbBox2d;
33 
34 class COIN_DLL_API SbBox2i32 {
35 public:
36  SbBox2i32(void) { makeEmpty(); }
37  SbBox2i32(int32_t xmin, int32_t ymin, int32_t xmax, int32_t ymax)
38  : minpt(xmin, ymin), maxpt(xmax, ymax) { }
39  SbBox2i32(const SbVec2i32 & minpoint, const SbVec2i32 & maxpoint)
40  : minpt(minpoint), maxpt(maxpoint) { }
41  explicit SbBox2i32(const SbBox2s & box) { setBounds(box); }
42  explicit SbBox2i32(const SbBox2f & box) { setBounds(box); }
43  explicit SbBox2i32(const SbBox2d & box) { setBounds(box); }
44 
45  SbBox2i32 & setBounds(int32_t xmin, int32_t ymin, int32_t xmax, int32_t ymax)
46  { minpt.setValue(xmin, ymin); maxpt.setValue(xmax, ymax); return *this; }
47  SbBox2i32 & setBounds(const SbVec2i32 & minpoint, const SbVec2i32 & maxpoint)
48  { minpt = minpoint; maxpt = maxpoint; return *this; }
49  SbBox2i32 & setBounds(const SbBox2s & box);
50  SbBox2i32 & setBounds(const SbBox2f & box);
51  SbBox2i32 & setBounds(const SbBox2d & box);
52 
53  void getBounds(int32_t & xmin, int32_t & ymin, int32_t & xmax, int32_t & ymax) const
54  { minpt.getValue(xmin, ymin); maxpt.getValue(xmax, ymax); }
55  void getBounds(SbVec2i32 & minpoint, SbVec2i32 & maxpoint) const
56  { minpoint = minpt; maxpoint = maxpt; }
57 
58  const SbVec2i32 & getMin(void) const { return minpt; }
59  SbVec2i32 & getMin(void) { return minpt; }
60  const SbVec2i32 & getMax(void) const { return maxpt; }
61  SbVec2i32 & getMax(void) { return maxpt; }
62 
63  void extendBy(const SbVec2i32 & point);
64  void extendBy(const SbBox2i32 & box);
65  void makeEmpty(void);
66  SbBool isEmpty(void) const { return (maxpt[0] < minpt[0]); }
67  SbBool hasArea(void) const { return ((maxpt[0] > minpt[0]) && (maxpt[1] > minpt[1])); }
68 
69  SbBool intersect(const SbVec2i32 & point) const;
70  SbBool intersect(const SbBox2i32 & box) const;
71 
72  SbVec2f getCenter(void) const { return SbVec2f((minpt[0] + maxpt[0]) * 0.5f, (minpt[0] + maxpt[0]) * 0.5f); }
73  void getOrigin(int32_t & originX, int32_t & originY) const
74  { minpt.getValue(originX, originY); }
75  void getSize(int32_t & sizeX, int32_t & sizeY) const
76  { if (isEmpty()) { sizeX = sizeY = 0; }
77  else { sizeX = maxpt[0] - minpt[0]; sizeY = maxpt[1] - minpt[1]; } }
78  float getAspectRatio(void) const
79  { SbDividerChk("SbBox2i32::getAspectRatio()", maxpt[1] - minpt[1]);
80  return float(maxpt[0] - minpt[0]) / float(maxpt[1] - minpt[1]); }
81 
82 private:
83  SbVec2i32 minpt, maxpt;
84 
85 }; // SbBox2i32
86 
87 COIN_DLL_API inline int operator == (const SbBox2i32 & b1, const SbBox2i32 & b2) {
88  return ((b1.getMin() == b2.getMin()) && (b1.getMax() == b2.getMax()));
89 }
90 
91 COIN_DLL_API inline int operator != (const SbBox2i32 & b1, const SbBox2i32 & b2) {
92  return !(b1 == b2);
93 }
94 
95 #endif // !COIN_SBBOX2I32_H
The SbBox2d class is a 2 dimensional box with double precision corner coordinates.
Definition: SbBox2d.h:33
The SbBox2f class is a 2 dimensional box with floating point corner coordinates.
Definition: SbBox2f.h:33
The SbBox2i32 class is a 2 dimensional box with int32_t coordinates.
Definition: SbBox2i32.h:34
SbBox2i32(void)
Definition: SbBox2i32.h:36
SbBox2i32 & setBounds(int32_t xmin, int32_t ymin, int32_t xmax, int32_t ymax)
Definition: SbBox2i32.h:45
float getAspectRatio(void) const
Definition: SbBox2i32.h:78
SbVec2f getCenter(void) const
Definition: SbBox2i32.h:72
void getSize(int32_t &sizeX, int32_t &sizeY) const
Definition: SbBox2i32.h:75
const SbVec2i32 & getMax(void) const
Definition: SbBox2i32.h:60
SbBox2i32(const SbVec2i32 &minpoint, const SbVec2i32 &maxpoint)
Definition: SbBox2i32.h:39
SbBox2i32(int32_t xmin, int32_t ymin, int32_t xmax, int32_t ymax)
Definition: SbBox2i32.h:37
SbBool hasArea(void) const
Definition: SbBox2i32.h:67
SbBox2i32(const SbBox2s &box)
Definition: SbBox2i32.h:41
SbBool isEmpty(void) const
Definition: SbBox2i32.h:66
void getOrigin(int32_t &originX, int32_t &originY) const
Definition: SbBox2i32.h:73
void getBounds(int32_t &xmin, int32_t &ymin, int32_t &xmax, int32_t &ymax) const
Definition: SbBox2i32.h:53
SbBox2i32(const SbBox2f &box)
Definition: SbBox2i32.h:42
SbVec2i32 & getMax(void)
Definition: SbBox2i32.h:61
void getBounds(SbVec2i32 &minpoint, SbVec2i32 &maxpoint) const
Definition: SbBox2i32.h:55
SbBox2i32(const SbBox2d &box)
Definition: SbBox2i32.h:43
const SbVec2i32 & getMin(void) const
Definition: SbBox2i32.h:58
SbVec2i32 & getMin(void)
Definition: SbBox2i32.h:59
SbBox2i32 & setBounds(const SbVec2i32 &minpoint, const SbVec2i32 &maxpoint)
Definition: SbBox2i32.h:47
The SbBox2s class is a 2 dimensional box with short integer coordinates.
Definition: SbBox2s.h:34
int operator==(const SbBox2s &b1, const SbBox2s &b2)
Definition: SbBox2s.cpp:432
int operator!=(const SbBox2s &b1, const SbBox2s &b2)
Definition: SbBox2s.cpp:443
The SbVec2f class is a 2 dimensional vector with floating point coordinates.
Definition: SbVec2f.h:36
The SbVec2i32 class is a 2 dimensional vector with 32-bit integer coordinates.
Definition: SbVec2i32.h:39

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

Generated on Wed Jul 21 2021 for Coin by Doxygen. 1.9.1