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

SbBox2d.h
1 #ifndef COIN_SBBOX2D_H
2 #define COIN_SBBOX2D_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/SbVec2d.h>
37 
38 class SbBox2f;
39 class SbBox2s;
40 class SbBox2i32;
41 
42 class COIN_DLL_API SbBox2d {
43 public:
44  SbBox2d(void) { makeEmpty(); }
45  SbBox2d(double xmin, double ymin, double xmax, double ymax)
46  : minpt(xmin, ymin), maxpt(xmax, ymax) { }
47  SbBox2d(const SbVec2d & minpoint, const SbVec2d & maxpoint)
48  : minpt(minpoint), maxpt(maxpoint) { }
49  explicit SbBox2d(const SbBox2f & box) { setBounds(box); }
50  explicit SbBox2d(const SbBox2s & box) { setBounds(box); }
51  explicit SbBox2d(const SbBox2i32 & box) { setBounds(box); }
52 
53  SbBox2d & setBounds(double xmin, double ymin, double xmax, double ymax)
54  { minpt.setValue(xmin, ymin); maxpt.setValue(xmax, ymax); return *this; }
55  SbBox2d & setBounds(const SbVec2d & minpoint, const SbVec2d & maxpoint)
56  { minpt = minpoint; maxpt = maxpoint; return *this; }
57  SbBox2d & setBounds(const SbBox2f & box);
58  SbBox2d & setBounds(const SbBox2s & box);
59  SbBox2d & setBounds(const SbBox2i32 & box);
60 
61  void getBounds(double & xmin, double & ymin, double & xmax, double & ymax) const
62  { minpt.getValue(xmin, ymin); maxpt.getValue(xmax, ymax); }
63  void getBounds(SbVec2d & minpoint, SbVec2d & maxpoint) const
64  { minpoint = minpt; maxpoint = maxpt; }
65 
66  const SbVec2d & getMin(void) const { return minpt; }
67  SbVec2d & getMin(void) { return minpt; }
68  const SbVec2d & getMax(void) const { return maxpt; }
69  SbVec2d & getMax(void) { return maxpt; }
70 
71  void extendBy(const SbVec2d & point);
72  void extendBy(const SbBox2d & box);
73  void makeEmpty(void);
74  SbBool isEmpty(void) const { return (maxpt[0] < minpt[0]); }
75  SbBool hasArea(void) const { return ((maxpt[0] > minpt[0]) && (maxpt[1] > minpt[1])); }
76 
77  SbBool intersect(const SbVec2d & point) const;
78  SbBool intersect(const SbBox2d & box) const;
79  SbVec2d getClosestPoint(const SbVec2d & p) const;
80  SbBool findIntersection(const SbVec2d & a, const SbVec2d & b, SbVec2d & ia, SbVec2d & ib) const;
81 
82  SbVec2d getCenter(void) const { return (minpt + maxpt) * 0.5; }
83  void getOrigin(double & originX, double & originY) const
84  { minpt.getValue(originX, originY); }
85  void getSize(double & sizeX, double & sizeY) const
86  { if (isEmpty()) { sizeX = sizeY = 0.0; }
87  else { sizeX = maxpt[0] - minpt[0]; sizeY = maxpt[1] - minpt[1]; } }
88  SbVec2d getSize(void) const {
89  SbVec2d v;
90  this->getSize(v[0], v[1]);
91  return v;
92  }
93  double getAspectRatio(void) const
94  { SbDividerChk("SbBox2d::getAspectRatio()", maxpt[1] - minpt[1]);
95  return (maxpt[0] - minpt[0]) / (maxpt[1] - minpt[1]); }
96 
97 private:
98  SbVec2d minpt, maxpt;
99 
100 }; // SbBox2d
101 
102 COIN_DLL_API inline int operator == (const SbBox2d & b1, const SbBox2d & b2) {
103  return ((b1.getMin() == b2.getMin()) && (b1.getMax() == b2.getMax()));
104 }
105 
106 COIN_DLL_API inline int operator != (const SbBox2d & b1, const SbBox2d & b2) {
107  return !(b1 == b2);
108 }
109 
110 #endif // !COIN_SBBOX2D_H
SbBox2d & setBounds(double xmin, double ymin, double xmax, double ymax)
Definition: SbBox2d.h:53
SbBox2d(void)
Definition: SbBox2d.h:44
SbBox2d(const SbVec2d &minpoint, const SbVec2d &maxpoint)
Definition: SbBox2d.h:47
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
SbVec2d getCenter(void) const
Definition: SbBox2d.h:82
SbVec2d & getMin(void)
Definition: SbBox2d.h:67
void getBounds(double &xmin, double &ymin, double &xmax, double &ymax) const
Definition: SbBox2d.h:61
double getAspectRatio(void) const
Definition: SbBox2d.h:93
void getBounds(SbVec2d &minpoint, SbVec2d &maxpoint) const
Definition: SbBox2d.h:63
The SbBox2s class is a 2 dimensional box with short integer coordinates.This box class is used by oth...
Definition: SbBox2s.h:43
SbBox2d(double xmin, double ymin, double xmax, double ymax)
Definition: SbBox2d.h:45
The SbVec2d class is a 2 dimensional vector with double precision floating point coordinates.This vector class is used by many other classes in Coin. It provides storage for a vector in 2 dimensions aswell as simple floating point arithmetic operations on this vector.
Definition: SbVec2d.h:48
const SbVec2d & getMin(void) const
Definition: SbBox2d.h:66
const SbVec2d & getMax(void) const
Definition: SbBox2d.h:68
The SbBox2f class is a 2 dimensional box with floating point corner coordinates.This box class is use...
Definition: SbBox2f.h:42
SbBox2d & setBounds(const SbVec2d &minpoint, const SbVec2d &maxpoint)
Definition: SbBox2d.h:55
SbVec2d & getMax(void)
Definition: SbBox2d.h:69
void getSize(double &sizeX, double &sizeY) const
Definition: SbBox2d.h:85
SbBool isEmpty(void) const
Definition: SbBox2d.h:74
void getOrigin(double &originX, double &originY) const
Definition: SbBox2d.h:83
SbBool hasArea(void) const
Definition: SbBox2d.h:75

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

Generated for Coin by Doxygen