From aafcab1e7237d3ccbc80945eb8379a985d567a53 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Mon, 18 May 2015 13:10:34 -0300 Subject: ForceScheme now (hopefully) does not produce NaNs. Removed the Glyph class and placed all scatterplot drawing code inside the Scatterplot class. --- glyph.cpp | 103 -------------------------------------------------------------- 1 file changed, 103 deletions(-) delete mode 100644 glyph.cpp (limited to 'glyph.cpp') diff --git a/glyph.cpp b/glyph.cpp deleted file mode 100644 index f143ee8..0000000 --- a/glyph.cpp +++ /dev/null @@ -1,103 +0,0 @@ -#include "glyph.h" - -#include -#include -#include -#include -#include - -const float PI = 3.1415f; - -Glyph::Glyph(QQuickItem *parent) - : QQuickItem(parent) - , m_size(0) -{ - setFlag(QQuickItem::ItemHasContents); -} - -void Glyph::setSize(qreal size) -{ - if (size == m_size) - return; - - m_size = size; - setWidth(size); - setHeight(size); - emit sizeChanged(); - update(); -} - -void Glyph::setColor(const QColor &color) -{ - if (color == m_color) - return; - - m_color = color; - emit colorChanged(); - update(); -} - -int calculateCircleVertexCount(qreal radius) -{ - // 10 * sqrt(r) \approx 2*pi / acos(1 - 1 / (4*r)) - return (int) (10.0 * sqrt(radius)); -} - -void updateCircleGeometry(QSGGeometry *geometry, const QRectF &bounds) -{ - int vertexCount = geometry->vertexCount(); - float cy = bounds.center().x(); - float cx = bounds.center().y(); - - float theta = 2 * PI / float(vertexCount); - float c = cosf(theta); - float s = sinf(theta); - float x = bounds.width() / 2; - float y = 0; - - QSGGeometry::Point2D *vertexData = geometry->vertexDataAsPoint2D(); - for (int i = 0; i < vertexCount; i++) { - vertexData[i].set(x + cx, y + cy); - - float t = x; - x = c*x - s*y; - y = s*t + c*y; - } -} - -QSGNode *Glyph::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) -{ - QSGGeometryNode *node = 0; - QSGGeometry *geometry = 0; - QSGFlatColorMaterial *material = 0; - int vertexCount = calculateCircleVertexCount(m_size / 2); - - if (!oldNode) { - node = new QSGGeometryNode; - - geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), vertexCount); - geometry->setDrawingMode(GL_POLYGON); - node->setGeometry(geometry); - node->setFlag(QSGNode::OwnsGeometry); - - material = new QSGFlatColorMaterial; - material->setColor(m_color); - node->setMaterial(material); - node->setFlag(QSGNode::OwnsMaterial); - } else { - node = static_cast(oldNode); - geometry = node->geometry(); - geometry->allocate(vertexCount); - } - - updateCircleGeometry(geometry, boundingRect()); - node->markDirty(QSGNode::DirtyGeometry); - - material = static_cast(node->material()); - if (material->color() != m_color) { - material->setColor(m_color); - node->markDirty(QSGNode::DirtyMaterial); - } - - return node; -} -- cgit v1.2.3