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

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
29class SbBox2d;
30class SbBox2s;
31class SbBox2i32;
32
33class COIN_DLL_API SbBox2f {
34public:
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
83protected:
84 SbVec2f minpt, maxpt;
85
86}; // SbBox2f
87
88COIN_DLL_API inline int operator == (const SbBox2f & b1, const SbBox2f & b2) {
89 return ((b1.getMin() == b2.getMin()) && (b1.getMax() == b2.getMax()));
90}
91
92COIN_DLL_API inline int operator != (const SbBox2f & b1, const SbBox2f & b2) {
93 return !(b1 == b2);
94}
95
96#endif // !COIN_SBBOX2F_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
void getSize(float &sizeX, float &sizeY) const
Definition SbBox2f.h:76
float getAspectRatio(void) const
Definition SbBox2f.h:79
SbBox2f & setBounds(float xmin, float ymin, float xmax, float ymax)
Definition SbBox2f.h:44
const SbVec2f & getMax(void) const
Definition SbBox2f.h:60
SbBox2f(float xmin, float ymin, float xmax, float ymax)
Definition SbBox2f.h:36
void getBounds(SbVec2f &minpoint, SbVec2f &maxpoint) const
Definition SbBox2f.h:54
SbVec2f & getMin(void)
Definition SbBox2f.h:58
SbBox2f(const SbVec2f &minpoint, const SbVec2f &maxpoint)
Definition SbBox2f.h:38
void getOrigin(float &originX, float &originY) const
Definition SbBox2f.h:74
SbBool isEmpty(void) const
Definition SbBox2f.h:66
void getBounds(float &xmin, float &ymin, float &xmax, float &ymax) const
Definition SbBox2f.h:52
const SbVec2f & getMin(void) const
Definition SbBox2f.h:57
SbVec2f getCenter(void) const
Definition SbBox2f.h:73
SbBox2f & setBounds(const SbVec2f &minpoint, const SbVec2f &maxpoint)
Definition SbBox2f.h:46
SbBox2f(void)
Definition SbBox2f.h:35
SbBool hasArea(void) const
Definition SbBox2f.h:67
The SbBox2s class is a 2 dimensional box with short integer coordinates.
Definition SbBox2s.h:34
The SbVec2f class is a 2 dimensional vector with floating point coordinates.
Definition SbVec2f.h:39

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

Generated on Wed Jul 17 2024 for Coin by Doxygen 1.12.0.