From 1a71fd8efa0350d1e121f6792e8fad67e82b25c1 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Thu, 5 Apr 2018 13:20:20 +0200 Subject: fixed name conflict, now builds in MSVC --- src/data/edge.cpp | 32 +++++++------- src/data/graph.cpp | 7 ++- src/data/tikzdocument.cpp | 2 +- src/data/tikzparser.y | 52 +++++++++++----------- src/data/tikzparserdefs.h | 4 ++ src/gui/mainmenu.cpp | 6 ++- src/gui/nodeitem.cpp | 2 +- src/gui/tikzscene.cpp | 107 +++++++++++++++++++++++++++++++++++----------- src/gui/tikzscene.h | 3 ++ src/gui/tikzview.cpp | 33 ++++++++------ src/gui/tikzview.h | 1 + src/gui/undocommands.cpp | 12 +++--- src/main.cpp | 1 - src/tikzit.cpp | 2 +- src/tikzit.h | 9 ++-- src/util.cpp | 6 +++ src/util.h | 6 +++ 17 files changed, 191 insertions(+), 94 deletions(-) (limited to 'src') diff --git a/src/data/edge.cpp b/src/data/edge.cpp index d3396e8..bcf127f 100644 --- a/src/data/edge.cpp +++ b/src/data/edge.cpp @@ -222,21 +222,23 @@ void Edge::updateData() // TODO: style handling? - if (_basicBendMode && _bend != 0) { - QString bendKey; - int b; - if (_bend < 0) { - bendKey = "bend left"; - b = -_bend; - } else { - bendKey = "bend right"; - b = _bend; - } - - if (b == 30) { - _data->setAtom(bendKey); - } else { - _data->setProperty(bendKey, QString::number(b)); + if (_basicBendMode) { + if (_bend != 0) { + QString bendKey; + int b; + if (_bend < 0) { + bendKey = "bend left"; + b = -_bend; + } else { + bendKey = "bend right"; + b = _bend; + } + + if (b == 30) { + _data->setAtom(bendKey); + } else { + _data->setProperty(bendKey, QString::number(b)); + } } } else { _data->setProperty("in", QString::number(_inAngle)); diff --git a/src/data/graph.cpp b/src/data/graph.cpp index 208cd00..33af93d 100644 --- a/src/data/graph.cpp +++ b/src/data/graph.cpp @@ -1,4 +1,5 @@ #include "graph.h" +#include "util.h" #include #include @@ -158,7 +159,9 @@ QString Graph::tikz() code << n->data()->tikz() << " "; code << "(" << n->name() << ") at (" - << n->point().x() << ", " << n->point().y() + << floatToString(n->point().x()) + << ", " + << floatToString(n->point().y()) << ") {" << n->label() << "};\n"; line++; } @@ -230,7 +233,7 @@ Graph *Graph::copyOfSubgraphWithNodes(QSet nds) g->addNode(n1); } foreach (Edge *e, edges()) { - if (nds.contains(e->source()) || nds.contains(e->target())) { + if (nds.contains(e->source()) && nds.contains(e->target())) { g->addEdge(e->copy(&nodeTable)); } } diff --git a/src/data/tikzdocument.cpp b/src/data/tikzdocument.cpp index eeb4e14..4a813ad 100644 --- a/src/data/tikzdocument.cpp +++ b/src/data/tikzdocument.cpp @@ -85,7 +85,7 @@ void TikzDocument::save() { QSettings settings("tikzit", "tikzit"); settings.setValue("previous-file-path", fi.absolutePath()); - if (file.open(QIODevice::ReadWrite)) { + if (file.open(QIODevice::WriteOnly)) { QTextStream stream(&file); stream << _tikz; file.close(); diff --git a/src/data/tikzparser.y b/src/data/tikzparser.y index 76674f1..6e708a3 100644 --- a/src/data/tikzparser.y +++ b/src/data/tikzparser.y @@ -25,6 +25,7 @@ * along with this program. If not, see . */ + #include "tikzparserdefs.h" %} @@ -62,7 +63,7 @@ #include "graphelementproperty.h" #include "tikzlexer.h" -#import "tikzassembler.h" +#include "tikzassembler.h" /* the assembler (used by this parser) is stored in the lexer state as "extra" data */ #define assembler yyget_extra(scanner) @@ -71,7 +72,7 @@ void yyerror(YYLTYPE *yylloc, void *scanner, const char *str) { // TODO: implement reportError() //assembler->reportError(str, yylloc); - qDebug() << "parse error: " << str; + qDebug() << "\nparse error: " << str << " line:" << yylloc->first_line; } %} @@ -104,7 +105,7 @@ void yyerror(YYLTYPE *yylloc, void *scanner, const char *str) { %token RIGHTBRACKET "]" %token FULLSTOP "." %token EQUALS "=" -%token COORD "co-ordinate" +%token TCOORD "coordinate" %token PROPSTRING "key/value string" %token REFSTRING "string" %token DELIMITEDSTRING "{-delimited string" @@ -187,7 +188,7 @@ property: val: PROPSTRING { $$ = $1; } | DELIMITEDSTRING { $$ = $1; }; nodename: "(" REFSTRING ")" { $$ = $2; }; -node: "\\node" optproperties nodename "at" COORD DELIMITEDSTRING ";" +node: "\\node" optproperties nodename "at" TCOORD DELIMITEDSTRING ";" { Node *node = new Node(); @@ -240,36 +241,39 @@ edge: "\\draw" optproperties noderef "to" optedgenode optnoderef ";" t = s; } - Edge *edge = new Edge(s, t); - if ($2) { - edge->setData($2); - edge->setAttributesFromData(); - } + // if the source or the target of the edge doesn't exist, quietly ignore it. + if (s != 0 && t != 0) { + Edge *edge = new Edge(s, t); + if ($2) { + edge->setData($2); + edge->setAttributesFromData(); + } - if ($5) - edge->setEdgeNode($5); - if ($3.anchor) { - edge->setSourceAnchor(QString($3.anchor)); - free($3.anchor); - } + if ($5) + edge->setEdgeNode($5); + if ($3.anchor) { + edge->setSourceAnchor(QString($3.anchor)); + free($3.anchor); + } - if ($6.node) { - if ($6.anchor) { - edge->setTargetAnchor(QString($6.anchor)); - free($6.anchor); + if ($6.node) { + if ($6.anchor) { + edge->setTargetAnchor(QString($6.anchor)); + free($6.anchor); + } + } else { + edge->setTargetAnchor(edge->sourceAnchor()); } - } else { - edge->setTargetAnchor(edge->sourceAnchor()); - } - assembler->graph()->addEdge(edge); + assembler->graph()->addEdge(edge); + } }; ignoreprop: val | val "=" val; ignoreprops: ignoreprop ignoreprops | ; optignoreprops: "[" ignoreprops "]"; boundingbox: - "\\path" optignoreprops COORD "rectangle" COORD ";" + "\\path" optignoreprops TCOORD "rectangle" TCOORD ";" { assembler->graph()->setBbox(QRectF(*$3, *$5)); delete $3; diff --git a/src/data/tikzparserdefs.h b/src/data/tikzparserdefs.h index b51a8c9..1625136 100644 --- a/src/data/tikzparserdefs.h +++ b/src/data/tikzparserdefs.h @@ -1,6 +1,8 @@ #ifndef TIKZPARSERDEFS_H #define TIKZPARSERDEFS_H +#define YY_NO_UNISTD_H 1 + #include "graphelementproperty.h" #include "graphelementdata.h" #include "node.h" @@ -15,4 +17,6 @@ struct noderef { char *anchor; }; +inline int isatty(void*) { return 0; } + #endif // TIKZPARSERDEFS_H diff --git a/src/gui/mainmenu.cpp b/src/gui/mainmenu.cpp index dfb447f..0166caf 100644 --- a/src/gui/mainmenu.cpp +++ b/src/gui/mainmenu.cpp @@ -80,12 +80,14 @@ void MainMenu::on_actionDelete_triggered() void MainMenu::on_actionSelect_All_triggered() { - // TODO + if (tikzit->activeWindow() != 0) + tikzit->activeWindow()->tikzScene()->selectAllNodes(); } void MainMenu::on_actionDeselect_All_triggered() { - // TODO + if (tikzit->activeWindow() != 0) + tikzit->activeWindow()->tikzScene()->deselectAll(); } diff --git a/src/gui/nodeitem.cpp b/src/gui/nodeitem.cpp index 36d488c..06b46ff 100644 --- a/src/gui/nodeitem.cpp +++ b/src/gui/nodeitem.cpp @@ -94,7 +94,7 @@ void NodeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidge QPainterPath NodeItem::shape() const { QPainterPath path; - path.addEllipse(QPointF(0,0), GLOBAL_SCALEF * 0.1, GLOBAL_SCALEF * 0.1); + path.addEllipse(QPointF(0,0), GLOBAL_SCALEF * 0.2, GLOBAL_SCALEF * 0.2); return path; } diff --git a/src/gui/tikzscene.cpp b/src/gui/tikzscene.cpp index 59faa65..24f4ad1 100644 --- a/src/gui/tikzscene.cpp +++ b/src/gui/tikzscene.cpp @@ -8,6 +8,7 @@ #include #include #include +#include TikzScene::TikzScene(TikzDocument *tikzDocument, ToolPalette *tools, QObject *parent) : @@ -16,15 +17,28 @@ TikzScene::TikzScene(TikzDocument *tikzDocument, ToolPalette *tools, QObject *pa _modifyEdgeItem = 0; _edgeStartNodeItem = 0; _drawEdgeItem = new QGraphicsLineItem(); - setSceneRect(-310,-230,620,450); + _rubberBandItem = new QGraphicsRectItem(); + //setSceneRect(-310,-230,620,450); + setSceneRect(-1000,-1000,2000,2000); QPen pen; pen.setColor(QColor::fromRgbF(0.5f, 0.0f, 0.5f)); pen.setWidth(3); + pen.setCosmetic(true); _drawEdgeItem->setPen(pen); _drawEdgeItem->setLine(0,0,0,0); _drawEdgeItem->setVisible(false); addItem(_drawEdgeItem); + + pen.setColor(QColor::fromRgbF(0.6f, 0.6f, 0.8f)); + pen.setWidth(3); + QVector dash; + dash << 4.0 << 4.0; + pen.setDashPattern(dash); + _rubberBandItem->setPen(pen); + + _rubberBandItem->setVisible(false); + addItem(_rubberBandItem); } TikzScene::~TikzScene() { @@ -71,7 +85,7 @@ void TikzScene::mousePressEvent(QGraphicsSceneMouseEvent *event) // disable rubber band drag, which will clear the selection. Only re-enable it // for the SELECT tool, and when no control point has been clicked. - views()[0]->setDragMode(QGraphicsView::NoDrag); + //views()[0]->setDragMode(QGraphicsView::NoDrag); // radius of a control point for bezier edges, in scene coordinates qreal cpR = GLOBAL_SCALEF * (0.05); @@ -113,9 +127,23 @@ void TikzScene::mousePressEvent(QGraphicsSceneMouseEvent *event) _oldWeight = e->weight(); } else { // since we are not dragging a control point, process the click normally - views()[0]->setDragMode(QGraphicsView::RubberBandDrag); + //views()[0]->setDragMode(QGraphicsView::RubberBandDrag); QGraphicsScene::mousePressEvent(event); + if (items(_mouseDownPos).isEmpty()) { + _rubberBandItem->setRect(QRectF(_mouseDownPos,_mouseDownPos)); + _rubberBandItem->setVisible(true); + qDebug() << "starting rubber band drag"; + } + +// foreach (QGraphicsItem *gi, items()) { +// if (EdgeItem *ei = dynamic_cast(gi)) { +// //qDebug() << "got an edge item: " << ei; +// ei->setFlag(QGraphicsItem::ItemIsSelectable, false); +// //ei->setSelected(true); +// } +// } + // save current node positions for undo support _oldNodePositions.clear(); foreach (QGraphicsItem *gi, selectedItems()) { @@ -155,7 +183,7 @@ void TikzScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) QPointF mousePos = event->scenePos(); //QRectF rb = views()[0]->rubberBandRect(); //invalidate(-800,-800,1600,1600); - invalidate(QRectF(), QGraphicsScene::BackgroundLayer); + //invalidate(QRectF(), QGraphicsScene::BackgroundLayer); switch (_tools->currentTool()) { case ToolPalette::SELECT: @@ -244,8 +272,7 @@ void TikzScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) // apply the same offset to all nodes, otherwise we get odd rounding behaviour with // multiple selection. QPointF shift = mousePos - _mouseDownPos; - int gridSize = GLOBAL_SCALE / 8; - shift = QPointF(round(shift.x()/gridSize)*gridSize, round(shift.y()/gridSize)*gridSize); + shift = QPointF(round(shift.x()/GRID_SEP)*GRID_SEP, round(shift.y()/GRID_SEP)*GRID_SEP); foreach (Node *n, _oldNodePositions.keys()) { NodeItem *ni = _nodeItems[n]; @@ -257,6 +284,15 @@ void TikzScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) } else { // otherwise, process mouse move normally QGraphicsScene::mouseMoveEvent(event); + + if (_rubberBandItem->isVisible()) { + qreal left = std::min(_mouseDownPos.x(), mousePos.x()); + qreal top = std::min(_mouseDownPos.y(), mousePos.y()); + qreal w = std::abs(_mouseDownPos.x() - mousePos.x()); + qreal h = std::abs(_mouseDownPos.y() - mousePos.y()); + + _rubberBandItem->setRect(QRectF(left, top, w, h)); + } } break; @@ -308,6 +344,19 @@ void TikzScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) // otherwise, process mouse move normally QGraphicsScene::mouseReleaseEvent(event); + if (_rubberBandItem->isVisible()) { + QPainterPath sel; + sel.addRect(_rubberBandItem->rect()); + foreach (QGraphicsItem *gi, items()) { + if (NodeItem *ni = dynamic_cast(gi)) { + if (sel.contains(toScreen(ni->node()->point()))) ni->setSelected(true); + } + } + //setSelectionArea(sel); + } + + _rubberBandItem->setVisible(false); + if (!_oldNodePositions.empty()) { QMap newNodePositions; @@ -329,8 +378,7 @@ void TikzScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) break; case ToolPalette::VERTEX: { - int gridSize = GLOBAL_SCALE / 8; - QPointF gridPos(round(mousePos.x()/gridSize)*gridSize, round(mousePos.y()/gridSize)*gridSize); + QPointF gridPos(round(mousePos.x()/GRID_SEP)*GRID_SEP, round(mousePos.y()/GRID_SEP)*GRID_SEP); Node *n = new Node(_tikzDocument); n->setName(graph()->freshNodeName()); n->setPoint(fromScreen(gridPos)); @@ -460,7 +508,6 @@ void TikzScene::pasteFromClipboard() QRectF tgtRect = graph()->realBbox(); QPointF shift(tgtRect.right() - srcRect.left(), 0.0f); - // shift g to the right until it is in free space if (shift.x() > 0) { foreach (Node *n, g->nodes()) { n->setPoint(n->point() + shift); @@ -472,6 +519,18 @@ void TikzScene::pasteFromClipboard() } } +void TikzScene::selectAllNodes() +{ + foreach (NodeItem *ni, _nodeItems.values()) { + ni->setSelected(true); + } +} + +void TikzScene::deselectAll() +{ + selectedItems().clear(); +} + void TikzScene::getSelection(QSet &selNodes, QSet &selEdges) { foreach (QGraphicsItem *gi, selectedItems()) { @@ -511,21 +570,21 @@ void TikzScene::reloadStyles() void TikzScene::refreshSceneBounds() { - if (!views().empty()) { - QGraphicsView *v = views().first(); - QRectF viewB = v->mapToScene(v->viewport()->rect()).boundingRect(); - //QPointF tl = v->mapToScene(viewB.topLeft()); - //viewB.setTopLeft(tl); - - QRectF bounds = viewB.united(rectToScreen(graph()->realBbox().adjusted(-1.0f, -1.0f, 1.0f, 1.0f))); - qDebug() << viewB; - - if (bounds != sceneRect()) { - QPointF c = viewB.center(); - setSceneRect(bounds); - v->centerOn(c); - } - } +// if (!views().empty()) { +// QGraphicsView *v = views().first(); +// QRectF viewB = v->mapToScene(v->viewport()->rect()).boundingRect(); +// //QPointF tl = v->mapToScene(viewB.topLeft()); +// //viewB.setTopLeft(tl); + +// QRectF bounds = viewB.united(rectToScreen(graph()->realBbox().adjusted(-1.0f, -1.0f, 1.0f, 1.0f))); +// //qDebug() << viewB; + +// if (bounds != sceneRect()) { +// QPointF c = viewB.center(); +// setSceneRect(bounds); +// v->centerOn(c); +// } +// } //setBounds(graphB); } diff --git a/src/gui/tikzscene.h b/src/gui/tikzscene.h index b551abd..f7735ee 100644 --- a/src/gui/tikzscene.h +++ b/src/gui/tikzscene.h @@ -41,6 +41,8 @@ public: void copyToClipboard(); void cutToClipboard(); void pasteFromClipboard(); + void selectAllNodes(); + void deselectAll(); public slots: void graphReplaced(); @@ -56,6 +58,7 @@ private: QMap _nodeItems; QMap _edgeItems; QGraphicsLineItem *_drawEdgeItem; + QGraphicsRectItem *_rubberBandItem; EdgeItem *_modifyEdgeItem; NodeItem *_edgeStartNodeItem; NodeItem *_edgeEndNodeItem; diff --git a/src/gui/tikzview.cpp b/src/gui/tikzview.cpp index b8ae1c0..60dc2bc 100644 --- a/src/gui/tikzview.cpp +++ b/src/gui/tikzview.cpp @@ -7,7 +7,7 @@ TikzView::TikzView(QWidget *parent) : QGraphicsView(parent) { setRenderHint(QPainter::Antialiasing); - setDragMode(QGraphicsView::RubberBandDrag); + //setDragMode(QGraphicsView::RubberBandDrag); _scale = 1.0f; } @@ -24,10 +24,15 @@ void TikzView::zoomOut() scale(0.625,0.625); } +void TikzView::setScene(QGraphicsScene *scene) +{ + QGraphicsView::setScene(scene); + centerOn(QPointF(0.0f,-230.0f)); +} + void TikzView::drawBackground(QPainter *painter, const QRectF &rect) { // draw the grid - int step = GLOBAL_SCALE / 8; QPen pen1; pen1.setWidth(1); @@ -43,38 +48,38 @@ void TikzView::drawBackground(QPainter *painter, const QRectF &rect) painter->setPen(pen1); if (_scale > 0.2f) { - for (int x = -step; x > rect.left(); x -= step) { - if (x % (step * 8) != 0) painter->drawLine(x, rect.top(), x, rect.bottom()); + for (int x = -GRID_SEP; x > rect.left(); x -= GRID_SEP) { + if (x % (GRID_SEP * GRID_N) != 0) painter->drawLine(x, rect.top(), x, rect.bottom()); } - for (int x = step; x < rect.right(); x += step) { - if (x % (step * 8) != 0) painter->drawLine(x, rect.top(), x, rect.bottom()); + for (int x = GRID_SEP; x < rect.right(); x += GRID_SEP) { + if (x % (GRID_SEP * GRID_N) != 0) painter->drawLine(x, rect.top(), x, rect.bottom()); } - for (int y = -step; y > rect.top(); y -= step) { - if (y % (step * 8) != 0) painter->drawLine(rect.left(), y, rect.right(), y); + for (int y = -GRID_SEP; y > rect.top(); y -= GRID_SEP) { + if (y % (GRID_SEP * GRID_N) != 0) painter->drawLine(rect.left(), y, rect.right(), y); } - for (int y = step; y < rect.bottom(); y += step) { - if (y % (step * 8) != 0) painter->drawLine(rect.left(), y, rect.right(), y); + for (int y = GRID_SEP; y < rect.bottom(); y += GRID_SEP) { + if (y % (GRID_SEP * GRID_N) != 0) painter->drawLine(rect.left(), y, rect.right(), y); } } painter->setPen(pen2); - for (int x = -step*8; x > rect.left(); x -= step*8) { + for (int x = -GRID_SEP*GRID_N; x > rect.left(); x -= GRID_SEP*GRID_N) { painter->drawLine(x, rect.top(), x, rect.bottom()); } - for (int x = step*8; x < rect.right(); x += step*8) { + for (int x = GRID_SEP*GRID_N; x < rect.right(); x += GRID_SEP*GRID_N) { painter->drawLine(x, rect.top(), x, rect.bottom()); } - for (int y = -step*8; y > rect.top(); y -= step*8) { + for (int y = -GRID_SEP*GRID_N; y > rect.top(); y -= GRID_SEP*GRID_N) { painter->drawLine(rect.left(), y, rect.right(), y); } - for (int y = step*8; y < rect.bottom(); y += step*8) { + for (int y = GRID_SEP*GRID_N; y < rect.bottom(); y += GRID_SEP*GRID_N) { painter->drawLine(rect.left(), y, rect.right(), y); } diff --git a/src/gui/tikzview.h b/src/gui/tikzview.h index f89729b..cb41fd4 100644 --- a/src/gui/tikzview.h +++ b/src/gui/tikzview.h @@ -23,6 +23,7 @@ public: public slots: void zoomIn(); void zoomOut(); + void setScene(QGraphicsScene *scene); protected: void drawBackground(QPainter *painter, const QRectF &rect); private: diff --git a/src/gui/undocommands.cpp b/src/gui/undocommands.cpp index c9ca041..f64b1db 100644 --- a/src/gui/undocommands.cpp +++ b/src/gui/undocommands.cpp @@ -312,6 +312,12 @@ void PasteCommand::redo() _scene->clearSelection(); _scene->graph()->insertGraph(_graph); + foreach (Edge *e, _graph->edges()) { + EdgeItem *ei = new EdgeItem(e); + _scene->edgeItems().insert(e, ei); + _scene->addItem(ei); + } + foreach (Node *n, _graph->nodes()) { n->attachStyle(); // in case styles have changed NodeItem *ni = new NodeItem(n); @@ -320,11 +326,5 @@ void PasteCommand::redo() ni->setSelected(true); } - foreach (Edge *e, _graph->edges()) { - EdgeItem *ei = new EdgeItem(e); - _scene->edgeItems().insert(e, ei); - _scene->addItem(ei); - } - GraphUpdateCommand::redo(); } diff --git a/src/main.cpp b/src/main.cpp index 4433f58..b15840d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -20,6 +20,5 @@ int main(int argc, char *argv[]) a.setQuitOnLastWindowClosed(false); tikzit = new Tikzit(); tikzit->init(&a); - return a.exec(); } diff --git a/src/tikzit.cpp b/src/tikzit.cpp index 53e83b6..78cb7a1 100644 --- a/src/tikzit.cpp +++ b/src/tikzit.cpp @@ -36,7 +36,7 @@ void Tikzit::init(QApplication *app) QString styleFile = settings.value("previous-tikzstyles-file").toString(); if (!styleFile.isEmpty()) loadStyles(styleFile); - connect(app, &QApplication::focusChanged, this, &focusChanged); + //connect(app, &QApplication::focusChanged, this, &focusChanged); } //QMenuBar *Tikzit::mainMenu() const diff --git a/src/tikzit.h b/src/tikzit.h index 5b23083..39aa9e4 100644 --- a/src/tikzit.h +++ b/src/tikzit.h @@ -49,9 +49,12 @@ // 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 80 -#define GLOBAL_SCALEF 80.0f -#define GLOBAL_SCALEF_INV 0.0125f +#define GLOBAL_SCALE 40 +#define GLOBAL_SCALEF 40.0f +#define GLOBAL_SCALEF_INV 0.025f +#define GRID_N 4 +#define GRID_SEP 10 +#define GRID_SEPF 10.0f inline QPointF toScreen(QPointF src) { src.setY(-src.y()); src *= GLOBAL_SCALEF; return src; } diff --git a/src/util.cpp b/src/util.cpp index 64716d2..5e56cd9 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -46,3 +46,9 @@ 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"; + else return QString::number(f); +} diff --git a/src/util.h b/src/util.h index 7622269..706928d 100644 --- a/src/util.h +++ b/src/util.h @@ -6,8 +6,13 @@ #define UTIL_H #include +#include #include +#ifndef M_PI +#define M_PI 3.14159265358979323846264338327950288 +#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); @@ -15,6 +20,7 @@ QPointF bezierInterpolateFull (float dist, QPointF c0, QPointF c1, QPointF c2, Q // rounding float roundToNearest(float stepSize, float val); float radiansToDegrees (float radians); +QString floatToString(float f); // angles float degreesToRadians(float degrees); -- cgit v1.2.3