#include "BoundingBox.hpp" #include namespace Slic3r { template BoundingBoxBase::BoundingBoxBase(const std::vector points) { for (typename std::vector::const_iterator it = points.begin(); it != points.end(); ++it) { this->min.x = std::min(it->x, this->min.x); this->min.y = std::min(it->y, this->min.y); this->max.x = std::max(it->x, this->max.x); this->max.y = std::max(it->y, this->max.y); } } template BoundingBox3Base::BoundingBox3Base(const std::vector points) : BoundingBoxBase(points) { for (typename std::vector::const_iterator it = points.begin(); it != points.end(); ++it) { this->min.z = std::min(it->z, this->min.z); this->max.z = std::max(it->z, this->max.z); } } void BoundingBox::polygon(Polygon* polygon) const { polygon->points.clear(); polygon->points.resize(4); polygon->points[0].x = this->min.x; polygon->points[0].y = this->min.y; polygon->points[1].x = this->max.x; polygon->points[1].y = this->min.y; polygon->points[2].x = this->max.x; polygon->points[2].y = this->max.y; polygon->points[3].x = this->min.x; polygon->points[3].y = this->max.y; } template void BoundingBoxBase::scale(double factor) { this->min.scale(factor); this->max.scale(factor); } template void BoundingBoxBase::merge(const BoundingBoxBase &bb) { this->min.x = std::min(bb.min.x, this->min.x); this->min.y = std::min(bb.min.y, this->min.y); this->max.x = std::max(bb.max.x, this->max.x); this->max.y = std::max(bb.max.y, this->max.y); } template void BoundingBox3Base::merge(const BoundingBox3Base &bb) { BoundingBoxBase::merge(bb); this->min.z = std::min(bb.min.z, this->min.z); this->max.z = std::max(bb.max.z, this->max.z); } template PointClass BoundingBox2Base::size() const { return PointClass(this->max.x - this->min.x, this->max.y - this->min.y); } template PointClass BoundingBox3Base::size() const { return PointClass(this->max.x - this->min.x, this->max.y - this->min.y, this->max.z - this->min.z); } template void BoundingBox2Base::translate(coordf_t x, coordf_t y) { this->min.translate(x, y); this->max.translate(x, y); } template void BoundingBox3Base::translate(coordf_t x, coordf_t y, coordf_t z) { this->min.translate(x, y, z); this->max.translate(x, y, z); } template PointClass BoundingBox2Base::center() const { return PointClass( (this->max.x - this->min.x)/2, (this->max.y - this->min.y)/2 ); } template PointClass BoundingBox3Base::center() const { return PointClass( (this->max.x - this->min.x)/2, (this->max.y - this->min.y)/2, (this->max.z - this->min.z)/2 ); } }