summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleks Kissinger <aleks0@gmail.com>2019-01-03 14:01:00 +0100
committerAleks Kissinger <aleks0@gmail.com>2019-01-03 14:01:00 +0100
commit99bc4eedae99fc813db3a852139758bca75bddd7 (patch)
treecec779f1a075f8b7e8f5eac02ee8e9441e516f14
parentcbe3074cedac1cc509282a1a0df80cac998355a6 (diff)
fixed many warnings in TikzScene and related files (mostly floating point)
-rw-r--r--src/data/edge.cpp76
-rw-r--r--src/data/edge.h12
-rw-r--r--src/gui/tikzscene.cpp81
-rw-r--r--src/gui/tikzscene.h4
-rw-r--r--src/gui/undocommands.cpp6
-rw-r--r--src/gui/undocommands.h36
-rw-r--r--src/tikzit.h4
-rw-r--r--src/util.cpp34
-rw-r--r--src/util.h16
9 files changed, 139 insertions, 130 deletions
diff --git a/src/data/edge.cpp b/src/data/edge.cpp
index a9acd85..afb1e57 100644
--- a/src/data/edge.cpp
+++ b/src/data/edge.cpp
@@ -27,7 +27,7 @@ Edge::Edge(Node *s, Node *t, QObject *parent) :
QObject(parent), _source(s), _target(t)
{
_data = new GraphElementData(this);
- _edgeNode = 0;
+ _edgeNode = nullptr;
_dirty = true;
if (s != t) {
@@ -35,13 +35,13 @@ Edge::Edge(Node *s, Node *t, QObject *parent) :
_bend = 0;
_inAngle = 0;
_outAngle = 0;
- _weight = 0.4f;
+ _weight = 0.4;
} else {
_basicBendMode = false;
_bend = 0;
_inAngle = 135;
_outAngle = 45;
- _weight = 1.0f;
+ _weight = 1.0;
}
_style = noneEdgeStyle;
updateControls();
@@ -57,7 +57,7 @@ Edge::Edge(Node *s, Node *t, QObject *parent) :
Edge *Edge::copy(QMap<Node*,Node*> *nodeTable)
{
Edge *e;
- if (nodeTable == 0) e = new Edge(_source, _target);
+ if (nodeTable == nullptr) e = new Edge(_source, _target);
else e = new Edge(nodeTable->value(_source), nodeTable->value(_target));
e->setData(_data->copy());
e->setBasicBendMode(_basicBendMode);
@@ -145,12 +145,12 @@ void Edge::setEdgeNode(Node *edgeNode)
{
Node *oldEdgeNode = _edgeNode;
_edgeNode = edgeNode;
- if (oldEdgeNode != 0) oldEdgeNode->deleteLater();
+ if (oldEdgeNode != nullptr) oldEdgeNode->deleteLater();
}
bool Edge::hasEdgeNode()
{
- return _edgeNode != 0;
+ return _edgeNode != nullptr;
}
void Edge::updateControls() {
@@ -158,22 +158,22 @@ void Edge::updateControls() {
QPointF src = _source->point();
QPointF targ = _target->point();
- float dx = (targ.x() - src.x());
- float dy = (targ.y() - src.y());
+ qreal dx = (targ.x() - src.x());
+ qreal dy = (targ.y() - src.y());
- float outAngleR = 0.0f;
- float inAngleR = 0.0f;
+ qreal outAngleR = 0.0;
+ qreal inAngleR = 0.0;
if (_basicBendMode) {
- float angle = std::atan2(dy, dx);
- float bnd = (float)_bend * (M_PI / 180.0f);
+ qreal angle = std::atan2(dy, dx);
+ qreal bnd = static_cast<qreal>(_bend) * (M_PI / 180.0);
outAngleR = angle - bnd;
inAngleR = M_PI + angle + bnd;
- _outAngle = outAngleR * (180.f / M_PI);
- _inAngle = inAngleR * (180.f / M_PI);
+ _outAngle = static_cast<int>(round(outAngleR * (180.0 / M_PI)));
+ _inAngle = static_cast<int>(round(inAngleR * (180.0 / M_PI)));
} else {
- outAngleR = (float)_outAngle * (M_PI / 180.0f);
- inAngleR = (float)_inAngle * (M_PI / 180.0f);
+ outAngleR = static_cast<qreal>(_outAngle) * (M_PI / 180.0);
+ inAngleR = static_cast<qreal>(_inAngle) * (M_PI / 180.0);
}
// TODO: calculate head and tail properly, not just for circles
@@ -192,7 +192,7 @@ void Edge::updateControls() {
}
// give a default distance for self-loops
- _cpDist = (dx==0.0f && dy==0.0f) ? _weight : std::sqrt(dx*dx + dy*dy) * _weight;
+ _cpDist = (almostZero(dx) && almostZero(dy)) ? _weight : std::sqrt(dx*dx + dy*dy) * _weight;
_cp1 = QPointF(src.x() + (_cpDist * std::cos(outAngleR)),
src.y() + (_cpDist * std::sin(outAngleR)));
@@ -200,9 +200,9 @@ void Edge::updateControls() {
_cp2 = QPointF(targ.x() + (_cpDist * std::cos(inAngleR)),
targ.y() + (_cpDist * std::sin(inAngleR)));
- _mid = bezierInterpolateFull (0.5f, _tail, _cp1, _cp2, _head);
- _tailTangent = bezierTangent(0.0f, 0.1f);
- _headTangent = bezierTangent(1.0f, 0.9f);
+ _mid = bezierInterpolateFull (0.5, _tail, _cp1, _cp2, _head);
+ _tailTangent = bezierTangent(0.0, 0.1);
+ _headTangent = bezierTangent(1.0, 0.9);
}
void Edge::setAttributesFromData()
@@ -214,16 +214,16 @@ void Edge::setAttributesFromData()
_bend = -30;
} else if (_data->atom("bend right")) {
_bend = 30;
- } else if (_data->property("bend left") != 0) {
+ } else if (_data->property("bend left") != nullptr) {
_bend = -_data->property("bend left").toInt(&ok);
if (!ok) _bend = -30;
- } else if (_data->property("bend right") != 0) {
+ } else if (_data->property("bend right") != nullptr) {
_bend = _data->property("bend right").toInt(&ok);
if (!ok) _bend = 30;
} else {
_bend = 0;
- if (_data->property("in") != 0 && _data->property("out") != 0) {
+ if (_data->property("in") != nullptr && _data->property("out") != nullptr) {
_basicBendMode = false;
_inAngle = _data->property("in").toInt(&ok);
if (!ok) _inAngle = 0;
@@ -233,10 +233,10 @@ void Edge::setAttributesFromData()
}
if (!_data->property("looseness").isNull()) {
- _weight = _data->property("looseness").toFloat(&ok) / 2.5f;
- if (!ok) _weight = 0.4f;
+ _weight = _data->property("looseness").toDouble(&ok) / 2.5;
+ if (!ok) _weight = 0.4;
} else {
- _weight = (isSelfLoop()) ? 1.0f : 0.4f;
+ _weight = (isSelfLoop()) ? 1.0 : 0.4;
}
//qDebug() << "bend: " << _bend << " in: " << _inAngle << " out: " << _outAngle;
@@ -280,8 +280,8 @@ void Edge::updateData()
}
if (_source == _target) _data->setAtom("loop");
- if (!isSelfLoop() && !isStraight() && _weight != 0.4f)
- _data->setProperty("looseness", QString::number(_weight*2.5f, 'f', 2));
+ if (!isSelfLoop() && !isStraight() && almostEqual(_weight, 0.4))
+ _data->setProperty("looseness", QString::number(_weight*2.5, 'f', 2));
if (_source->isBlankNode()) _sourceAnchor = "center";
else _sourceAnchor = "";
if (_target->isBlankNode()) _targetAnchor = "center";
@@ -325,7 +325,7 @@ int Edge::outAngle() const
return _outAngle;
}
-float Edge::weight() const
+qreal Edge::weight() const
{
return _weight;
}
@@ -335,7 +335,7 @@ bool Edge::basicBendMode() const
return _basicBendMode;
}
-float Edge::cpDist() const
+qreal Edge::cpDist() const
{
return _cpDist;
}
@@ -360,7 +360,7 @@ void Edge::setOutAngle(int outAngle)
_outAngle = outAngle;
}
-void Edge::setWeight(float weight)
+void Edge::setWeight(qreal weight)
{
_weight = weight;
}
@@ -402,18 +402,18 @@ Style *Edge::style() const
return _style;
}
-QPointF Edge::bezierTangent(float start, float end) const
+QPointF Edge::bezierTangent(qreal start, qreal end) const
{
- float dx = bezierInterpolate(end, _tail.x(), _cp1.x(), _cp2.x(), _head.x()) -
+ qreal dx = bezierInterpolate(end, _tail.x(), _cp1.x(), _cp2.x(), _head.x()) -
bezierInterpolate(start, _tail.x(), _cp1.x(), _cp2.x(), _head.x());
- float dy = bezierInterpolate(end, _tail.y(), _cp1.y(), _cp2.y(), _head.y()) -
+ qreal dy = bezierInterpolate(end, _tail.y(), _cp1.y(), _cp2.y(), _head.y()) -
bezierInterpolate(start, _tail.y(), _cp1.y(), _cp2.y(), _head.y());
// normalise
- float len = sqrt(dx*dx + dy * dy);
- if (len != 0) {
- dx = (dx / len) * 0.1f;
- dy = (dy / len) * 0.1f;
+ qreal len = sqrt(dx*dx + dy*dy);
+ if (almostZero(len)) {
+ dx = (dx / len) * 0.1;
+ dy = (dy / len) * 0.1;
}
return QPointF(dx, dy);
diff --git a/src/data/edge.h b/src/data/edge.h
index 27d5bef..909824b 100644
--- a/src/data/edge.h
+++ b/src/data/edge.h
@@ -71,15 +71,15 @@ public:
int bend() const;
int inAngle() const;
int outAngle() const;
- float weight() const;
+ qreal weight() const;
bool basicBendMode() const;
- float cpDist() const;
+ qreal cpDist() const;
void setBasicBendMode(bool mode);
void setBend(int bend);
void setInAngle(int inAngle);
void setOutAngle(int outAngle);
- void setWeight(float weight);
+ void setWeight(qreal weight);
int tikzLine() const;
void setTikzLine(int tikzLine);
@@ -95,7 +95,7 @@ signals:
public slots:
private:
- QPointF bezierTangent(float start, float end) const;
+ QPointF bezierTangent(qreal start, qreal end) const;
QString _sourceAnchor;
QString _targetAnchor;
@@ -115,8 +115,8 @@ private:
int _bend;
int _inAngle;
int _outAngle;
- float _weight;
- float _cpDist;
+ qreal _weight;
+ qreal _cpDist;
QPointF _head;
QPointF _tail;
diff --git a/src/gui/tikzscene.cpp b/src/gui/tikzscene.cpp
index c061221..950bd59 100644
--- a/src/gui/tikzscene.cpp
+++ b/src/gui/tikzscene.cpp
@@ -34,8 +34,8 @@ TikzScene::TikzScene(TikzDocument *tikzDocument, ToolPalette *tools,
StylePalette *styles, QObject *parent) :
QGraphicsScene(parent), _tikzDocument(tikzDocument), _tools(tools), _styles(styles)
{
- _modifyEdgeItem = 0;
- _edgeStartNodeItem = 0;
+ _modifyEdgeItem = nullptr;
+ _edgeStartNodeItem = nullptr;
_drawEdgeItem = new QGraphicsLineItem();
_rubberBandItem = new QGraphicsRectItem();
_enabled = true;
@@ -43,7 +43,7 @@ TikzScene::TikzScene(TikzDocument *tikzDocument, ToolPalette *tools,
setSceneRect(-1000,-1000,2000,2000);
QPen pen;
- pen.setColor(QColor::fromRgbF(0.5f, 0.0f, 0.5f));
+ pen.setColor(QColor::fromRgbF(0.5, 0.0, 0.5));
//pen.setWidth(3.0f);
pen.setCosmetic(true);
_drawEdgeItem->setPen(pen);
@@ -51,7 +51,7 @@ TikzScene::TikzScene(TikzDocument *tikzDocument, ToolPalette *tools,
_drawEdgeItem->setVisible(false);
addItem(_drawEdgeItem);
- pen.setColor(QColor::fromRgbF(0.6f, 0.6f, 0.8f));
+ pen.setColor(QColor::fromRgbF(0.6, 0.6, 0.8));
//pen.setWidth(3.0f);
//QVector<qreal> dash;
//dash << 4.0 << 4.0;
@@ -110,7 +110,7 @@ void TikzScene::graphReplaced()
void TikzScene::extendSelectionUp()
{
bool found = false;
- float m = 0.0f;
+ qreal m = 0.0;
foreach (Node *n, getSelectedNodes()) {
if (!found) {
m = n->point().y();
@@ -128,7 +128,7 @@ void TikzScene::extendSelectionUp()
void TikzScene::extendSelectionDown()
{
bool found = false;
- float m = 0.0f;
+ qreal m = 0.0;
foreach (Node *n, getSelectedNodes()) {
if (!found) {
m = n->point().y();
@@ -146,7 +146,7 @@ void TikzScene::extendSelectionDown()
void TikzScene::extendSelectionLeft()
{
bool found = false;
- float m = 0.0f;
+ qreal m = 0.0;
foreach (Node *n, getSelectedNodes()) {
if (!found) {
m = n->point().x();
@@ -164,7 +164,7 @@ void TikzScene::extendSelectionLeft()
void TikzScene::extendSelectionRight()
{
bool found = false;
- float m = 0.0f;
+ qreal m = 0.0;
foreach (Node *n, getSelectedNodes()) {
if (!found) {
m = n->point().x();
@@ -266,7 +266,7 @@ void TikzScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
}
}
- if (_modifyEdgeItem != 0) {
+ if (_modifyEdgeItem != nullptr) {
// store for undo purposes
Edge *e = _modifyEdgeItem->edge();
_oldBend = e->bend();
@@ -337,15 +337,15 @@ void TikzScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
switch (_tools->currentTool()) {
case ToolPalette::SELECT:
- if (_modifyEdgeItem != 0) {
+ if (_modifyEdgeItem != nullptr) {
Edge *e = _modifyEdgeItem->edge();
// dragging a control point
QPointF src = toScreen(e->source()->point());
QPointF targ = toScreen(e->target()->point());
- float dx1 = targ.x() - src.x();
- float dy1 = targ.y() - src.y();
- float dx2, dy2;
+ qreal dx1 = targ.x() - src.x();
+ qreal dy1 = targ.y() - src.y();
+ qreal dx2, dy2;
if (_firstControlPoint) {
dx2 = mousePos.x() - src.x();
dy2 = mousePos.y() - src.y();
@@ -354,25 +354,26 @@ void TikzScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
dy2 = mousePos.y() - targ.y();
}
- float baseDist = sqrt(dx1*dx1 + dy1*dy1);
- float handleDist = sqrt(dx2*dx2 + dy2*dy2);
- float wcoarseness = 0.1f;
+ qreal baseDist = sqrt(dx1*dx1 + dy1*dy1);
+ qreal handleDist = sqrt(dx2*dx2 + dy2*dy2);
+ qreal wcoarseness = 0.1;
if (!e->isSelfLoop()) {
- if (baseDist != 0) {
+ if (baseDist != 0.0) {
e->setWeight(roundToNearest(wcoarseness, handleDist/baseDist));
} else {
e->setWeight(roundToNearest(wcoarseness, handleDist/GLOBAL_SCALEF));
}
}
- float control_angle = atan2(-dy2, dx2);
+ qreal control_angle = atan2(-dy2, dx2);
int bcoarseness = 15;
+ qreal bcoarsenessi = 1.0/15.0;
if(e->basicBendMode()) {
- float bnd;
- float base_angle = atan2(-dy1, dx1);
+ qreal bnd;
+ qreal base_angle = atan2(-dy1, dx1);
if (_firstControlPoint) {
bnd = base_angle - control_angle;
} else {
@@ -380,12 +381,10 @@ void TikzScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if (bnd > M_PI) bnd -= 2*M_PI;
}
- e->setBend(round(bnd * (180.0f / M_PI) * (1.0f / (float)bcoarseness)) * bcoarseness);
+ e->setBend(static_cast<int>(round(bnd * (180.0 / M_PI) * bcoarsenessi)) * bcoarseness);
} else {
- int bnd = round(control_angle * (180.0f / M_PI) *
- (1.0f / (float)bcoarseness)) *
- bcoarseness;
+ int bnd = static_cast<int>(round(control_angle * (180.0 / M_PI) * bcoarsenessi)) * bcoarseness;
if (_firstControlPoint) {
// TODO: enable moving both control points
// if ([theEvent modifierFlags] & NSAlternateKeyMask) {
@@ -428,7 +427,7 @@ void TikzScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
NodeItem *ni = _nodeItems[n];
// in (rare) cases, the graph can change while we are dragging
- if (ni != 0) {
+ if (ni != nullptr) {
ni->setPos(toScreen(_oldNodePositions[n]) + shift);
ni->writePos();
}
@@ -454,7 +453,7 @@ void TikzScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
break;
case ToolPalette::EDGE:
if (_drawEdgeItem->isVisible()) {
- _edgeEndNodeItem = 0;
+ _edgeEndNodeItem = nullptr;
foreach (QGraphicsItem *gi, items(mousePos)) {
if (NodeItem *ni = dynamic_cast<NodeItem*>(gi)){
_edgeEndNodeItem = ni;
@@ -462,7 +461,7 @@ void TikzScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
}
}
QPointF p1 = _drawEdgeItem->line().p1();
- QPointF p2 = (_edgeEndNodeItem != 0) ? toScreen(_edgeEndNodeItem->node()->point()) : mousePos;
+ QPointF p2 = (_edgeEndNodeItem != nullptr) ? toScreen(_edgeEndNodeItem->node()->point()) : mousePos;
QLineF line(p1, p2);
_drawEdgeItem->setLine(line);
@@ -482,11 +481,11 @@ void TikzScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
switch (_tools->currentTool()) {
case ToolPalette::SELECT:
- if (_modifyEdgeItem != 0) {
+ if (_modifyEdgeItem != nullptr) {
// finished dragging a control point
Edge *e = _modifyEdgeItem->edge();
- if (_oldWeight != e->weight() ||
+ if (!almostEqual(_oldWeight, e->weight()) ||
_oldBend != e->bend() ||
_oldInAngle != e->inAngle() ||
_oldOutAngle != e->outAngle())
@@ -495,7 +494,7 @@ void TikzScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
_tikzDocument->undoStack()->push(cmd);
}
- _modifyEdgeItem = 0;
+ _modifyEdgeItem = nullptr;
} else {
// otherwise, process mouse move normally
QGraphicsScene::mouseReleaseEvent(event);
@@ -517,7 +516,7 @@ void TikzScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
QPointF shift = mousePos - _mouseDownPos;
shift = QPointF(round(shift.x()/GRID_SEP)*GRID_SEP, round(shift.y()/GRID_SEP)*GRID_SEP);
- if (shift.x() != 0 || shift.y() != 0) {
+ if (shift.x() != 0.0 || shift.y() != 0.0) {
QMap<Node*,QPointF> newNodePositions;
foreach (QGraphicsItem *gi, selectedItems()) {
@@ -557,14 +556,14 @@ void TikzScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
break;
case ToolPalette::EDGE:
// add an edge
- if (_edgeStartNodeItem != 0 && _edgeEndNodeItem != 0) {
+ if (_edgeStartNodeItem != nullptr && _edgeEndNodeItem != nullptr) {
Edge *e = new Edge(_edgeStartNodeItem->node(), _edgeEndNodeItem->node(), _tikzDocument);
e->setStyleName(_styles->activeEdgeStyleName());
AddEdgeCommand *cmd = new AddEdgeCommand(this, e);
_tikzDocument->undoStack()->push(cmd);
}
- _edgeStartNodeItem = 0;
- _edgeEndNodeItem = 0;
+ _edgeStartNodeItem = nullptr;
+ _edgeEndNodeItem = nullptr;
_drawEdgeItem->setVisible(false);
break;
case ToolPalette::CROP:
@@ -613,19 +612,19 @@ void TikzScene::keyPressEvent(QKeyEvent *event)
if (event->modifiers() & Qt::ControlModifier) {
QPointF delta(0,0);
- float shift = (event->modifiers() & Qt::ShiftModifier) ? 1.0f : 10.0f;
+ qreal shift = (event->modifiers() & Qt::ShiftModifier) ? 1.0 : 10.0;
switch(event->key()) {
case Qt::Key_Left:
- delta.setX(-0.025f * shift);
+ delta.setX(-0.025 * shift);
break;
case Qt::Key_Right:
- delta.setX(0.025f * shift);
+ delta.setX(0.025 * shift);
break;
case Qt::Key_Up:
- delta.setY(0.025f * shift);
+ delta.setY(0.025 * shift);
break;
case Qt::Key_Down:
- delta.setY(-0.025f * shift);
+ delta.setY(-0.025 * shift);
break;
}
@@ -767,7 +766,7 @@ void TikzScene::pasteFromClipboard()
QRectF srcRect = g->realBbox();
QRectF tgtRect = graph()->realBbox();
- QPointF shift(tgtRect.right() - srcRect.left(), 0.0f);
+ QPointF shift(tgtRect.right() - srcRect.left(), 0.0);
if (shift.x() > 0) {
foreach (Node *n, g->nodes()) {
@@ -890,7 +889,7 @@ void TikzScene::refreshAdjacentEdges(QList<Node*> nodes)
EdgeItem *ei = _edgeItems[e];
// the list "nodes" can be out of date, e.g. if the graph changes while dragging
- if (ei != 0) {
+ if (ei != nullptr) {
if (nodes.contains(ei->edge()->source()) || nodes.contains(ei->edge()->target())) {
ei->edge()->updateControls();
ei->readPos();
diff --git a/src/gui/tikzscene.h b/src/gui/tikzscene.h
index 2a3e988..e8ea2c6 100644
--- a/src/gui/tikzscene.h
+++ b/src/gui/tikzscene.h
@@ -44,7 +44,7 @@ class TikzScene : public QGraphicsScene
Q_OBJECT
public:
TikzScene(TikzDocument *tikzDocument, ToolPalette *tools, StylePalette *styles, QObject *parent);
- ~TikzScene();
+ ~TikzScene() override;
Graph *graph();
QMap<Node*,NodeItem*> &nodeItems();
QMap<Edge*,EdgeItem*> &edgeItems();
@@ -108,7 +108,7 @@ private:
bool _draggingNodes;
QMap<Node*,QPointF> _oldNodePositions;
- float _oldWeight;
+ qreal _oldWeight;
int _oldBend;
int _oldInAngle;
int _oldOutAngle;
diff --git a/src/gui/undocommands.cpp b/src/gui/undocommands.cpp
index f713582..8a00536 100644
--- a/src/gui/undocommands.cpp
+++ b/src/gui/undocommands.cpp
@@ -80,7 +80,7 @@ void MoveCommand::redo()
}
EdgeBendCommand::EdgeBendCommand(TikzScene *scene, Edge *edge,
- float oldWeight, int oldBend,
+ qreal oldWeight, int oldBend,
int oldInAngle, int oldOutAngle, QUndoCommand *parent) :
GraphUpdateCommand(scene, parent),
_edge(edge),
@@ -405,7 +405,7 @@ void ChangeLabelCommand::undo()
foreach (Node *n, _oldLabels.keys()) {
n->setLabel(_oldLabels[n]);
NodeItem *ni = _scene->nodeItems()[n];
- if (ni != 0) ni->updateBounds();
+ if (ni != nullptr) ni->updateBounds();
}
GraphUpdateCommand::undo();
@@ -416,7 +416,7 @@ void ChangeLabelCommand::redo()
foreach (Node *n, _oldLabels.keys()) {
n->setLabel(_newLabel);
NodeItem *ni = _scene->nodeItems()[n];
- if (ni != 0) ni->updateBounds();
+ if (ni != nullptr) ni->updateBounds();
}
GraphUpdateCommand::redo();
diff --git a/src/gui/undocommands.h b/src/gui/undocommands.h
index dc60549..ff51c90 100644
--- a/src/gui/undocommands.h
+++ b/src/gui/undocommands.h
@@ -36,7 +36,7 @@
class GraphUpdateCommand : public QUndoCommand {
public:
explicit GraphUpdateCommand(TikzScene *scene,
- QUndoCommand *parent = 0);
+ QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
protected:
@@ -49,7 +49,7 @@ public:
explicit MoveCommand(TikzScene *scene,
QMap<Node*,QPointF> oldNodePositions,
QMap<Node*,QPointF> newNodePositions,
- QUndoCommand *parent = 0);
+ QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
private:
@@ -61,18 +61,18 @@ class EdgeBendCommand : public GraphUpdateCommand
{
public:
explicit EdgeBendCommand(TikzScene *scene, Edge *edge,
- float oldWeight, int oldBend,
+ qreal oldWeight, int oldBend,
int oldInAngle, int oldOutAngle,
- QUndoCommand *parent = 0);
+ QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
private:
Edge *_edge;
- float _oldWeight;
+ qreal _oldWeight;
int _oldBend;
int _oldInAngle;
int _oldOutAngle;
- float _newWeight;
+ qreal _newWeight;
int _newBend;
int _newInAngle;
int _newOutAngle;
@@ -85,7 +85,7 @@ public:
QMap<int,Node*> deleteNodes,
QMap<int,Edge*> deleteEdges,
QSet<Edge*> selEdges,
- QUndoCommand *parent = 0);
+ QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
private:
@@ -98,7 +98,7 @@ class AddNodeCommand : public GraphUpdateCommand
{
public:
explicit AddNodeCommand(TikzScene *scene, Node *node, QRectF newBounds,
- QUndoCommand *parent = 0);
+ QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
private:
@@ -110,7 +110,7 @@ private:
class AddEdgeCommand : public GraphUpdateCommand
{
public:
- explicit AddEdgeCommand(TikzScene *scene, Edge *edge, QUndoCommand *parent = 0);
+ explicit AddEdgeCommand(TikzScene *scene, Edge *edge, QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
private:
@@ -120,7 +120,7 @@ private:
class ChangeEdgeModeCommand : public GraphUpdateCommand
{
public:
- explicit ChangeEdgeModeCommand(TikzScene *scene, Edge *edge, QUndoCommand *parent = 0);
+ explicit ChangeEdgeModeCommand(TikzScene *scene, Edge *edge, QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
private:
@@ -130,7 +130,7 @@ private:
class ApplyStyleToNodesCommand : public GraphUpdateCommand
{
public:
- explicit ApplyStyleToNodesCommand(TikzScene *scene, QString style, QUndoCommand *parent = 0);
+ explicit ApplyStyleToNodesCommand(TikzScene *scene, QString style, QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
private:
@@ -141,7 +141,7 @@ private:
class ApplyStyleToEdgesCommand : public GraphUpdateCommand
{
public:
- explicit ApplyStyleToEdgesCommand(TikzScene *scene, QString style, QUndoCommand *parent = 0);
+ explicit ApplyStyleToEdgesCommand(TikzScene *scene, QString style, QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
private:
@@ -152,7 +152,7 @@ private:
class PasteCommand : public GraphUpdateCommand
{
public:
- explicit PasteCommand(TikzScene *scene, Graph *graph, QUndoCommand *parent = 0);
+ explicit PasteCommand(TikzScene *scene, Graph *graph, QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
private:
@@ -167,7 +167,7 @@ public:
explicit ChangeLabelCommand(TikzScene *scene,
QMap<Node*,QString> oldLabels,
QString newLabel,
- QUndoCommand *parent = 0);
+ QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
private:
@@ -181,7 +181,7 @@ public:
explicit ReplaceGraphCommand(TikzScene *scene,
Graph *oldGraph,
Graph *newGraph,
- QUndoCommand *parent = 0);
+ QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
private:
@@ -195,7 +195,7 @@ public:
explicit ReflectNodesCommand(TikzScene *scene,
QSet<Node*> nodes,
bool horizontal,
- QUndoCommand *parent = 0);
+ QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
private:
@@ -209,7 +209,7 @@ public:
explicit RotateNodesCommand(TikzScene *scene,
QSet<Node*> nodes,
bool clockwise,
- QUndoCommand *parent = 0);
+ QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
private:
@@ -225,7 +225,7 @@ public:
const QVector<Node*> &newNodeOrder,
const QVector<Edge*> &oldEdgeOrder,
const QVector<Edge*> &newEdgeOrder,
- QUndoCommand *parent = 0);
+ QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
private:
diff --git a/src/tikzit.h b/src/tikzit.h
index 15f0b46..6249b9e 100644
--- a/src/tikzit.h
+++ b/src/tikzit.h
@@ -76,8 +76,8 @@
// Number of pixels between (0,0) and (1,0) at 100% zoom level. This should be
// divisible by 8 to avoid rounding errors with e.g. grid-snapping.
#define GLOBAL_SCALE 40
-#define GLOBAL_SCALEF 40.0f
-#define GLOBAL_SCALEF_INV 0.025f
+#define GLOBAL_SCALEF 40.0
+#define GLOBAL_SCALEF_INV 0.025
#define GRID_N 4
#define GRID_SEP 10
#define GRID_SEPF 10.0f
diff --git a/src/util.cpp b/src/util.cpp
index d5e2b96..72b94eb 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -19,31 +19,31 @@
#include "util.h"
-float bezierInterpolate(float dist, float c0, float c1, float c2, float c3) {
- float distp = 1 - dist;
+qreal bezierInterpolate(qreal dist, qreal c0, qreal c1, qreal c2, qreal c3) {
+ qreal distp = 1 - dist;
return (distp*distp*distp) * c0 +
3 * (distp*distp) * dist * c1 +
3 * (dist*dist) * distp * c2 +
(dist*dist*dist) * c3;
}
-QPointF bezierInterpolateFull (float dist, QPointF c0, QPointF c1, QPointF c2, QPointF c3) {
+QPointF bezierInterpolateFull (qreal dist, QPointF c0, QPointF c1, QPointF c2, QPointF c3) {
return QPointF(bezierInterpolate (dist, c0.x(), c1.x(), c2.x(), c3.x()),
bezierInterpolate (dist, c0.y(), c1.y(), c2.y(), c3.y()));
}
-float roundToNearest(float stepSize, float val) {
- if (stepSize==0.0f) return val;
+qreal roundToNearest(qreal stepSize, qreal val) {
+ if (stepSize==0.0) return val;
else return round(val/stepSize)*stepSize;
}
-float radiansToDegrees (float radians) {
- return (radians * 180.0f) / M_PI;
+qreal radiansToDegrees (qreal radians) {
+ return (radians * 180.0) / M_PI;
}
-float degreesToRadians(float degrees) {
- return (degrees * M_PI) / 180.0f;
+qreal degreesToRadians(qreal degrees) {
+ return (degrees * M_PI) / 180.0;
}
int normaliseAngleDeg (int degrees) {
@@ -56,7 +56,7 @@ int normaliseAngleDeg (int degrees) {
return degrees;
}
-float normaliseAngleRad (float rads) {
+qreal normaliseAngleRad (qreal rads) {
while (rads > M_PI) {
rads -= 2 * M_PI;
}
@@ -66,8 +66,16 @@ float normaliseAngleRad (float rads) {
return rads;
}
-// convert float to string, squashing very small floats to zero
-QString floatToString(float f) {
- if (f >= -0.000001 && f <= 0.000001) return "0";
+bool almostZero(qreal f) {
+ return (f >= -0.000001 && f <= 0.000001);
+}
+
+bool almostEqual(qreal f1, qreal f2) {
+ return almostZero(f1 - f2);
+}
+
+// convert qreal to string, squashing very small qreals to zero
+QString floatToString(qreal f) {
+ if (almostZero(f)) return "0";
else return QString::number(f);
}
diff --git a/src/util.h b/src/util.h
index 89d0c5b..5d1073a 100644
--- a/src/util.h
+++ b/src/util.h
@@ -33,17 +33,19 @@
#endif
// interpolate on a cubic bezier curve
-float bezierInterpolate(float dist, float c0, float c1, float c2, float c3);
-QPointF bezierInterpolateFull (float dist, QPointF c0, QPointF c1, QPointF c2, QPointF c3);
+qreal bezierInterpolate(qreal dist, qreal c0, qreal c1, qreal c2, qreal c3);
+QPointF bezierInterpolateFull (qreal dist, QPointF c0, QPointF c1, QPointF c2, QPointF c3);
// rounding
-float roundToNearest(float stepSize, float val);
-float radiansToDegrees (float radians);
-QString floatToString(float f);
+qreal roundToNearest(qreal stepSize, qreal val);
+qreal radiansToDegrees (qreal radians);
+bool almostZero(qreal f);
+bool almostEqual(qreal f1, qreal f2);
+QString floatToString(qreal f);
// angles
-float degreesToRadians(float degrees);
+qreal degreesToRadians(qreal degrees);
int normaliseAngleDeg (int degrees);
-float normaliseAngleRad (float rads);
+qreal normaliseAngleRad (qreal rads);
#endif // UTIL_H