File indexing completed on 2024-04-28 03:44:26
0001 /* 0002 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #include "skypolygonnode.h" 0007 0008 #include "ksutils.h" 0009 #include "linelist.h" 0010 #include "nodes/polynode.h" 0011 0012 SkyPolygonNode::SkyPolygonNode(LineList *list) : m_list(list), m_polygonNode(new PolyNode) 0013 { 0014 addChildNode(m_polygonNode); 0015 } 0016 0017 void SkyPolygonNode::update(bool forceClip) 0018 { 0019 if (!m_polygonNode->visible()) 0020 { 0021 m_polygonNode->show(); 0022 } 0023 0024 bool isVisible = false, isVisibleLast = false; 0025 SkyList *points = m_list->points(); 0026 QPolygonF polygon; 0027 const Projector *m_proj = SkyMapLite::Instance()->projector(); 0028 0029 if (forceClip == false) 0030 { 0031 for (int i = 0; i < points->size(); ++i) 0032 { 0033 polygon << m_proj->toScreen(points->at(i).get(), false, &isVisibleLast); 0034 isVisible |= isVisibleLast; 0035 } 0036 0037 // If 1+ points are visible, draw it 0038 if (polygon.size() && isVisible) 0039 { 0040 m_polygonNode->updateGeometry(polygon, true); 0041 } 0042 else 0043 { 0044 m_polygonNode->hide(); 0045 } 0046 0047 return; 0048 } 0049 0050 SkyPoint *pLast = points->last().get(); 0051 QPointF oLast = m_proj->toScreen(pLast, true, &isVisibleLast); 0052 // & with the result of checkVisibility to clip away things below horizon 0053 isVisibleLast &= m_proj->checkVisibility(pLast); 0054 0055 for (int i = 0; i < points->size(); ++i) 0056 { 0057 SkyPoint *pThis = points->at(i).get(); 0058 QPointF oThis = m_proj->toScreen(pThis, true, &isVisible); 0059 0060 // & with the result of checkVisibility to clip away things below horizon 0061 isVisible &= m_proj->checkVisibility(pThis); 0062 0063 if (isVisible && isVisibleLast) 0064 { 0065 polygon << oThis; 0066 } 0067 else if (isVisibleLast) 0068 { 0069 QPointF oMid = m_proj->clipLine(pLast, pThis); 0070 polygon << oMid; 0071 } 0072 else if (isVisible) 0073 { 0074 QPointF oMid = m_proj->clipLine(pThis, pLast); 0075 polygon << oMid; 0076 polygon << oThis; 0077 } 0078 0079 pLast = pThis; 0080 oLast = oThis; 0081 isVisibleLast = isVisible; 0082 } 0083 0084 if (polygon.size()) 0085 { 0086 m_polygonNode->updateGeometry(polygon, true); 0087 } 0088 else 0089 { 0090 m_polygonNode->hide(); 0091 return; 0092 } 0093 } 0094 0095 void SkyPolygonNode::setColor(QColor color) 0096 { 0097 m_polygonNode->setColor(color); 0098 } 0099 0100 void SkyPolygonNode::hide() 0101 { 0102 m_polygonNode->hide(); 0103 }