Kstars

skypolygonnode.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Artem Fedoskin <[email protected]>
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 
12 SkyPolygonNode::SkyPolygonNode(LineList *list) : m_list(list), m_polygonNode(new PolyNode)
13 {
14  addChildNode(m_polygonNode);
15 }
16 
17 void 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 
95 void SkyPolygonNode::setColor(QColor color)
96 {
97  m_polygonNode->setColor(color);
98 }
99 
101 {
102  m_polygonNode->hide();
103 }
virtual void hide() override
hides all child nodes (sets opacity of m_opacity to 0)
virtual void show()
makes this node visible
T & last()
Stores dms coordinates for a point in the sky. for converting between coordinate systems.
Definition: skypoint.h:44
virtual void update()
Updates coordinate of the object on SkyMapLite.
Definition: skynode.h:48
QPointF clipLine(SkyPoint *p1, SkyPoint *p2) const
ASSUMES *p1 did not clip but *p2 did.
Definition: projector.cpp:108
const Projector * projector() const
Get the current projector.
Definition: skymaplite.h:323
const T & at(int i) const const
A SkyOpacityNode derived class used for drawing of polygons (both filled and non-filled)
Definition: polynode.h:22
SkyPolygonNode(LineList *list)
Constructor.
SkyList * points()
return the list of points for iterating or appending (or whatever).
Definition: linelist.h:33
void updateGeometry(const QPolygonF &polygon, bool filled)
Update the geometry of polygon.
Definition: polynode.cpp:47
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
int size() const const
virtual void hide()
hides this node
bool checkVisibility(const SkyPoint *p) const
Determine if the skypoint p is likely to be visible in the display window.
Definition: projector.cpp:183
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sun Aug 14 2022 04:14:01 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.