/** * @RDE_HEADER@ * Interface of AbstractMapObject * $Id$ * $HeadURL$ * $Author$ */ // Own #include "bounding_box.h" #include "situation_map_utils.h" #include //---------------------------------------------------------------------------- namespace SituationMap { BoundingBox::BoundingBox(ExtentType extentType) { reset(); m_extentType = extentType; } BoundingBox::BoundingBox(ExtentType extentType, const Point3D ¢er, double width, double height) : m_extentType(extentType), m_center(center), m_width(width), m_height(height) { } void BoundingBox::reset() { m_extentType = ExtentType::Undefined; m_center = Point3D(); m_width = m_height = std::numeric_limits::lowest(); } BoundingBox::ExtentType BoundingBox::extentType() const { return m_extentType; } void BoundingBox::setExtentType(BoundingBox::ExtentType extentType) { m_extentType = extentType; } bool BoundingBox::isValid() const { return m_extentType != ExtentType::Undefined && !m_center.isNull() && m_width != std::numeric_limits::lowest() && m_height != std::numeric_limits::lowest(); } Point3D BoundingBox::center() const { return m_center; } double BoundingBox::width() const { return m_width; } double BoundingBox::height() const { return m_height; } Point3D BoundingBox::topLeft() const { return Point3D(m_center.x() - width() / 2.0, m_center.y() + height() / 2.0, m_center.z()); } Point3D BoundingBox::topRight() const { return Point3D(m_center.x() + width() / 2.0, m_center.y() + height() / 2.0, m_center.z()); } Point3D BoundingBox::bottomLeft() const { return Point3D(m_center.x() - width() / 2.0, m_center.y() - height() / 2.0, m_center.z()); } Point3D BoundingBox::bottomRight() const { return Point3D(m_center.x() + width() / 2.0, m_center.y() - height() / 2.0, m_center.z()); } Point3D BoundingBox::centerRight() const { return Point3D(m_center.x() + width() / 2.0, m_center.y(), m_center.z()); } PositionCont BoundingBox::positions() const { PositionCont posCont; posCont.reserve(4); posCont.append(topLeft()); posCont.append(topRight()); posCont.append(bottomRight()); posCont.append(bottomLeft()); return posCont; } QString BoundingBox::toString() const { QString asString = toString(m_extentType); asString += QStringLiteral(" center=(%1;%2;%3), width=%4, height=%5") .arg(m_center.x()).arg(m_center.y()).arg(m_center.z()).arg(m_width).arg(m_height); return asString; } QString BoundingBox::toString(BoundingBox::ExtentType value) { switch (value) { case BoundingBox::ExtentType::Undefined: return QLatin1String("Undefined"); case BoundingBox::ExtentType::Sim: return QLatin1String("Sim"); case BoundingBox::ExtentType::Pixel: return QLatin1String("Pixel"); } // switch return QLatin1String("BoundingBox::ExtentTypeERROR"); } //----------------------------------------------------------------------------- // output operator: //----------------------------------------------------------------------------- std::ostream &operator<< (std::ostream &stream, const BoundingBox &value) { stream << value.toString(); return stream; } std::ostream &operator<< (std::ostream &stream, const BoundingBox::ExtentType &value) { stream << BoundingBox::toString(value); return stream; } } // namespace SituationMap