| http://www.sim.no/ http://www.coin3d.org/

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

SbBox2f.h
1 #ifndef COIN_SBBOX2F_H
2 #define COIN_SBBOX2F_H
3
4 /**************************************************************************\
5 *
6 * This file is part of the Coin 3D visualization library.
7 * Copyright (C) by Kongsberg Oil & Gas Technologies.
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 Kongsberg Oil & Gas Technologies
18 * about acquiring a Coin Professional Edition License.
19 *
20 * See http://www.coin3d.org/ for more information.
21 *
22 * Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
23 * http://www.sim.no/ sales@sim.no coin-support@coin3d.org
24 *
25 \**************************************************************************/
26
27 #include <Inventor/SbVec2f.h>
28
29 class SbBox2d;
30 class SbBox2s;
31 class SbBox2i32;
32
33 class COIN_DLL_API SbBox2f {
34 public:
35 SbBox2f(void) { makeEmpty(); }
36 SbBox2f(float xmin, float ymin, float xmax, float ymax)
37 : minpt(xmin, ymin), maxpt(xmax, ymax) { }
38 SbBox2f(const SbVec2f & minpoint, const SbVec2f & maxpoint)
39 : minpt(minpoint), maxpt(maxpoint) { }
40 explicit SbBox2f(const SbBox2d & box) { setBounds(box); }
41 explicit SbBox2f(const SbBox2s & box) { setBounds(box); }
42 explicit SbBox2f(const SbBox2i32 & box) { setBounds(box); }
43
44 SbBox2f & setBounds(float xmin, float ymin, float xmax, float ymax)
45 { minpt.setValue(xmin, ymin); maxpt.setValue(xmax, ymax); return *this; }
46 SbBox2f & setBounds(const SbVec2f & minpoint, const SbVec2f & maxpoint)
47 { minpt = minpoint; maxpt = maxpoint; return *this; }
48 SbBox2f & setBounds(const SbBox2d & box);
49 SbBox2f & setBounds(const SbBox2s & box);
50 SbBox2f & setBounds(const SbBox2i32 & box);
51
52 void getBounds(float & xmin, float & ymin, float & xmax, float & ymax) const
53 { minpt.getValue(xmin, ymin); maxpt.getValue(xmax, ymax); }
54 void getBounds(SbVec2f & minpoint, SbVec2f & maxpoint) const
55 { minpoint = minpt; maxpoint = maxpt; }
56
57 const SbVec2f & getMin(void) const { return minpt; }
58 SbVec2f & getMin(void) { return minpt; }
59
60 const SbVec2f & getMax(void) const { return maxpt; }
61 SbVec2f & getMax(void) { return maxpt; }
62
63 void extendBy(const SbVec2f & point);
64 void extendBy(const SbBox2f & 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 SbVec2f & point) const;
70 SbBool intersect(const SbBox2f & box) const;
71 SbVec2f getClosestPoint(const SbVec2f & point) const;
72
73 SbVec2f getCenter(void) const { return (minpt + maxpt) * 0.5f; }
74 void getOrigin(float & originX, float & originY) const
75 { minpt.getValue(originX, originY); }
76 void getSize(float & sizeX, float & sizeY) const
77 { if (isEmpty()) { sizeX = sizeY = 0.0f; }
78 else { sizeX = maxpt[0] - minpt[0]; sizeY = maxpt[1] - minpt[1]; } }
79 float getAspectRatio(void) const
80 { SbDividerChk("SbBox2f::getAspectRatio()", maxpt[1] - minpt[1]);
81 return (maxpt[0] - minpt[0]) / (maxpt[1] - minpt[1]); }
82
83 protected:
84 SbVec2f minpt, maxpt;
85
86 }; // SbBox2f
87
88 COIN_DLL_API inline int operator == (const SbBox2f & b1, const SbBox2f & b2) {
89 return ((b1.getMin() == b2.getMin()) && (b1.getMax() == b2.getMax()));
90 }
91
92 COIN_DLL_API inline int operator != (const SbBox2f & b1, const SbBox2f & b2) {
93 return !(b1 == b2);
94 }
95
96 #endif // !COIN_SBBOX2F_H

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