2014-01-06 17:29:10 +00:00
|
|
|
#ifndef slic3r_BoundingBox_hpp_
|
|
|
|
#define slic3r_BoundingBox_hpp_
|
|
|
|
|
2015-12-07 23:39:54 +00:00
|
|
|
#include "libslic3r.h"
|
2014-01-06 17:29:10 +00:00
|
|
|
#include "Point.hpp"
|
|
|
|
#include "Polygon.hpp"
|
|
|
|
|
|
|
|
namespace Slic3r {
|
|
|
|
|
|
|
|
typedef Point Size;
|
|
|
|
typedef Point3 Size3;
|
|
|
|
typedef Pointf Sizef;
|
|
|
|
typedef Pointf3 Sizef3;
|
|
|
|
|
|
|
|
template <class PointClass>
|
|
|
|
class BoundingBoxBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PointClass min;
|
|
|
|
PointClass max;
|
2014-09-21 08:51:36 +00:00
|
|
|
bool defined;
|
2014-01-06 17:29:10 +00:00
|
|
|
|
2014-09-21 08:51:36 +00:00
|
|
|
BoundingBoxBase() : defined(false) {};
|
2016-04-10 17:02:00 +00:00
|
|
|
BoundingBoxBase(const PointClass &pmin, const PointClass &pmax) : min(pmin), max(pmax) {}
|
2014-01-09 18:56:12 +00:00
|
|
|
BoundingBoxBase(const std::vector<PointClass> &points);
|
2014-01-07 11:48:09 +00:00
|
|
|
void merge(const PointClass &point);
|
2014-11-15 21:41:22 +00:00
|
|
|
void merge(const std::vector<PointClass> &points);
|
2014-01-06 18:42:31 +00:00
|
|
|
void merge(const BoundingBoxBase<PointClass> &bb);
|
2014-01-06 17:29:10 +00:00
|
|
|
void scale(double factor);
|
|
|
|
PointClass size() const;
|
|
|
|
void translate(coordf_t x, coordf_t y);
|
2014-07-24 16:32:07 +00:00
|
|
|
void offset(coordf_t delta);
|
2014-01-06 17:29:10 +00:00
|
|
|
PointClass center() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class PointClass>
|
|
|
|
class BoundingBox3Base : public BoundingBoxBase<PointClass>
|
|
|
|
{
|
|
|
|
public:
|
2014-09-21 08:51:36 +00:00
|
|
|
BoundingBox3Base() : BoundingBoxBase<PointClass>() {};
|
2016-04-10 17:02:00 +00:00
|
|
|
BoundingBox3Base(const PointClass &pmin, const PointClass &pmax) : BoundingBoxBase<PointClass>(pmin, pmax) {}
|
2014-01-09 18:56:12 +00:00
|
|
|
BoundingBox3Base(const std::vector<PointClass> &points);
|
2014-01-07 11:48:09 +00:00
|
|
|
void merge(const PointClass &point);
|
2014-11-15 21:41:22 +00:00
|
|
|
void merge(const std::vector<PointClass> &points);
|
2014-01-06 18:42:31 +00:00
|
|
|
void merge(const BoundingBox3Base<PointClass> &bb);
|
2014-01-06 17:29:10 +00:00
|
|
|
PointClass size() const;
|
|
|
|
void translate(coordf_t x, coordf_t y, coordf_t z);
|
2014-07-24 16:32:07 +00:00
|
|
|
void offset(coordf_t delta);
|
2014-01-06 17:29:10 +00:00
|
|
|
PointClass center() const;
|
|
|
|
};
|
|
|
|
|
2014-01-07 11:48:09 +00:00
|
|
|
class BoundingBox : public BoundingBoxBase<Point>
|
2014-01-06 17:29:10 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
void polygon(Polygon* polygon) const;
|
2014-05-13 18:06:01 +00:00
|
|
|
Polygon polygon() const;
|
2014-01-06 17:29:10 +00:00
|
|
|
|
2014-09-21 08:51:36 +00:00
|
|
|
BoundingBox() : BoundingBoxBase<Point>() {};
|
2016-04-10 17:02:00 +00:00
|
|
|
BoundingBox(const Point &pmin, const Point &pmax) : BoundingBoxBase<Point>(pmin, pmax) {};
|
2014-01-09 18:56:12 +00:00
|
|
|
BoundingBox(const Points &points) : BoundingBoxBase<Point>(points) {};
|
|
|
|
BoundingBox(const Lines &lines);
|
2014-01-06 17:29:10 +00:00
|
|
|
};
|
|
|
|
|
2014-01-07 11:48:09 +00:00
|
|
|
/*
|
2014-01-06 17:29:10 +00:00
|
|
|
class BoundingBox3 : public BoundingBox3Base<Point3> {};
|
2014-01-07 11:48:09 +00:00
|
|
|
*/
|
2014-01-06 17:29:10 +00:00
|
|
|
|
2014-06-16 13:18:39 +00:00
|
|
|
class BoundingBoxf : public BoundingBoxBase<Pointf> {
|
|
|
|
public:
|
2014-09-21 08:51:36 +00:00
|
|
|
BoundingBoxf() : BoundingBoxBase<Pointf>() {};
|
2016-04-10 17:02:00 +00:00
|
|
|
BoundingBoxf(const Pointf &pmin, const Pointf &pmax) : BoundingBoxBase<Pointf>(pmin, pmax) {};
|
2014-06-16 13:18:39 +00:00
|
|
|
BoundingBoxf(const std::vector<Pointf> &points) : BoundingBoxBase<Pointf>(points) {};
|
|
|
|
};
|
|
|
|
|
2014-01-06 17:29:10 +00:00
|
|
|
class BoundingBoxf3 : public BoundingBox3Base<Pointf3> {
|
|
|
|
public:
|
2014-09-21 08:51:36 +00:00
|
|
|
BoundingBoxf3() : BoundingBox3Base<Pointf3>() {};
|
2016-04-10 17:02:00 +00:00
|
|
|
BoundingBoxf3(const Pointf3 &pmin, const Pointf3 &pmax) : BoundingBox3Base<Pointf3>(pmin, pmax) {};
|
2014-01-09 18:56:12 +00:00
|
|
|
BoundingBoxf3(const std::vector<Pointf3> &points) : BoundingBox3Base<Pointf3>(points) {};
|
2014-01-06 17:29:10 +00:00
|
|
|
};
|
|
|
|
|
2016-04-10 17:02:00 +00:00
|
|
|
template<typename VT>
|
|
|
|
inline bool operator==(const BoundingBoxBase<VT> &bb1, const BoundingBoxBase<VT> &bb2)
|
|
|
|
{
|
|
|
|
return bb1.min == bb2.min && bb1.max == bb2.max;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename VT>
|
|
|
|
inline bool operator!=(const BoundingBoxBase<VT> &bb1, const BoundingBoxBase<VT> &bb2)
|
|
|
|
{
|
|
|
|
return !(bb1 == bb2);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename VT>
|
|
|
|
inline bool empty(const BoundingBoxBase<VT> &bb)
|
|
|
|
{
|
2016-09-12 11:52:31 +00:00
|
|
|
return bb.min.x > bb.max.x || bb.min.y > bb.max.y;
|
2016-04-10 17:02:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename VT>
|
|
|
|
inline bool empty(const BoundingBox3Base<VT> &bb)
|
|
|
|
{
|
|
|
|
return bb.min.x > bb.max.x || bb.min.y > bb.max.y || bb.min.z > bb.max.z;}
|
2014-01-06 17:29:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|