File indexing completed on 2024-04-14 03:49:01

0001 /*************************************************************************
0002  *  Copyright (C) 2020 by Caio Jordão Carvalho <caiojcarvalho@gmail.com> *
0003  *                                                                       *
0004  *  This program is free software; you can redistribute it and/or        *
0005  *  modify it under the terms of the GNU General Public License as       *
0006  *  published by the Free Software Foundation; either version 3 of       *
0007  *  the License, or (at your option) any later version.                  *
0008  *                                                                       *
0009  *  This program is distributed in the hope that it will be useful,      *
0010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of       *
0011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
0012  *  GNU General Public License for more details.                         *
0013  *                                                                       *
0014  *  You should have received a copy of the GNU General Public License    *
0015  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.*
0016  *************************************************************************/
0017 
0018 #include "core/markedobject_p.h"
0019 #include "image/polygon.h"
0020 
0021 Polygon::Polygon(MarkedClass* objClass) :
0022     MarkedObject(std::make_unique<MarkedObjectPrivate>(), objClass)
0023 {
0024     d_p->m_objClass = objClass;
0025 }
0026 
0027 Polygon::Polygon(const Polygon* pol) :
0028     MarkedObject (std::make_unique<MarkedObjectPrivate>(), pol->objClass())
0029 {
0030     for (const QPointF& point : *pol)
0031         append(point);
0032 }
0033 
0034 Polygon::Polygon(MarkedClass* objClass, const QPolygonF& polygon) :
0035     MarkedObject (std::make_unique<MarkedObjectPrivate>(), objClass)
0036 {
0037     for (const auto& point : polygon)
0038         append(point);
0039 }
0040 
0041 void Polygon::clear()
0042 {
0043     QPolygonF::clear();
0044 }
0045 
0046 QString Polygon::unitName() const
0047 {
0048     return "pt";
0049 }
0050 
0051 MarkedObject::Type Polygon::type()
0052 {
0053     return MarkedObject::Type::Polygon;
0054 }
0055 
0056 void Polygon::scale(const QPointF offset, const qreal scaleW, const qreal scaleH)
0057 {
0058     for (QPointF& point : *this) {
0059         point -= offset;
0060         point = QPointF(point.x() / scaleW, point.y() / scaleH);
0061     }
0062 }
0063 
0064 void Polygon::unscale(const QPointF offset, const qreal scaleW, const qreal scaleH)
0065 {
0066     for (QPointF& point : *this) {
0067         point = QPointF(point.x() * scaleW, point.y() * scaleH);
0068         point += offset;
0069     }
0070 }