Use 4 points of precision for circle point coordinates

Sat, 24 Mar 2018 12:51:24 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 24 Mar 2018 12:51:24 +0200
changeset 1325
f9abfc7ba676
parent 1324
563a9b65777b
child 1326
69a90bd2dba2

Use 4 points of precision for circle point coordinates

src/algorithms/geometry.cpp file | annotate | diff | comparison | revisions
src/algorithms/geometry.h file | annotate | diff | comparison | revisions
src/basics.cpp file | annotate | diff | comparison | revisions
src/primitives.cpp file | annotate | diff | comparison | revisions
--- a/src/algorithms/geometry.cpp	Sat Mar 24 12:46:40 2018 +0200
+++ b/src/algorithms/geometry.cpp	Sat Mar 24 12:51:24 2018 +0200
@@ -1,15 +1,26 @@
 #include "geometry.h"
 
 /*
- * getRadialPoint
- *
- * Gets an ordinate of a point in circle.
- * If func == sin, then this gets the Y co-ordinate, if func == cos, then X co-ordinate.
+ * LDraw uses 4 points of precision for sin and cos values. Primitives must be generated
+ * accordingly.
  */
-QPointF pointOnCircumference(int segment, int divisions)
+double ldrawsin(double angle)
+{
+	return roundToDecimals(sin(angle), 4);
+}
+
+double ldrawcos(double angle)
+{
+	return roundToDecimals(cos(angle), 4);
+}
+
+/*
+ * Returns a point on a circumference. LDraw precision is used.
+ */
+QPointF pointOnLDrawCircumference(int segment, int divisions)
 {
 	double angle = (segment * 2 * pi) / divisions;
-	return {cos(angle), sin(angle)};
+	return {ldrawcos(angle), ldrawsin(angle)};
 }
 
 /*
@@ -29,8 +40,8 @@
 
 	for (int i = 0; i < segments; i += 1)
 	{
-		QPointF p0 = radius * ::pointOnCircumference(i, divisions);
-		QPointF p1 = radius * ::pointOnCircumference(i + 1, divisions);
+		QPointF p0 = radius * ::pointOnLDrawCircumference(i, divisions);
+		QPointF p1 = radius * ::pointOnLDrawCircumference(i + 1, divisions);
 		lines.append({p0, p1});
 	}
 
--- a/src/algorithms/geometry.h	Sat Mar 24 12:46:40 2018 +0200
+++ b/src/algorithms/geometry.h	Sat Mar 24 12:51:24 2018 +0200
@@ -1,6 +1,8 @@
 #pragma once
 #include "../main.h"
 
-QPointF pointOnCircumference(int segment, int divisions);
+double ldrawsin(double angle);
+double ldrawcos(double angle);
+QPointF pointOnLDrawCircumference(int segment, int divisions);
 QVector<QLineF> makeCircle(int segments, int divisions, double radius);
 qreal distanceFromPointToRectangle(const QPointF& point, const QRectF& rectangle);
--- a/src/basics.cpp	Sat Mar 24 12:46:40 2018 +0200
+++ b/src/basics.cpp	Sat Mar 24 12:51:24 2018 +0200
@@ -36,7 +36,6 @@
 	return a;
 }
 
-
 void simplify(int& numerator, int& denominator)
 {
 	int factor = gcd(numerator, denominator);
--- a/src/primitives.cpp	Sat Mar 24 12:46:40 2018 +0200
+++ b/src/primitives.cpp	Sat Mar 24 12:51:24 2018 +0200
@@ -372,9 +372,9 @@
 
 	for (int i : conditionalLineSegments)
 	{
-		QPointF p0 = ::pointOnCircumference(i, divisions);
-		QPointF p2 = ::pointOnCircumference(i + 1, divisions);
-		QPointF p3 = ::pointOnCircumference(i - 1, divisions);
+		QPointF p0 = ::pointOnLDrawCircumference(i, divisions);
+		QPointF p2 = ::pointOnLDrawCircumference(i + 1, divisions);
+		QPointF p3 = ::pointOnLDrawCircumference(i - 1, divisions);
 		Vertex v0 = {p0.x(), 0.0, p0.y()};
 		Vertex v1;
 		Vertex v2 = {p2.x(), 0.0, p2.y()};

mercurial