Skip to content

Commit

Permalink
Fix sin/cos and small values display (#1631)
Browse files Browse the repository at this point in the history
* Fix printing very small values for printTextBlock

* Use degrees for sin and cos in block's programming instead of radians

* Fix sin/cos generation for python and js on trik

* Fix printTextBlock for trik too
  • Loading branch information
IKhonakhbeeva authored Feb 17, 2023
1 parent 683154d commit a17e92c
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ void TrikPrintTextBlock::doJob(kitBase::robotModel::robotParts::Display &display
const int x = eval<int>("XCoordinateText");
const int y = eval<int>("YCoordinateText");
const int fontSize = eval<int>("FontSize");
const QString result = boolProperty("Evaluate") ? eval<QString>("PrintText") : stringProperty("PrintText");
const QString result = boolProperty("Evaluate")
? QString::number(QString::number(eval<qreal>("PrintText"), 'f', 6).toDouble())
: stringProperty("PrintText");
const bool redraw = boolProperty("Redraw");

if (!errorsOccured()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
math.cos(@@ARGUMENT@@)
math.cos(@@ARGUMENT@@*pi/180)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
math.sin(@@ARGUMENT@@)
math.sin(@@ARGUMENT@@*pi/180)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Math.cos(@@ARGUMENT@@)
Math.cos(@@ARGUMENT@@*pi/180)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Math.sin(@@ARGUMENT@@)
Math.sin(@@ARGUMENT@@*pi/180)
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ void PrintTextBlock::doJob(kitBase::robotModel::robotParts::Display &display)
{
const int x = eval<int>("XCoordinateText");
const int y = eval<int>("YCoordinateText");
const QString result = boolProperty("Evaluate") ? eval<QString>("PrintText") : stringProperty("PrintText");
const QString result = boolProperty("Evaluate")
? QString::number(QString::number(eval<qreal>("PrintText"), 'f', 6).toDouble())
: stringProperty("PrintText");
const bool redraw = boolProperty("Redraw");

if (!errorsOccured()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ void RobotsBlockParser::addIntrinsicFuctions()
return text;
});

addFloatFunction("sin", [](qreal x) {return qSin(x); });
addFloatFunction("cos", [](qreal x) {return qCos(x); });
addFloatFunction("sin", [](qreal x) { return qSin(M_PI / 180 * x); });
addFloatFunction("cos", [](qreal x) { return qCos(M_PI / 180 * x); });
addFloatFunction("ln", [](qreal x) {return qLn(x); });
addFloatFunction("exp", [](qreal x) {return qExp(x); });
addFloatFunction("asin", [](qreal x) {return qAsin(x); });
Expand Down

0 comments on commit a17e92c

Please sign in to comment.