Kstars

skypolygonnode.cpp
1/*
2 SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
3 SPDX-License-Identifier: GPL-2.0-or-later
4*/
5
6#include "skypolygonnode.h"
7
8#include "ksutils.h"
9#include "linelist.h"
10#include "nodes/polynode.h"
11
12SkyPolygonNode::SkyPolygonNode(LineList *list) : m_list(list), m_polygonNode(new PolyNode)
13{
14 addChildNode(m_polygonNode);
15}
16
17void SkyPolygonNode::update(bool forceClip)
18{
19 if (!m_polygonNode->visible())
20 {
21 m_polygonNode->show();
22 }
23
24 bool isVisible = false, isVisibleLast = false;
25 SkyList *points = m_list->points();
26 QPolygonF polygon;
27 const Projector *m_proj = SkyMapLite::Instance()->projector();
28
29 if (forceClip == false)
30 {
31 for (int i = 0; i < points->size(); ++i)
32 {
33 polygon << m_proj->toScreen(points->at(i).get(), false, &isVisibleLast);
34 isVisible |= isVisibleLast;
35 }
36
37 // If 1+ points are visible, draw it
38 if (polygon.size() && isVisible)
39 {
40 m_polygonNode->updateGeometry(polygon, true);
41 }
42 else
43 {
44 m_polygonNode->hide();
45 }
46
47 return;
48 }
49
50 SkyPoint *pLast = points->last().get();
51 QPointF oLast = m_proj->toScreen(pLast, true, &isVisibleLast);
52 // & with the result of checkVisibility to clip away things below horizon
53 isVisibleLast &= m_proj->checkVisibility(pLast);
54
55 for (int i = 0; i < points->size(); ++i)
56 {
57 SkyPoint *pThis = points->at(i).get();
58 QPointF oThis = m_proj->toScreen(pThis, true, &isVisible);
59
60 // & with the result of checkVisibility to clip away things below horizon
61 isVisible &= m_proj->checkVisibility(pThis);
62
63 if (isVisible && isVisibleLast)
64 {
65 polygon << oThis;
66 }
67 else if (isVisibleLast)
68 {
69 QPointF oMid = m_proj->clipLine(pLast, pThis);
70 polygon << oMid;
71 }
72 else if (isVisible)
73 {
74 QPointF oMid = m_proj->clipLine(pThis, pLast);
75 polygon << oMid;
76 polygon << oThis;
77 }
78
79 pLast = pThis;
80 oLast = oThis;
81 isVisibleLast = isVisible;
82 }
83
84 if (polygon.size())
85 {
86 m_polygonNode->updateGeometry(polygon, true);
87 }
88 else
89 {
90 m_polygonNode->hide();
91 return;
92 }
93}
94
95void SkyPolygonNode::setColor(QColor color)
96{
97 m_polygonNode->setColor(color);
98}
99
101{
102 m_polygonNode->hide();
103}
A simple data container used by LineListIndex.
Definition linelist.h:25
SkyList * points()
return the list of points for iterating or appending (or whatever).
Definition linelist.h:33
A SkyOpacityNode derived class used for drawing of polygons (both filled and non-filled)
Definition polynode.h:23
void updateGeometry(const QPolygonF &polygon, bool filled)
Update the geometry of polygon.
Definition polynode.cpp:47
The Projector class is the primary class that serves as an interface to handle projections.
Definition projector.h:58
QPointF toScreen(const SkyPoint *o, bool oRefract=true, bool *onVisibleHemisphere=nullptr) const
This is exactly the same as toScreenVec but it returns a QPointF.
Definition projector.cpp:93
bool checkVisibility(const SkyPoint *p) const
Determine if the skypoint p is likely to be visible in the display window.
QPointF clipLine(SkyPoint *p1, SkyPoint *p2) const
ASSUMES *p1 did not clip but *p2 did.
const Projector * projector() const
Get the current projector.
Definition skymaplite.h:323
virtual void update()
Updates coordinate of the object on SkyMapLite.
Definition skynode.h:48
virtual void show()
makes this node visible
virtual void hide()
hides this node
SkyPolygonNode(LineList *list)
Constructor.
virtual void hide() override
hides all child nodes (sets opacity of m_opacity to 0)
qsizetype size() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.