1
#include "BoundingBox.hpp"
6
template <class PointClass>
7
BoundingBoxBase<PointClass>::BoundingBoxBase(const std::vector<PointClass> &points)
9
if (points.empty()) CONFESS("Empty point set supplied to BoundingBoxBase constructor");
10
typename std::vector<PointClass>::const_iterator it = points.begin();
11
this->min.x = this->max.x = it->x;
12
this->min.y = this->max.y = it->y;
13
for (++it; it != points.end(); ++it) {
14
this->min.x = std::min(it->x, this->min.x);
15
this->min.y = std::min(it->y, this->min.y);
16
this->max.x = std::max(it->x, this->max.x);
17
this->max.y = std::max(it->y, this->max.y);
20
template BoundingBoxBase<Point>::BoundingBoxBase(const std::vector<Point> &points);
22
template <class PointClass>
23
BoundingBox3Base<PointClass>::BoundingBox3Base(const std::vector<PointClass> &points)
24
: BoundingBoxBase<PointClass>(points)
26
if (points.empty()) CONFESS("Empty point set supplied to BoundingBox3Base constructor");
27
typename std::vector<PointClass>::const_iterator it = points.begin();
28
this->min.z = this->max.z = it->z;
29
for (++it; it != points.end(); ++it) {
30
this->min.z = std::min(it->z, this->min.z);
31
this->max.z = std::max(it->z, this->max.z);
34
template BoundingBox3Base<Pointf3>::BoundingBox3Base(const std::vector<Pointf3> &points);
36
BoundingBox::BoundingBox(const Lines &lines)
39
for (Lines::const_iterator line = lines.begin(); line != lines.end(); ++line) {
40
points.push_back(line->a);
41
points.push_back(line->b);
43
*this = BoundingBox(points);
47
BoundingBox::polygon(Polygon* polygon) const
49
polygon->points.clear();
50
polygon->points.resize(4);
51
polygon->points[0].x = this->min.x;
52
polygon->points[0].y = this->min.y;
53
polygon->points[1].x = this->max.x;
54
polygon->points[1].y = this->min.y;
55
polygon->points[2].x = this->max.x;
56
polygon->points[2].y = this->max.y;
57
polygon->points[3].x = this->min.x;
58
polygon->points[3].y = this->max.y;
61
template <class PointClass> void
62
BoundingBoxBase<PointClass>::scale(double factor)
64
this->min.scale(factor);
65
this->max.scale(factor);
67
template void BoundingBoxBase<Point>::scale(double factor);
68
template void BoundingBoxBase<Pointf3>::scale(double factor);
70
template <class PointClass> void
71
BoundingBoxBase<PointClass>::merge(const PointClass &point)
73
this->min.x = std::min(point.x, this->min.x);
74
this->min.y = std::min(point.y, this->min.y);
75
this->max.x = std::max(point.x, this->max.x);
76
this->max.y = std::max(point.y, this->max.y);
78
template void BoundingBoxBase<Point>::merge(const Point &point);
80
template <class PointClass> void
81
BoundingBoxBase<PointClass>::merge(const BoundingBoxBase<PointClass> &bb)
83
this->min.x = std::min(bb.min.x, this->min.x);
84
this->min.y = std::min(bb.min.y, this->min.y);
85
this->max.x = std::max(bb.max.x, this->max.x);
86
this->max.y = std::max(bb.max.y, this->max.y);
88
template void BoundingBoxBase<Point>::merge(const BoundingBoxBase<Point> &bb);
90
template <class PointClass> void
91
BoundingBox3Base<PointClass>::merge(const PointClass &point)
93
BoundingBoxBase<PointClass>::merge(point);
94
this->min.z = std::min(point.z, this->min.z);
95
this->max.z = std::max(point.z, this->max.z);
97
template void BoundingBox3Base<Pointf3>::merge(const Pointf3 &point);
99
template <class PointClass> void
100
BoundingBox3Base<PointClass>::merge(const BoundingBox3Base<PointClass> &bb)
102
BoundingBoxBase<PointClass>::merge(bb);
103
this->min.z = std::min(bb.min.z, this->min.z);
104
this->max.z = std::max(bb.max.z, this->max.z);
106
template void BoundingBox3Base<Pointf3>::merge(const BoundingBox3Base<Pointf3> &bb);
108
template <class PointClass> PointClass
109
BoundingBoxBase<PointClass>::size() const
111
return PointClass(this->max.x - this->min.x, this->max.y - this->min.y);
113
template Point BoundingBoxBase<Point>::size() const;
115
template <class PointClass> PointClass
116
BoundingBox3Base<PointClass>::size() const
118
return PointClass(this->max.x - this->min.x, this->max.y - this->min.y, this->max.z - this->min.z);
120
template Pointf3 BoundingBox3Base<Pointf3>::size() const;
122
template <class PointClass> void
123
BoundingBoxBase<PointClass>::translate(coordf_t x, coordf_t y)
125
this->min.translate(x, y);
126
this->max.translate(x, y);
128
template void BoundingBoxBase<Point>::translate(coordf_t x, coordf_t y);
130
template <class PointClass> void
131
BoundingBox3Base<PointClass>::translate(coordf_t x, coordf_t y, coordf_t z)
133
this->min.translate(x, y, z);
134
this->max.translate(x, y, z);
136
template void BoundingBox3Base<Pointf3>::translate(coordf_t x, coordf_t y, coordf_t z);
138
template <class PointClass> PointClass
139
BoundingBoxBase<PointClass>::center() const
142
(this->max.x + this->min.x)/2,
143
(this->max.y + this->min.y)/2
146
template Point BoundingBoxBase<Point>::center() const;
148
template <class PointClass> PointClass
149
BoundingBox3Base<PointClass>::center() const
152
(this->max.x + this->min.x)/2,
153
(this->max.y + this->min.y)/2,
154
(this->max.z + this->min.z)/2
157
template Pointf3 BoundingBox3Base<Pointf3>::center() const;
160
REGISTER_CLASS(BoundingBox, "Geometry::BoundingBox");
161
REGISTER_CLASS(BoundingBoxf, "Geometry::BoundingBoxf");
162
REGISTER_CLASS(BoundingBoxf3, "Geometry::BoundingBoxf3");