From 0f34fd437efb936ef29ac91186321aa7251fbfb1 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Tue, 23 May 2023 11:22:33 +0200 Subject: Massive changes in initial port away from Qt. --- geometry.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 6 deletions(-) (limited to 'geometry.cpp') diff --git a/geometry.cpp b/geometry.cpp index ad29438..101911e 100644 --- a/geometry.cpp +++ b/geometry.cpp @@ -4,13 +4,66 @@ static const float PI = 3.1415f; +Point2D::Point2D() +{} + +void Point2D::set(float x, float y) +{ +} + +RectF::RectF(float x, float y, float width, float height) + : m_x(x) + , m_y(y) + , m_width(width) + , m_height(height) +{} + +RectF::RectF(const RectF &other) + : m_x(other.m_x) + , m_y(other.m_y) + , m_width(other.m_width) + , m_height(other.m_height) +{} + +RectF::RectF(const Point2D &p1, const Point2D &p2) + : m_x(fmin(p1.x(), p2.x())) + , m_y(fmin(p1.y(), p2.y())) + , m_width(fabs(p1.x() - p2.x())) + , m_height(fabs(p1.y() - p2.y())) +{} + +bool RectF::contains(float x, float y) const +{ + return (x > m_x && x < m_x + m_width) + && (y > m_y && y < m_y + m_height); +} + +bool RectF::intersects(const RectF &other) const +{ + // TODO + return false; +} + +Geometry::Geometry() +{} + +int Geometry::vertexCount() const +{ + return 0; +} + +Point2D *Geometry::vertexDataAsPoint2D() +{ + return nullptr; +} + int calculateCircleVertexCount(float diameter) { // 10 * sqrt(r) \approx 2*pi / acos(1 - 1 / (4*r)) return int(10.0 * sqrt(diameter / 2)); } -void updateCircleGeometry(QSGGeometry *geometry, float diameter, float cx, float cy) +void updateCircleGeometry(Geometry *geometry, float diameter, float cx, float cy) { int vertexCount = geometry->vertexCount(); @@ -20,7 +73,7 @@ void updateCircleGeometry(QSGGeometry *geometry, float diameter, float cx, float float x = diameter / 2; float y = 0; - QSGGeometry::Point2D *vertexData = geometry->vertexDataAsPoint2D(); + Point2D *vertexData = geometry->vertexDataAsPoint2D(); for (int i = 0; i < vertexCount; i++) { vertexData[i].set(x + cx, y + cy); @@ -30,9 +83,9 @@ void updateCircleGeometry(QSGGeometry *geometry, float diameter, float cx, float } } -void updateRectGeometry(QSGGeometry *geometry, float x, float y, float w, float h) +void updateRectGeometry(Geometry *geometry, float x, float y, float w, float h) { - QSGGeometry::Point2D *vertexData = geometry->vertexDataAsPoint2D(); + Point2D *vertexData = geometry->vertexDataAsPoint2D(); vertexData[0].set(x, y); vertexData[1].set(x + w, y); @@ -40,13 +93,13 @@ void updateRectGeometry(QSGGeometry *geometry, float x, float y, float w, float vertexData[3].set(x, y + h); } -void updateCrossHairGeometry(QSGGeometry *geometry, +void updateCrossHairGeometry(Geometry *geometry, float x, float y, float thickness, float length) { - QSGGeometry::Point2D *vertexData = geometry->vertexDataAsPoint2D(); + Point2D *vertexData = geometry->vertexDataAsPoint2D(); if (geometry->vertexCount() != 12) { return; } -- cgit v1.2.3