FTGL 2.4.0

FTBBox.h
Go to the documentation of this file.
1/*
2 * FTGL - OpenGL font library
3 *
4 * Copyright (c) 2001-2004 Henry Maddocks <ftgl@opengl.geek.nz>
5 * Copyright (c) 2008 Sam Hocevar <sam@hocevar.net>
6 * Copyright (c) 2008 Sean Morrison <learner@brlcad.org>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining
9 * a copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be
17 * included in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 */
27
28#ifndef __ftgl__
29# warning This header is deprecated. Please use <FTGL/ftgl.h> from now.
30# include <FTGL/ftgl.h>
31#endif
32
33#ifndef __FTBBox__
34#define __FTBBox__
35
36#ifdef __cplusplus
37
38
42 class FTGL_EXPORT FTBBox
43{
44 public:
48 FTBBox()
49 : lower(0.0f, 0.0f, 0.0f),
50 upper(0.0f, 0.0f, 0.0f)
51 {}
52
56 FTBBox(float lx, float ly, float lz, float ux, float uy, float uz)
57 : lower(lx, ly, lz),
58 upper(ux, uy, uz)
59 {}
60
64 FTBBox(FTPoint l, FTPoint u)
65 : lower(l),
66 upper(u)
67 {}
68
75 FTBBox(FT_GlyphSlot glyph)
76 : lower(0.0f, 0.0f, 0.0f),
77 upper(0.0f, 0.0f, 0.0f)
78 {
79 FT_BBox bbox;
80 FT_Outline_Get_CBox(&(glyph->outline), &bbox);
81
82 lower.X(static_cast<float>(bbox.xMin) / 64.0f);
83 lower.Y(static_cast<float>(bbox.yMin) / 64.0f);
84 lower.Z(0.0f);
85 upper.X(static_cast<float>(bbox.xMax) / 64.0f);
86 upper.Y(static_cast<float>(bbox.yMax) / 64.0f);
87 upper.Z(0.0f);
88 }
89
93 ~FTBBox()
94 {}
95
100 void Invalidate()
101 {
102 lower = FTPoint(1.0f, 1.0f, 1.0f);
103 upper = FTPoint(-1.0f, -1.0f, -1.0f);
104 }
105
112 bool IsValid()
113 {
114 return lower.X() <= upper.X()
115 && lower.Y() <= upper.Y()
116 && lower.Z() <= upper.Z();
117 }
118
124 FTBBox& operator += (const FTPoint vector)
125 {
126 lower += vector;
127 upper += vector;
128
129 return *this;
130 }
131
138 FTBBox& operator |= (const FTBBox& bbox)
139 {
140 if(bbox.lower.X() < lower.X()) lower.X(bbox.lower.X());
141 if(bbox.lower.Y() < lower.Y()) lower.Y(bbox.lower.Y());
142 if(bbox.lower.Z() < lower.Z()) lower.Z(bbox.lower.Z());
143 if(bbox.upper.X() > upper.X()) upper.X(bbox.upper.X());
144 if(bbox.upper.Y() > upper.Y()) upper.Y(bbox.upper.Y());
145 if(bbox.upper.Z() > upper.Z()) upper.Z(bbox.upper.Z());
146
147 return *this;
148 }
149
150 void SetDepth(float depth)
151 {
152 if(depth > 0)
153 upper.Z(lower.Z() + depth);
154 else
155 lower.Z(upper.Z() + depth);
156 }
157
158
159 inline FTPoint const Upper() const
160 {
161 return upper;
162 }
163
164
165 inline FTPoint const Lower() const
166 {
167 return lower;
168 }
169
170 private:
174 FTPoint lower, upper;
175};
176
177#endif //__cplusplus
178
179#endif // __FTBBox__
180
FTBBox
FTBBox is a convenience class for handling bounding boxes.
Definition FTBBox.h:43
FTBBox::FTBBox
FTBBox(FT_GlyphSlot glyph)
Constructor.
Definition FTBBox.h:75
FTBBox::FTBBox
FTBBox(float lx, float ly, float lz, float ux, float uy, float uz)
Constructor.
Definition FTBBox.h:56
FTBBox::Invalidate
void Invalidate()
Mark the bounds invalid by setting all lower dimensions greater than the upper dimensions.
Definition FTBBox.h:100
FTBBox::FTBBox
FTBBox()
Default constructor.
Definition FTBBox.h:48
FTBBox::Lower
FTPoint const Lower() const
Definition FTBBox.h:165
FTBBox::~FTBBox
~FTBBox()
Destructor.
Definition FTBBox.h:93
FTBBox::SetDepth
void SetDepth(float depth)
Definition FTBBox.h:150
FTBBox::IsValid
bool IsValid()
Determines if this bounding box is valid.
Definition FTBBox.h:112
FTBBox::FTBBox
FTBBox(FTPoint l, FTPoint u)
Constructor.
Definition FTBBox.h:64
FTBBox::Upper
FTPoint const Upper() const
Definition FTBBox.h:159
FTPoint
FTPoint class is a basic 3-dimensional point or vector.
Definition FTPoint.h:43
FTPoint::Y
void Y(FTGL_DOUBLE y)
Definition FTPoint.h:250
FTPoint::Z
void Z(FTGL_DOUBLE z)
Definition FTPoint.h:251
FTPoint::X
void X(FTGL_DOUBLE x)
Setters.
Definition FTPoint.h:249
ftgl.h
FTGL_EXPORT
#define FTGL_EXPORT
Definition ftgl.h:134