19 #ifndef RStarBoundingBox_H 20 #define RStarBoundingBox_H 29 template <std::
size_t dimensions>
38 for (std::size_t axis = 0; axis <
dimensions; axis++)
59 for (std::size_t axis = 0; axis <
dimensions; axis++)
62 if (edges[axis].first > bb.
edges[axis].first)
64 edges[axis].first = bb.
edges[axis].first;
70 edges[axis].second = bb.
edges[axis].second;
82 for (std::size_t axis = 0; axis <
dimensions; axis++)
83 distance += edges[axis].
second - edges[axis].first;
92 for (std::size_t axis = 0; axis <
dimensions; axis++)
93 area *= (
double)(edges[axis].second - edges[axis].first);
102 for (std::size_t axis = 0; axis <
dimensions; axis++)
103 if (bb.
edges[axis].first < edges[axis].first || edges[axis].second < bb.
edges[axis].second)
114 for (std::size_t axis = 0; axis <
dimensions; axis++)
116 if (!(edges[axis].first < bb.
edges[axis].second) || !(bb.
edges[axis].first < edges[axis].second))
127 for (std::size_t axis = 0; area && axis <
dimensions; axis++)
130 const double x1 = edges[axis].first;
131 const double x2 = edges[axis].second;
132 const double y1 = bb.
edges[axis].first;
133 const double y2 = bb.
edges[axis].second;
143 area *= (double)( y2 - y1 );
145 area *= (double)( x2 - y1 );
155 area *= (double)( x2 - x1 );
157 area *= (double)( y2 - x1 );
173 for (std::size_t axis = 0; axis <
dimensions; axis++)
175 t = ((double)edges[axis].first + (
double)edges[axis].second +
176 (double)bb.
edges[axis].first + (
double)bb.
edges[axis].second)
187 for (std::size_t axis = 0; axis <
dimensions; axis++)
188 if (edges[axis].first != bb.
edges[axis].first || edges[axis].second != bb.
edges[axis].second)
198 std::stringstream
name(
"");
200 for (std::size_t axis = 0; axis <
dimensions; axis++)
202 name <<
"(" << edges[axis].first <<
"," << edges[axis].second <<
")";
203 if (axis != dimensions -1)
214 template <std::
size_t dimensions>
228 template <
typename BoundedItem>
230 public std::unary_function< const BoundedItem * const, void >
235 void operator() (
const BoundedItem *
const item)
237 m_bound->stretch(item->bound);
248 template <
typename BoundedItem>
250 public std::binary_function< const BoundedItem * const, const BoundedItem * const, bool >
255 bool operator() (
const BoundedItem *
const bi1,
const BoundedItem *
const bi2)
const 257 return bi1->bound.edges[m_axis].first < bi2->bound.edges[m_axis].first;
261 template <
typename BoundedItem>
263 public std::binary_function< const BoundedItem * const, const BoundedItem * const, bool >
268 bool operator() (
const BoundedItem *
const bi1,
const BoundedItem *
const bi2)
const 270 return bi1->bound.edges[m_axis].second < bi2->bound.edges[m_axis].second;
275 template <
typename BoundedItem>
277 public std::binary_function< const BoundedItem * const, const BoundedItem * const, bool >
282 bool operator() (
const BoundedItem *
const bi1,
const BoundedItem *
const bi2)
const 284 return bi1->bound.distanceFromCenter(*m_center) < bi2->bound.distanceFromCenter(*m_center);
288 template <
typename BoundedItem>
290 public std::binary_function< const BoundedItem * const, const BoundedItem * const, bool >
295 bool operator() (
const BoundedItem *
const bi1,
const BoundedItem *
const bi2)
const 297 return area - bi1->bound.area() < area - bi2->bound.area();
301 template <
typename BoundedItem>
303 public std::binary_function< const BoundedItem * const, const BoundedItem * const, bool >
308 bool operator() (
const BoundedItem *
const bi1,
const BoundedItem *
const bi2)
const 310 return bi1->bound.overlap(*m_center) < bi2->bound.overlap(*m_center);
double distanceFromCenter(const RStarBoundingBox< dimensions > &bb) const
bool operator==(const RStarBoundingBox< dimensions > &bb)
double overlap(const RStarBoundingBox< dimensions > &bb) const
SortBoundedItemsByDistanceFromCenter(const typename BoundedItem::BoundingBox *const center)
SortBoundedItemsByOverlapEnlargement(const typename BoundedItem::BoundingBox *const center)
SortBoundedItemsByFirstEdge(const std::size_t axis)
const BoundedItem::BoundingBox *const m_center
SortBoundedItemsBySecondEdge(const std::size_t axis)
bool stretch(const RStarBoundingBox< dimensions > &bb)
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
static int max(int a, int b)
bool encloses(const RStarBoundingBox< dimensions > &bb) const
RTree::BoundingBox BoundingBox
BoundedItem::BoundingBox * m_bound
StretchBoundingBox(typename BoundedItem::BoundingBox *bound)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
std::string ToString() const
bool overlaps(const RStarBoundingBox< dimensions > &bb) const
SortBoundedItemsByAreaEnlargement(const typename BoundedItem::BoundingBox *center)
std::pair< double, double > edges[dimensions]
static RStarBoundingBox MaximumBounds()
RStarBoundingBox< dimensions > BoundingBox
second_as<> second
Type of time stored in seconds, in double precision.
const BoundedItem::BoundingBox *const m_center