Coin Logo http://www.coin3d.org/
http://www.kongsberg.com/kogt/

SbBox2s.h
1 #ifndef COIN_SBBOX2S_H
2 #define COIN_SBBOX2S_H
3 
4 /**************************************************************************\
5  * Copyright (c) Kongsberg Oil & Gas Technologies AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 \**************************************************************************/
35 
36 #include <Inventor/SbVec2s.h>
37 #include <Inventor/SbVec2f.h>
38 
39 class SbBox2i32;
40 class SbBox2f;
41 class SbBox2d;
42 
43 class COIN_DLL_API SbBox2s {
44 public:
45  SbBox2s(void) { makeEmpty(); }
46  SbBox2s(short xmin, short ymin, short xmax, short ymax)
47  : minpt(xmin, ymin), maxpt(xmax, ymax) { }
48  SbBox2s(const SbVec2s & minpoint, const SbVec2s & maxpoint)
49  : minpt(minpoint), maxpt(maxpoint) { }
50  explicit SbBox2s(const SbBox2i32 & box) { setBounds(box); }
51  explicit SbBox2s(const SbBox2f & box) { setBounds(box); }
52  explicit SbBox2s(const SbBox2d & box) { setBounds(box); }
53 
54  SbBox2s & setBounds(short xmin, short ymin, short xmax, short ymax)
55  { minpt.setValue(xmin, ymin); maxpt.setValue(xmax, ymax); return *this; }
56  SbBox2s & setBounds(const SbVec2s & minpoint, const SbVec2s & maxpoint)
57  { minpt = minpoint; maxpt = maxpoint; return *this; }
58  SbBox2s & setBounds(const SbBox2i32 & box);
59  SbBox2s & setBounds(const SbBox2f & box);
60  SbBox2s & setBounds(const SbBox2d & box);
61 
62  void getBounds(short & xmin, short & ymin, short & xmax, short & ymax) const
63  { minpt.getValue(xmin, ymin); maxpt.getValue(xmax, ymax); }
64  void getBounds(SbVec2s & minpoint, SbVec2s & maxpoint) const
65  { minpoint = minpt; maxpoint = maxpt; }
66 
67  const SbVec2s & getMin(void) const { return minpt; }
68  SbVec2s & getMin(void) { return minpt; }
69  const SbVec2s & getMax(void) const { return maxpt; }
70  SbVec2s & getMax(void) { return maxpt; }
71 
72  void extendBy(const SbVec2s & point);
73  void extendBy(const SbBox2s & box);
74  void makeEmpty(void);
75  SbBool isEmpty(void) const { return (maxpt[0] < minpt[0]); }
76  SbBool hasArea(void) const { return ((maxpt[0] > minpt[0]) && (maxpt[1] > minpt[1])); }
77 
78  SbBool intersect(const SbVec2s & point) const;
79  SbBool intersect(const SbBox2s & box) const;
80 
81  SbVec2f getCenter(void) const { return SbVec2f((minpt[0] + maxpt[0]) * 0.5f, (minpt[1] + maxpt[1]) * 0.5f); }
82  void getOrigin(short & originX, short & originY) const
83  { minpt.getValue(originX, originY); }
84  void getSize(short & sizeX, short & sizeY) const
85  { if (isEmpty()) { sizeX = sizeY = 0; }
86  else { sizeX = maxpt[0] - minpt[0]; sizeY = maxpt[1] - minpt[1]; } }
87  SbVec2s getSize(void) const {
88  SbVec2s v;
89  this->getSize(v[0], v[1]);
90  return v;
91  }
92 
93  float getAspectRatio(void) const
94  { SbDividerChk("SbBox2s::getAspectRatio()", maxpt[1] - minpt[1]);
95  return (float(maxpt[0] - minpt[0]) / float(maxpt[1] - minpt[1])); }
96 
97 private:
98  SbVec2s minpt, maxpt;
99 
100 }; // SbBox2s
101 
102 COIN_DLL_API inline int operator == (const SbBox2s & b1, const SbBox2s & b2) {
103  return ((b1.getMin() == b2.getMin()) && (b1.getMax() == b2.getMax()));
104 }
105 
106 COIN_DLL_API inline int operator != (const SbBox2s & b1, const SbBox2s & b2) {
107  return !(b1 == b2);
108 }
109 
110 #endif // !COIN_SBBOX2S_H
void getOrigin(short &originX, short &originY) const
Definition: SbBox2s.h:82
The SbVec2f class is a 2 dimensional vector with floating point coordinates.This vector class is used...
Definition: SbVec2f.h:49
const SbVec2s & getMin(void) const
Definition: SbBox2s.h:67
SbBox2s(const SbVec2s &minpoint, const SbVec2s &maxpoint)
Definition: SbBox2s.h:48
void getBounds(short &xmin, short &ymin, short &xmax, short &ymax) const
Definition: SbBox2s.h:62
The SbBox2d class is a 2 dimensional box with double precision corner coordinates.This box class is used by many other classes in Coin for data exchange and storage. It provides two box corners with double precision coordinates, which is among other things useful for representing screen or canvas dimensions in normalized coordinates.
Definition: SbBox2d.h:42
const SbVec2s & getMax(void) const
Definition: SbBox2s.h:69
SbBox2s & setBounds(const SbVec2s &minpoint, const SbVec2s &maxpoint)
Definition: SbBox2s.h:56
SbBox2s(short xmin, short ymin, short xmax, short ymax)
Definition: SbBox2s.h:46
float getAspectRatio(void) const
Definition: SbBox2s.h:93
The SbBox2s class is a 2 dimensional box with short integer coordinates.This box class is used by oth...
Definition: SbBox2s.h:43
The SbBox2f class is a 2 dimensional box with floating point corner coordinates.This box class is use...
Definition: SbBox2f.h:42
void getSize(short &sizeX, short &sizeY) const
Definition: SbBox2s.h:84
SbBox2s & setBounds(short xmin, short ymin, short xmax, short ymax)
Definition: SbBox2s.h:54
SbBox2s(void)
Definition: SbBox2s.h:45
The SbVec2s class is a 2 dimensional vector with short integer coordinates.This vector class is used ...
Definition: SbVec2s.h:51
void getBounds(SbVec2s &minpoint, SbVec2s &maxpoint) const
Definition: SbBox2s.h:64

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

Generated for Coin by Doxygen