From 30f327b2fd25104916bffe6fe76823f0dbe35a72 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Tue, 29 Sep 2015 14:59:59 -0300 Subject: Inital history graph implementation and using linear scales where applicable. - geometry.h for geometry calculation functions - scale.h for implementations of scales (currently only the linear scale) - updated main_view.qml for the new HistoryGraph component - HistoryGraph displays each subsample used as a mini scatterplot (no colors currently) - Scatterplot now uses scale.h for transformations - Code cleanup and some bug fixes --- geometry.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 geometry.cpp (limited to 'geometry.cpp') diff --git a/geometry.cpp b/geometry.cpp new file mode 100644 index 0000000..3a4a861 --- /dev/null +++ b/geometry.cpp @@ -0,0 +1,39 @@ +#include "geometry.h" + +static const float PI = 3.1415f; + +int calculateCircleVertexCount(float radius) +{ + // 10 * sqrt(r) \approx 2*pi / acos(1 - 1 / (4*r)) + return int(10.0 * sqrt(radius)); +} + +void updateCircleGeometry(QSGGeometry *geometry, float radius, float cx, float cy) +{ + int vertexCount = geometry->vertexCount(); + + float theta = 2 * PI / float(vertexCount); + float c = cosf(theta); + float s = sinf(theta); + float x = radius; + 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; + } +} + +void updateRectGeometry(QSGGeometry *geometry, float x, float y, float w, float h) +{ + QSGGeometry::Point2D *vertexData = geometry->vertexDataAsPoint2D(); + + vertexData[0].set(x, y); + vertexData[1].set(x + w, y); + vertexData[2].set(x + w, y + h); + vertexData[3].set(x, y + h); +} -- cgit v1.2.3