#ifndef slic3r_BoundingBox_hpp_ #define slic3r_BoundingBox_hpp_ #include "libslic3r.h" #include "Point.hpp" #include "Polygon.hpp" namespace Slic3r { typedef Point Size; typedef Point3 Size3; typedef Pointf Sizef; typedef Pointf3 Sizef3; template class BoundingBoxBase { public: PointClass min; PointClass max; bool defined; BoundingBoxBase() : defined(false) {}; BoundingBoxBase(const PointClass &pmin, const PointClass &pmax) : min(pmin), max(pmax), defined(pmin.x < pmax.x && pmin.y < pmax.y) {} BoundingBoxBase(const std::vector &points); void merge(const PointClass &point); void merge(const std::vector &points); void merge(const BoundingBoxBase &bb); void scale(double factor); PointClass size() const; double radius() const; void translate(coordf_t x, coordf_t y); void offset(coordf_t delta); PointClass center() const; bool contains(const PointClass &point) const; bool overlap(const BoundingBoxBase &other) const; }; template class BoundingBox3Base : public BoundingBoxBase { public: BoundingBox3Base() : BoundingBoxBase() {}; BoundingBox3Base(const PointClass &pmin, const PointClass &pmax) : BoundingBoxBase(pmin, pmax) { if (pmin.z >= pmax.z) defined = false; } BoundingBox3Base(const std::vector &points); void merge(const PointClass &point); void merge(const std::vector &points); void merge(const BoundingBox3Base &bb); PointClass size() const; double radius() const; void translate(coordf_t x, coordf_t y, coordf_t z); void offset(coordf_t delta); PointClass center() const; }; class BoundingBox : public BoundingBoxBase { public: void polygon(Polygon* polygon) const; Polygon polygon() const; BoundingBox rotated(double angle) const; BoundingBox rotated(double angle, const Point ¢er) const; void rotate(double angle) { (*this) = this->rotated(angle); } void rotate(double angle, const Point ¢er) { (*this) = this->rotated(angle, center); } BoundingBox() : BoundingBoxBase() {}; BoundingBox(const Point &pmin, const Point &pmax) : BoundingBoxBase(pmin, pmax) {}; BoundingBox(const Points &points) : BoundingBoxBase(points) {}; BoundingBox(const Lines &lines); }; /* class BoundingBox3 : public BoundingBox3Base {}; */ class BoundingBoxf : public BoundingBoxBase { public: BoundingBoxf() : BoundingBoxBase() {}; BoundingBoxf(const Pointf &pmin, const Pointf &pmax) : BoundingBoxBase(pmin, pmax) {}; BoundingBoxf(const std::vector &points) : BoundingBoxBase(points) {}; }; class BoundingBoxf3 : public BoundingBox3Base { public: BoundingBoxf3() : BoundingBox3Base() {}; BoundingBoxf3(const Pointf3 &pmin, const Pointf3 &pmax) : BoundingBox3Base(pmin, pmax) {}; BoundingBoxf3(const std::vector &points) : BoundingBox3Base(points) {}; }; template inline bool operator==(const BoundingBoxBase &bb1, const BoundingBoxBase &bb2) { return bb1.min == bb2.min && bb1.max == bb2.max; } template inline bool operator!=(const BoundingBoxBase &bb1, const BoundingBoxBase &bb2) { return !(bb1 == bb2); } template inline bool empty(const BoundingBoxBase &bb) { return ! bb.defined || bb.min.x >= bb.max.x || bb.min.y >= bb.max.y; } template inline bool empty(const BoundingBox3Base &bb) { return ! bb.defined || bb.min.x >= bb.max.x || bb.min.y >= bb.max.y || bb.min.z >= bb.max.z; } } // namespace Slic3r #endif