LCOV - code coverage report
Current view: top level - src/utils/shapes - SUMOPolygon.cpp (source / functions) Coverage Total Hit
Test: lcov.info Lines: 81.0 % 63 51
Test Date: 2026-07-25 16:16:11 Functions: 80.0 % 15 12

            Line data    Source code
       1              : /****************************************************************************/
       2              : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
       3              : // Copyright (C) 2004-2026 German Aerospace Center (DLR) and others.
       4              : // This program and the accompanying materials are made available under the
       5              : // terms of the Eclipse Public License 2.0 which is available at
       6              : // https://www.eclipse.org/legal/epl-2.0/
       7              : // This Source Code may also be made available under the following Secondary
       8              : // Licenses when the conditions for such availability set forth in the Eclipse
       9              : // Public License 2.0 are satisfied: GNU General Public License, version 2
      10              : // or later which is available at
      11              : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
      12              : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
      13              : /****************************************************************************/
      14              : /// @file    SUMOPolygon.cpp
      15              : /// @author  Daniel Krajzewicz
      16              : /// @author  Michael Behrisch
      17              : /// @author  Jakob Erdmann
      18              : /// @date    Jun 2004
      19              : ///
      20              : // A 2D-polygon
      21              : /****************************************************************************/
      22              : #include <config.h>
      23              : 
      24              : #include <utils/iodevices/OutputDevice.h>
      25              : #include <utils/common/FileHelpers.h>
      26              : #include <utils/common/StringUtils.h>
      27              : #include <utils/geom/GeoConvHelper.h>
      28              : 
      29              : #include "SUMOPolygon.h"
      30              : 
      31              : // ===========================================================================
      32              : // member definitions
      33              : // ===========================================================================
      34              : 
      35       147689 : SUMOPolygon::SUMOPolygon(const std::string& id, const std::string& type, const RGBColor& color,
      36              :                          const PositionVector& shape, const bool geo, const bool fill, const double lineWidth,
      37              :                          const double layer, const double angle, const std::string& imgFile, const std::string& name,
      38       147689 :                          const double height, const Parameterised::Map& parameters) :
      39              :     Shape(id, type, color, layer, angle, imgFile, name),
      40              :     Parameterised(parameters),
      41              :     myShape(shape),
      42       147689 :     myGEO(geo),
      43       147689 :     myFill(fill),
      44       147689 :     myLineWidth(lineWidth),
      45       147689 :     myHeight(height) {
      46       147689 : }
      47              : 
      48              : 
      49       168064 : SUMOPolygon::~SUMOPolygon() {}
      50              : 
      51              : 
      52              : const PositionVector&
      53      2888704 : SUMOPolygon::getShape() const {
      54      2888704 :     return myShape;
      55              : }
      56              : 
      57              : 
      58              : PositionVector&
      59       123501 : SUMOPolygon::getShapeRef() {
      60       123501 :     return myShape;
      61              : }
      62              : 
      63              : 
      64              : const std::vector<PositionVector>&
      65            0 : SUMOPolygon::getHoles() const {
      66            0 :     return myHoles;
      67              : }
      68              : 
      69              : 
      70              : bool
      71        24689 : SUMOPolygon::getFill() const {
      72        24689 :     return myFill;
      73              : }
      74              : 
      75              : 
      76              : double
      77        13163 : SUMOPolygon::getLineWidth() const {
      78        13163 :     return myLineWidth;
      79              : }
      80              : 
      81              : 
      82              : double
      83         3839 : SUMOPolygon::getHeight() const {
      84         3839 :     return myHeight;
      85              : }
      86              : 
      87              : 
      88              : void
      89            6 : SUMOPolygon::setFill(bool fill) {
      90            6 :     myFill = fill;
      91            6 : }
      92              : 
      93              : 
      94              : void
      95            6 : SUMOPolygon::setLineWidth(double lineWidth) {
      96            6 :     myLineWidth = lineWidth;
      97            6 : }
      98              : 
      99              : 
     100              : void
     101            0 : SUMOPolygon::setHeight(double height) {
     102            0 :     myHeight = height;
     103            0 : }
     104              : 
     105              : 
     106              : void
     107         2813 : SUMOPolygon::setShape(const PositionVector& shape) {
     108              :     myShape = shape;
     109         2813 : }
     110              : 
     111              : void
     112            0 : SUMOPolygon::setHoles(const std::vector<PositionVector>& holes) {
     113            0 :     myHoles = holes;
     114            0 : }
     115              : 
     116              : 
     117              : void
     118         3761 : SUMOPolygon::writeXML(OutputDevice& out, bool geo) const {
     119         3761 :     out.openTag(SUMO_TAG_POLY);
     120         3761 :     out.writeAttr(SUMO_ATTR_ID, StringUtils::escapeXML(getID()));
     121         3761 :     if (getShapeType().size() > 0) {
     122         3761 :         out.writeAttr(SUMO_ATTR_TYPE, StringUtils::escapeXML(getShapeType()));
     123              :     }
     124         3761 :     out.writeAttr(SUMO_ATTR_COLOR, getShapeColor());
     125         3761 :     out.writeAttr(SUMO_ATTR_FILL,  getFill());
     126         3761 :     if (getLineWidth() != Shape::DEFAULT_LINEWIDTH) {
     127            0 :         out.writeAttr(SUMO_ATTR_LINEWIDTH, getLineWidth());
     128              :     }
     129         3761 :     if (getHeight() != Shape::DEFAULT_HEIGHT) {
     130           77 :         out.writeAttr(SUMO_ATTR_HEIGHT, getHeight());
     131              :     }
     132         3761 :     out.writeAttr(SUMO_ATTR_LAYER, getShapeLayer());
     133         3761 :     if (!getShapeName().empty()) {
     134            0 :         out.writeAttr(SUMO_ATTR_NAME, getShapeName());
     135              :     }
     136         3761 :     PositionVector shape = getShape();
     137         3761 :     if (geo) {
     138          143 :         out.writeAttr(SUMO_ATTR_GEO, true);
     139         1455 :         for (int i = 0; i < (int) shape.size(); i++) {
     140         1312 :             GeoConvHelper::getFinal().cartesian2geo(shape[i]);
     141              :         }
     142              :     }
     143         3761 :     out.setPrecision(gPrecisionGeo);
     144         3761 :     out.writeAttr(SUMO_ATTR_SHAPE, shape);
     145         3761 :     out.setPrecision();
     146         3761 :     if (getShapeNaviDegree() != Shape::DEFAULT_ANGLE) {
     147            0 :         out.writeAttr(SUMO_ATTR_ANGLE, getShapeNaviDegree());
     148              :     }
     149         3761 :     if (getShapeImgFile() != Shape::DEFAULT_IMG_FILE) {
     150            0 :         out.writeAttr(SUMO_ATTR_IMGFILE, getShapeImgFile());
     151              :     }
     152         3761 :     writeParams(out);
     153         3761 :     out.closeTag();
     154         3761 : }
     155              : 
     156              : /****************************************************************************/
        

Generated by: LCOV version 2.0-1