Coin  4.0.3
Coin3D core library
Loading...
Searching...
No Matches
SbBox2f.h
1#ifndef COIN_SBBOX2F_H
2#define COIN_SBBOX2F_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/SbVec2f.h>
37
38class SbBox2d;
39class SbBox2s;
40class SbBox2i32;
41
43public:
44 SbBox2f(void) { makeEmpty(); }
45 SbBox2f(float xmin, float ymin, float xmax, float ymax)
46 : minpt(xmin, ymin), maxpt(xmax, ymax) { }
48 : minpt(minpoint), maxpt(maxpoint) { }
49 explicit SbBox2f(const SbBox2d & box) { setBounds(box); }
50 explicit SbBox2f(const SbBox2s & box) { setBounds(box); }
51 explicit SbBox2f(const SbBox2i32 & box) { setBounds(box); }
52
53 SbBox2f & setBounds(float xmin, float ymin, float xmax, float ymax)
54 { minpt.setValue(xmin, ymin); maxpt.setValue(xmax, ymax); return *this; }
56 { minpt = minpoint; maxpt = maxpoint; return *this; }
57 SbBox2f & setBounds(const SbBox2d & box);
58 SbBox2f & setBounds(const SbBox2s & box);
59 SbBox2f & setBounds(const SbBox2i32 & box);
60
61 void getBounds(float & xmin, float & ymin, float & xmax, float & ymax) const
62 { minpt.getValue(xmin, ymin); maxpt.getValue(xmax, ymax); }
64 { minpoint = minpt; maxpoint = maxpt; }
65
66 const SbVec2f & getMin(void) const { return minpt; }
67 SbVec2f & getMin(void) { return minpt; }
68
69 const SbVec2f & getMax(void) const { return maxpt; }
70 SbVec2f & getMax(void) { return maxpt; }
71
72 void extendBy(const SbVec2f & point);
73 void extendBy(const SbBox2f & 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 SbVec2f & point) const;
79 SbBool intersect(const SbBox2f & box) const;
80 SbVec2f getClosestPoint(const SbVec2f & point) const;
81
82 SbVec2f getCenter(void) const { return (minpt + maxpt) * 0.5f; }
83 void getOrigin(float & originX, float & originY) const
84 { minpt.getValue(originX, originY); }
85 void getSize(float & sizeX, float & sizeY) const
86 { if (isEmpty()) { sizeX = sizeY = 0.0f; }
87 else { sizeX = maxpt[0] - minpt[0]; sizeY = maxpt[1] - minpt[1]; } }
88 SbVec2f getSize(void) const {
89 SbVec2f v;
90 this->getSize(v[0], v[1]);
91 return v;
92 }
93
94 float getAspectRatio(void) const
95 { SbDividerChk("SbBox2f::getAspectRatio()", maxpt[1] - minpt[1]);
96 return (maxpt[0] - minpt[0]) / (maxpt[1] - minpt[1]); }
97
98protected:
99 SbVec2f minpt, maxpt;
100
101}; // SbBox2f
102
103COIN_DLL_API inline int operator == (const SbBox2f & b1, const SbBox2f & b2) {
104 return ((b1.getMin() == b2.getMin()) && (b1.getMax() == b2.getMax()));
105}
106
107COIN_DLL_API inline int operator != (const SbBox2f & b1, const SbBox2f & b2) {
108 return !(b1 == b2);
109}
110
111#endif // !COIN_SBBOX2F_H
The SbBox2d class is a 2 dimensional box with double precision corner coordinates.
Definition SbBox2d.h:42
The SbBox2f class is a 2 dimensional box with floating point corner coordinates.
Definition SbBox2f.h:42
SbVec2f & getMax(void)
Definition SbBox2f.h:70
SbBox2f(const SbBox2i32 &box)
Definition SbBox2f.h:51
void getSize(float &sizeX, float &sizeY) const
Definition SbBox2f.h:85
float getAspectRatio(void) const
Definition SbBox2f.h:94
SbBox2f & setBounds(float xmin, float ymin, float xmax, float ymax)
Definition SbBox2f.h:53
const SbVec2f & getMax(void) const
Definition SbBox2f.h:69
SbBox2f(float xmin, float ymin, float xmax, float ymax)
Definition SbBox2f.h:45
void getBounds(SbVec2f &minpoint, SbVec2f &maxpoint) const
Definition SbBox2f.h:63
SbBox2f(const SbBox2s &box)
Definition SbBox2f.h:50
SbBox2f(const SbBox2d &box)
Definition SbBox2f.h:49
SbVec2f getSize(void) const
Definition SbBox2f.h:88
SbVec2f & getMin(void)
Definition SbBox2f.h:67
SbBox2f(const SbVec2f &minpoint, const SbVec2f &maxpoint)
Definition SbBox2f.h:47
void getOrigin(float &originX, float &originY) const
Definition SbBox2f.h:83
SbBool isEmpty(void) const
Definition SbBox2f.h:75
void getBounds(float &xmin, float &ymin, float &xmax, float &ymax) const
Definition SbBox2f.h:61
const SbVec2f & getMin(void) const
Definition SbBox2f.h:66
SbVec2f getCenter(void) const
Definition SbBox2f.h:82
SbBox2f & setBounds(const SbVec2f &minpoint, const SbVec2f &maxpoint)
Definition SbBox2f.h:55
SbBox2f(void)
Definition SbBox2f.h:44
SbBool hasArea(void) const
Definition SbBox2f.h:76
The SbBox2i32 class is a 2 dimensional box with 32-bit integer coordinates.
Definition SbBox2i32.h:43
The SbBox2s class is a 2 dimensional box with short integer coordinates.
Definition SbBox2s.h:43
The SbList class is a template container class for lists.
Definition SbList.h:70
SbList(const int sizehint=DEFAULTSIZE)
Definition SbList.h:78
The SbVec2f class is a 2 dimensional vector with floating point coordinates.
Definition SbVec2f.h:49