From 27a67f7745cb156f6ece74823318835140e7c607 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Thu, 9 Nov 2017 23:34:13 +0100 Subject: [PATCH] [DEBUG] build back with new etk and no stl --- dollar/EnginePPlus.cpp | 12 +++--- dollar/EnginePPlus.hpp | 1 + dollar/Gesture.cpp | 4 +- dollar/Rectangle.cpp | 12 +++--- dollar/tools.cpp | 16 ++++---- dollar/tools.hpp | 8 ++-- test/main.cpp | 29 +++++++------- tool/bench-corpus/main.cpp | 2 +- tool/generate-form/main.cpp | 9 +++-- .../appl/widget/TextAreaRecognition.cpp | 38 +++++++++---------- .../appl/widget/TextAreaRecognition.hpp | 7 ++-- 11 files changed, 72 insertions(+), 66 deletions(-) diff --git a/dollar/EnginePPlus.cpp b/dollar/EnginePPlus.cpp index 9cc5bfd..f7fde17 100644 --- a/dollar/EnginePPlus.cpp +++ b/dollar/EnginePPlus.cpp @@ -268,7 +268,7 @@ static void storeSVG(const etk::String& _fileName, data += " "; } first = false; - data += etk::toString(itPoints.x()*100.0f) + "," + etk::to_string((1.0-itPoints.y())*100.0f); + data += etk::toString(itPoints.x()*100.0f) + "," + etk::toString((1.0-itPoints.y())*100.0f); } data += "\"\n"; data += " />\n"; @@ -282,25 +282,25 @@ static void storeSVG(const etk::String& _fileName, data += " "; } first = false; - data += etk::toString(itPoints.x()*100.0f) + "," + etk::to_string((1.0-itPoints.y())*100.0f); + data += etk::toString(itPoints.x()*100.0f) + "," + etk::toString((1.0-itPoints.y())*100.0f); } data += "\"\n"; data += " />\n"; } etk::Vector refListPoint = _gesture->getEnginePoints(); for (auto &it : refListPoint) { - data += " \n"; + data += " \n"; } etk::Vector testListPoint = _points; for (auto &it : testListPoint) { - data += " \n"; + data += " \n"; } for (auto &it : _links) { data += " #include #include +#include namespace dollar { class EnginePPlus : public dollar::Engine { diff --git a/dollar/Gesture.cpp b/dollar/Gesture.cpp index d6d038a..d165cfc 100644 --- a/dollar/Gesture.cpp +++ b/dollar/Gesture.cpp @@ -164,7 +164,7 @@ void dollar::Gesture::storeSVG(const etk::String& _fileName, bool _storeDot) { data += " "; } first = false; - data += etk::toString(itPoints.x()*100.0f) + "," + etk::to_string((1.0-itPoints.y())*100.0f); + data += etk::toString(itPoints.x()*100.0f) + "," + etk::toString((1.0-itPoints.y())*100.0f); } data += "\"\n"; data += " />\n"; @@ -172,7 +172,7 @@ void dollar::Gesture::storeSVG(const etk::String& _fileName, bool _storeDot) { if (_storeDot == true) { /* for (auto &it : m_enginePoints) { - data += " \n"; + data += " \n"; } */ } diff --git a/dollar/Rectangle.cpp b/dollar/Rectangle.cpp index b2d00e1..0211fe2 100644 --- a/dollar/Rectangle.cpp +++ b/dollar/Rectangle.cpp @@ -6,7 +6,9 @@ #include #include -#define MAX_FLOAT std::numeric_limits::max() +#include + +//#define MAX_FLOAT std::numeric_limits::max() dollar::Rectangle::Rectangle(const vec2& _pos, const vec2& _size): m_pos(_pos), @@ -14,8 +16,8 @@ dollar::Rectangle::Rectangle(const vec2& _pos, const vec2& _size): } dollar::Rectangle::Rectangle(const etk::Vector& _points) { - vec2 minPos(MAX_FLOAT,MAX_FLOAT); - vec2 maxPos(-MAX_FLOAT,-MAX_FLOAT); + vec2 minPos(FLT_MAX, FLT_MAX); + vec2 maxPos(FLT_MIN, FLT_MIN); for (auto &it : _points) { minPos.setMin(it); maxPos.setMax(it); @@ -24,8 +26,8 @@ dollar::Rectangle::Rectangle(const etk::Vector& _points) { m_size = maxPos-minPos; } dollar::Rectangle::Rectangle(const etk::Vector>& _points) { - vec2 minPos(MAX_FLOAT,MAX_FLOAT); - vec2 maxPos(-MAX_FLOAT,-MAX_FLOAT); + vec2 minPos(FLT_MAX, FLT_MAX); + vec2 maxPos(FLT_MIN, FLT_MIN); for (auto &it : _points) { for (auto &itPoint : it) { minPos.setMin(itPoint); diff --git a/dollar/tools.cpp b/dollar/tools.cpp index 6af8edb..3c66a9d 100644 --- a/dollar/tools.cpp +++ b/dollar/tools.cpp @@ -80,7 +80,7 @@ etk::Vector dollar::scaleToOne(const etk::Vector& _points, bool _kee return out; } -etk::Vector> dollar::scaleToOne(const std::vector>& _points, bool _keepAspectRation) { +etk::Vector> dollar::scaleToOne(const etk::Vector>& _points, bool _keepAspectRation) { dollar::Rectangle box(_points); etk::Vector> out; vec2 scale(1.0f/box.getSize().x(), 1.0f/box.getSize().y()); @@ -162,7 +162,7 @@ etk::Vector dollar::resample(etk::Vector _points, int32_t _nbPoints) return out; } -etk::Vector> dollar::makeReferenceStrokes(const std::vector>& _strokes) { +etk::Vector> dollar::makeReferenceStrokes(const etk::Vector>& _strokes) { etk::Vector> out; // create the ordr of all possibilities of writing the strokes ... (ABC, ACB, BAC, BCA ...) etk::Vector order; @@ -172,7 +172,7 @@ etk::Vector> dollar::makeReferenceStrokes(const std::vector stroke; @@ -180,7 +180,9 @@ etk::Vector> dollar::makeReferenceStrokes(const std::vector pts = _strokes[order[iii]]; // check to permut the value order if (((permut>>iii) & 0x01) == 1) { - reverse(pts.begin(),pts.end()); + for (size_t kkk=0; kkk < pts.size()/2; ++kkk) { + etk::swap(pts[kkk], pts[pts.size()-1-kkk]); + } } // Add point in next of the path... for (auto &it : pts) { @@ -190,11 +192,11 @@ etk::Vector> dollar::makeReferenceStrokes(const std::vector dollar::combineStrokes(const etk::Vector>& _strokes) { +etk::Vector dollar::combineStrokes(const etk::Vector>& _strokes) { etk::Vector out; for (auto &it : _strokes) { for (auto &pointIt : it) { @@ -250,7 +252,7 @@ float dollar::getAspectRatio(etk::Vector> _points) { } } -etk::Vector dollar::normalizePathToPoints(etk::Vector> _points, float _distance, bool _keepAspectRatio) { +etk::Vector dollar::normalizePathToPoints(etk::Vector> _points, float _distance, bool _keepAspectRatio) { // Scale point to (0.0,0.0) position and (1.0,1.0) size _points = dollar::scaleToOne(_points, _keepAspectRatio); etk::Vector out; diff --git a/dollar/tools.hpp b/dollar/tools.hpp index c33df75..bda4027 100644 --- a/dollar/tools.hpp +++ b/dollar/tools.hpp @@ -54,7 +54,7 @@ namespace dollar { * @param[in] _keepAspectRation Keep the aspect ratio of the scaling * @return modify points */ - etk::Vector> scaleToOne(const std::vector>& _points, bool _keepAspectRation=false); + etk::Vector> scaleToOne(const etk::Vector>& _points, bool _keepAspectRation=false); /** * @brief Get center of the path and move the path to be center at (0,0) * @param[in] _points List of point in the path @@ -73,13 +73,13 @@ namespace dollar { * @param[in] _strokes List of all strokes * @return List of a list of single stroke of multiple stroke */ - etk::Vector> makeReferenceStrokes(const std::vector>& _strokes); + etk::Vector> makeReferenceStrokes(const etk::Vector>& _strokes); /** * @brief combine some stroke in a single one. * @param[in] _strokes value to merge * @return Merged vector */ - etk::Vector combineStrokes(const etk::Vector>& _strokes); + etk::Vector combineStrokes(const etk::Vector>& _strokes); /** * @brief Normalise the Path with the full magnetude of the data * @param[in] _points Input path @@ -111,7 +111,7 @@ namespace dollar { * @param[in] _keepAspectRatio Keep Aspect ratio when scaling to the correct size (1.0,1.0) (it will be centered) * @return new list of points */ - etk::Vector normalizePathToPoints(etk::Vector> _points, float _distance, bool _keepAspectRatio); + etk::Vector normalizePathToPoints(etk::Vector> _points, float _distance, bool _keepAspectRatio); /** * @brief get the aspect ratio of a list of points * @param[in] _points List of points diff --git a/test/main.cpp b/test/main.cpp index 7c4e035..54efa25 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -12,10 +12,7 @@ #include int main(int _argc, const char *_argv[]) { - // init Google test : - ::testing::InitGoogleTest(&_argc, const_cast(_argv)); - // init etk log system and file interface: - etk::init(_argc, _argv); + etest::init(_argc, _argv); // Run all test with etest return RUN_ALL_TESTS(); } @@ -35,8 +32,8 @@ TEST(TestAll, singleStroke_normal) { ememory::SharedPtr reco = dollar::createEngine("$N"); reco->loadPath("DATA:figure"); dollar::Results res = reco->recognize(dollar::loadPoints("DATA:test/arrow.json")); - EXPECT_EQ(res.haveMath(), true); - if (res.haveMath() == false) { + EXPECT_EQ(res.haveMatch(), true); + if (res.haveMatch() == false) { TEST_INFO(" Recognise noting ..."); return; } @@ -51,8 +48,8 @@ TEST(TestAll, singleStroke_protractor) { ememory::SharedPtr reco = dollar::createEngine("$N"); reco->loadPath("DATA:figure"); dollar::Results res = reco->recognize(dollar::loadPoints("DATA:test/arrow.json")); - EXPECT_EQ(res.haveMath(), true); - if (res.haveMath() == false) { + EXPECT_EQ(res.haveMatch(), true); + if (res.haveMatch() == false) { TEST_INFO(" Recognise noting ..."); return; } @@ -71,8 +68,8 @@ TEST(TestAll, multiStroke_normal) { ememory::SharedPtr reco = dollar::createEngine("$N"); reco->loadPath("DATA:text"); dollar::Results res = reco->recognize(dollar::loadPoints("DATA:test/P.json")); - EXPECT_EQ(res.haveMath(), true); - if (res.haveMath() == false) { + EXPECT_EQ(res.haveMatch(), true); + if (res.haveMatch() == false) { TEST_INFO(" Recognise noting ..."); return; } @@ -87,8 +84,8 @@ TEST(TestAll, multiStroke_protractor) { ememory::SharedPtr reco = dollar::createEngine("$N-protractor"); reco->loadPath("DATA:text"); dollar::Results res = reco->recognize(dollar::loadPoints("DATA:test/P.json")); - EXPECT_EQ(res.haveMath(), true); - if (res.haveMath() == false) { + EXPECT_EQ(res.haveMatch(), true); + if (res.haveMatch() == false) { TEST_INFO(" Recognise noting ..."); return; } @@ -105,8 +102,8 @@ TEST(TestAll, multiStroke_point) { ememory::SharedPtr reco = dollar::createEngine("$P"); reco->loadPath("DATA:text"); dollar::Results res = reco->recognize(dollar::loadPoints("DATA:test/P.json")); - EXPECT_EQ(res.haveMath(), true); - if (res.haveMath() == false) { + EXPECT_EQ(res.haveMatch(), true); + if (res.haveMatch() == false) { TEST_INFO(" Recognise noting ..."); return; } @@ -123,8 +120,8 @@ TEST(TestAll, multiStroke_pointPlus) { ememory::SharedPtr reco = dollar::createEngine("$P+"); reco->loadPath("DATA:text"); dollar::Results res = reco->recognize(dollar::loadPoints("DATA:test/P.json")); - EXPECT_EQ(res.haveMath(), true); - if (res.haveMath() == false) { + EXPECT_EQ(res.haveMatch(), true); + if (res.haveMatch() == false) { TEST_INFO(" Recognise noting ..."); return; } diff --git a/tool/bench-corpus/main.cpp b/tool/bench-corpus/main.cpp index 05ef34d..d5d32b2 100644 --- a/tool/bench-corpus/main.cpp +++ b/tool/bench-corpus/main.cpp @@ -124,7 +124,7 @@ void generateFile(const etk::String& _fileName, const etk::Vector& data += " "; } first = false; - data += etk::toString(itPoints.x()*100.0f) + "," + etk::to_string((1.0-itPoints.y())*100.0f); + data += etk::toString(itPoints.x()*100.0f) + "," + etk::toString((1.0-itPoints.y())*100.0f); } data += "\"\n"; data += " />\n"; diff --git a/tool/generate-form/main.cpp b/tool/generate-form/main.cpp index 00c9533..b6752f8 100644 --- a/tool/generate-form/main.cpp +++ b/tool/generate-form/main.cpp @@ -137,7 +137,7 @@ void generateFile(const etk::String& _fileName, const etk::Vector& data += " "; } first = false; - data += etk::toString(itPoints.x()*100.0f) + "," + etk::to_string((1.0-itPoints.y())*100.0f); + data += etk::toString(itPoints.x()*100.0f) + "," + etk::toString((1.0-itPoints.y())*100.0f); } data += "\"\n"; data += " />\n"; @@ -157,7 +157,7 @@ void generateFile(const etk::String& _fileName, const etk::Vector& data += " "; } first = false; - data += etk::toString(itPoints.x()*100.0f) + "," + etk::to_string((1.0-itPoints.y())*100.0f); + data += etk::toString(itPoints.x()*100.0f) + "," + etk::toString((1.0-itPoints.y())*100.0f); } data += "\"\n"; data += " />\n"; @@ -187,7 +187,10 @@ bool testCorpus(const etk::String& _srcCorpus) { }if (elemName == "back-slash") { elemName = "\\"; } - if (std::find(listOfElementInCorpus.begin(), listOfElementInCorpus.end(), elemName) == listOfElementInCorpus.end()) { + for (auto &it: listOfElementInCorpus) { + if (it == elemName) { + continue; + } listOfElementInCorpus.pushBack(elemName); } } diff --git a/tool/recorder/appl/widget/TextAreaRecognition.cpp b/tool/recorder/appl/widget/TextAreaRecognition.cpp index 045638c..ed9194c 100644 --- a/tool/recorder/appl/widget/TextAreaRecognition.cpp +++ b/tool/recorder/appl/widget/TextAreaRecognition.cpp @@ -23,7 +23,7 @@ void appl::widget::TextAreaRecognition::init() { //m_dollarEngine.loadPath("DATA:text"); m_dollarEngine = dollar::createEngine("$P+"); m_dollarEngine->loadPath("DATA:reference"); - m_dollarEngine->setScaleKeepRatio(true); + // TODO: m_dollarEngine->setScaleKeepRatio(true); markToRedraw(); // connect a periodic update ... m_periodicConnection = getObjectManager().periodicCall.connect(this, &appl::widget::TextAreaRecognition::callbackPeriodicUpdate); @@ -38,7 +38,7 @@ appl::widget::TextAreaRecognition::~TextAreaRecognition() { void appl::widget::TextAreaRecognition::clear() { m_dataList.clear(); m_current.clear(); - m_time = std::chrono::system_clock::now(); + m_time = echrono::Clock::now(); markToRedraw(); } @@ -47,7 +47,7 @@ void appl::widget::TextAreaRecognition::undo() { return; } m_dataList.erase(m_dataList.begin()+(m_dataList.size()-1)); - m_time = std::chrono::system_clock::now(); + m_time = echrono::Clock::now(); markToRedraw(); } @@ -64,7 +64,7 @@ void appl::widget::TextAreaRecognition::store(const etk::String& _userName, cons doc.add("user", ejson::String(_userName)); doc.add("value", ejson::String(_value)); doc.add("type", ejson::String(_type)); - doc.add("time", ejson::Number(m_time.time_since_epoch().count())); + doc.add("time", ejson::Number(m_time.get())); ejson::Array list; doc.add("data", list); for (auto &it : m_dataList) { @@ -95,7 +95,7 @@ void appl::widget::TextAreaRecognition::store(const etk::String& _userName, cons fileName += "_"; fileName += _userName; fileName += "_"; - fileName += etk::toString(m_time.time_since_epoch().count()); + fileName += etk::toString(m_time.get()); fileName += ".json"; etk::FSNodeWriteAllData(fileName, streamOut); APPL_WARNING("store: " << fileName); @@ -106,10 +106,10 @@ void appl::widget::TextAreaRecognition::onDraw() { m_text.draw(); } -etk::Vector> scalePoints(std::vector> _list, float _objectSize) { +etk::Vector> scalePoints(etk::Vector> _list, float _objectSize) { // get min/max point - vec2 minPos(99999999,99999999); - vec2 maxPos(0,0); + vec2 minPos(FLT_MAX, FLT_MAX); + vec2 maxPos(FLT_MIN, FLT_MIN); for (auto &itLines : _list) { for (auto& itPoints : itLines) { minPos.setMin(itPoints); @@ -119,7 +119,7 @@ etk::Vector> scalePoints(std::vector> _list, // center and reduce to a size of XXX float scale = 1.0f; vec2 size = maxPos-minPos; - vec2 center(0,0); + vec2 center(0, 0); if (size.x() > size.y()) { scale = _objectSize/size.x(); center.setY((_objectSize-size.y()*scale)*0.5); @@ -137,11 +137,11 @@ etk::Vector> scalePoints(std::vector> _list, return _list; } -etk::Vector> renderWithSVG(const etk::Vector>& _list, int32_t _objectSize, const etk::String& _filename) { +etk::Vector> renderWithSVG(const etk::Vector>& _list, int32_t _objectSize, const etk::String& _filename) { // generate SVG to render: esvg::Document docSvg; etk::String data("\n"); - data += "\n"; + data += "\n"; for (auto &itLines : _list) { data += " > renderWithSVG(const etk::Vector> convertInLines(const std::vector& _list) { +static etk::Vector> convertInLines(const etk::Vector& _list) { etk::Vector> out; for (auto &it : _list) { if (it.m_data.size() > 1) { @@ -343,7 +343,7 @@ static etk::Vector> convertInLines(const std::vector std::chrono::milliseconds(1200) + if ( (echrono::Clock::now() - m_lastEvent) > echrono::milliseconds(1200) && m_updateDone == false) { if (m_current.m_data.size() != 0) { // ==> writing in progress @@ -362,11 +362,11 @@ void appl::widget::TextAreaRecognition::callbackPeriodicUpdate(const ewol::event return; } - std::chrono::system_clock::time_point tic = std::chrono::system_clock::now(); + echrono::Clock tic = echrono::Clock::now(); // First Test with dollar engine m_dollarResults = m_dollarEngine->recognize(fullListlines); m_findValue = m_dollarResults.getName(); - m_dollarTime = std::chrono::duration_cast(std::chrono::system_clock::now() - tic); + m_dollarTime = echrono::Clock::now() - tic; markToRedraw(); m_updateDone = true; } diff --git a/tool/recorder/appl/widget/TextAreaRecognition.hpp b/tool/recorder/appl/widget/TextAreaRecognition.hpp index 6edf629..79c6fd5 100644 --- a/tool/recorder/appl/widget/TextAreaRecognition.hpp +++ b/tool/recorder/appl/widget/TextAreaRecognition.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include @@ -41,8 +42,8 @@ namespace appl { ewol::compositing::Text m_text; //!< drawing instance etk::Vector m_dataList; DrawingLine m_current; - std::chrono::system_clock::time_point m_time; - std::chrono::system_clock::time_point m_lastEvent; + echrono::Clock m_time; + echrono::Clock m_lastEvent; esignal::Connection m_periodicConnection; bool m_updateDone; etk::String m_svgData; @@ -51,7 +52,7 @@ namespace appl { ememory::SharedPtr m_dollarEngine; dollar::Results m_dollarResults; etk::String m_findValue; - std::chrono::milliseconds m_dollarTime; + echrono::Duration m_dollarTime; protected: //! @brief constructor TextAreaRecognition();