Skip to content

Commit

Permalink
cal: convert sin(45d) to sin(45*pi/180)
Browse files Browse the repository at this point in the history
  • Loading branch information
r-a-v-a-s committed Jun 22, 2015
1 parent d88d032 commit 5a19752
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions librecad/src/lib/gui/rs_eventhandler.cpp
Expand Up @@ -24,9 +24,10 @@
**
**********************************************************************/

#include<QObject>
#include "rs_eventhandler.h"
#include <QObject>
#include <QRegularExpression>

This comment has been minimized.

Copy link
@dinkel

dinkel Jun 22, 2015

Contributor

This brakes compiling with QT4 as QRegularExpression it is only available in QT5 (http://doc.qt.io/qt-5/qregularexpression.html).

Officially QT4 seems to be one of the supported versions if not the default if I understand the README.md file correctly.

Is this a problem?

This comment has been minimized.

Copy link
@r-a-v-a-s

r-a-v-a-s Jun 23, 2015

Author Member

I switched it to QRegExp until we know.
The whole project can be converted to QRegularExpression later.
✌️


#include "rs_eventhandler.h"
#include "rs_actioninterface.h"
#include "rs_dialogfactory.h"
#include "rs_commandevent.h"
Expand Down Expand Up @@ -233,6 +234,8 @@ bool RS_EventHandler::cliCalculator(const QString& cmd) const
// RS_DIALOGFACTORY->commandMessage("No math expression");
return false;
}
// convert sin(45d) to sin(45*pi/180)
str.replace(QRegularExpression("(\\d+)d"), "\\1*pi/180");

This comment has been minimized.

Copy link
@dxli

dxli Jun 22, 2015

Member

use c++11 style raw string;
allow 45d, 45 deg, 45.d, -45.d, -.1d,
str.replace(QRegularExpression(R"((\s_[-+]?(\d_[.])?\d+\s_d(eg)?)", Qt::CaseInSensitive), R"(\1_pi/180)");

This comment has been minimized.

Copy link
@r-a-v-a-s

r-a-v-a-s Jun 22, 2015

Author Member

I just realized the decimal case... ;-]
Didn't know about the raw string... thanks.

bool ok=true;
double result=RS_Math::eval(str,&ok);
if(ok)
Expand Down

2 comments on commit 5a19752

@dxli
Copy link
Member

@dxli dxli commented on 5a19752 Jun 22, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ries just mentioned, it's better to do muParser DefinePostfixOprt

@r-a-v-a-s
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started learning both C++ and Qt a few days ago.
Regex I know... DefinePostfixOprt is unknown to me. 😎
Do you want to code it?

Please sign in to comment.