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

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

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