/* * This file is part of the Owl Positioning System (OwlPS). * OwlPS is a project of the University of Franche-Comte * (Université de Franche-Comté), France. * * Copyright © Université de Franche-Comté 2007-2012. * * Corresponding author: Matteo Cypriani * *********************************************************************** * * This software is governed by the CeCILL license under French law and * abiding by the rules of distribution of free software. You can use, * modify and/or redistribute the software under the terms of the CeCILL * license as circulated by CEA, CNRS and INRIA at the following URL: * http://www.cecill.info * * As a counterpart to the access to the source code and rights to copy, * modify and redistribute granted by the license, users are provided * only with a limited warranty and the software's authors, the holder * of the economic rights, and the successive licensors have only * limited liability. * * In this respect, the user's attention is drawn to the risks * associated with loading, using, modifying and/or developing or * reproducing the software by the user in light of its specific status * of free software, that may mean that it is complicated to manipulate, * and that also therefore means that it is reserved for developers and * experienced professionals having in-depth computer knowledge. Users * are therefore encouraged to load and test the software's suitability * as regards their requirements in conditions enabling the security of * their systems and/or data to be ensured and, more generally, to use * and operate it in the same conditions as regards security. * * The fact that you are presently reading this means that you have had * knowledge of the CeCILL license and that you accept its terms. * *********************************************************************** */ #include "area.hh" #include "building.hh" using namespace std ; /* *** Constructors *** */ Area::Area(const Building *_building, const string &_name, const Point3D &p1, const Point3D &p2): building(const_cast(_building)), name(_name) { set_coordinates(p1, p2) ; } /* *** Operations *** */ /** * @return \em true if \em p is into the Area. * @return \em false if \em p is not into the Area. */ bool Area::contains_point(const Point3D &p) const { return p.get_x() >= p_min.get_x() && p.get_x() <= p_max.get_x() && p.get_y() >= p_min.get_y() && p.get_y() <= p_max.get_y() && p.get_z() >= p_min.get_z() && p.get_z() <= p_max.get_z() ; } /** * Changes the Area coordinates so that #p_min is the South-West-lower * point and #p_max the North-East-higher point. */ void Area::reorder_coordinates() { float x1 = p_min.get_x(), y1 = p_min.get_y(), z1 = p_min.get_z(), x2 = p_max.get_x(), y2 = p_max.get_y(), z2 = p_max.get_z(), x_min, x_max, y_min, y_max, z_min, z_max ; // 2-D coordinates (X and Y) // // First point is North-West if (x1 < x2 && y1 > y2) { x_min = x1 ; x_max = x2 ; y_min = y2 ; // We swap the two Y y_max = y1 ; } // First point is South-East else if (x1 > x2 && y1 < y2) { x_min = x2 ; // We swap the two X x_max = x1 ; y_min = y1 ; y_max = y2 ; } // First point is North-East else if (x1 > x2 && y1 > y2) { x_min = x2 ; // We swap the two X x_max = x1 ; y_min = y2 ; // and we swap the two Y y_max = y1 ; } // First point is South-West // (or other cases such as coordinates equal to zero) else { // We swap nothing x_min = x1 ; x_max = x2 ; y_min = y1 ; y_max = y2 ; } // Vertical coordinate (Z) // // First point is lower if (z1 < z2) { z_min = z1 ; z_max = z2 ; } // First point is higher else { // We swap the two Z z_min = z2 ; z_max = z1 ; } p_min = Point3D(x_min, y_min, z_min) ; p_max = Point3D(x_max, y_max, z_max) ; } /* *** Operators *** */ Area& Area::operator=(const Area &source) { if (this == &source) return *this ; building = source.building ; name = source.name ; p_min = source.p_min ; p_max = source.p_max ; return *this ; } bool Area::operator==(const Area &source) const { if (this == &source) return true ; return building == source.building && name == source.name && p_min == source.p_min && p_max == source.p_max ; } /** * Note: to avoid looping, the Building associated with the Area is * not displayed. */ ostream &operator<<(ostream &os, const Area &a) { os << (a.building ? a.building->get_name() : "No building") << ';' << a.name << ';' << a.p_min.get_x() << ';' << a.p_max.get_x() << ';' << a.p_min.get_y() << ';' << a.p_max.get_y() << ';' << a.p_min.get_z() << ';' << a.p_max.get_z() ; return os ; }