| 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
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
SbVec2f
The SbVec2f class is a 2 dimensional vector with floating point coordinates.This vector class is used...
Definition: SbVec2f.h:39
SbBox2f::getBounds
void getBounds(float &xmin, float &ymin, float &xmax, float &ymax) const
Definition: SbBox2f.h:52
SbBox2f::SbBox2f
SbBox2f(float xmin, float ymin, float xmax, float ymax)
Definition: SbBox2f.h:36
SbBox2f::getMax
const SbVec2f & getMax(void) const
Definition: SbBox2f.h:60
SbBox2f::SbBox2f
SbBox2f(void)
Definition: SbBox2f.h:35
SbBox2d
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:33
SbBox2d::operator!=
int operator!=(const SbBox2d &b1, const SbBox2d &b2)
Definition: SbBox2d.h:92
SbBox2f::getMin
const SbVec2f & getMin(void) const
Definition: SbBox2f.h:57
SbBox2d::operator==
int operator==(const SbBox2d &b1, const SbBox2d &b2)
Definition: SbBox2d.h:88
SbBox2f::setBounds
SbBox2f & setBounds(float xmin, float ymin, float xmax, float ymax)
Definition: SbBox2f.h:44
SbBox2f::getOrigin
void getOrigin(float &originX, float &originY) const
Definition: SbBox2f.h:74
SbBox2f::isEmpty
SbBool isEmpty(void) const
Definition: SbBox2f.h:66
SbBox2f::hasArea
SbBool hasArea(void) const
Definition: SbBox2f.h:67
SbBox2s
The SbBox2s class is a 2 dimensional box with short integer coordinates.This box class is used by oth...
Definition: SbBox2s.h:34
SbBox2f::getBounds
void getBounds(SbVec2f &minpoint, SbVec2f &maxpoint) const
Definition: SbBox2f.h:54
SbBox2f::getAspectRatio
float getAspectRatio(void) const
Definition: SbBox2f.h:79
SbBox2f
The SbBox2f class is a 2 dimensional box with floating point corner coordinates.This box class is use...
Definition: SbBox2f.h:33
SbBox2f::getCenter
SbVec2f getCenter(void) const
Definition: SbBox2f.h:73
SbBox2f::getSize
void getSize(float &sizeX, float &sizeY) const
Definition: SbBox2f.h:76
SbBox2f::SbBox2f
SbBox2f(const SbVec2f &minpoint, const SbVec2f &maxpoint)
Definition: SbBox2f.h:38
SbBox2f::setBounds
SbBox2f & setBounds(const SbVec2f &minpoint, const SbVec2f &maxpoint)
Definition: SbBox2f.h:46
SbBox2f::getMin
SbVec2f & getMin(void)
Definition: SbBox2f.h:58

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