From: Sam Moore Date: Thu, 25 Sep 2014 12:16:13 +0000 (+0800) Subject: Add loadsvg script command, fix ParanoidNumber size limiting* X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=3917214a11bf76381ddc528e3fe51de9ec038d42;p=ipdf%2Fcode.git Add loadsvg script command, fix ParanoidNumber size limiting* Need to write some scripts and performance test them now I guess? Maybe add commands for scripts to output information for plotting. --- diff --git a/src/bezier.cpp b/src/bezier.cpp index 67b384c..cb92697 100644 --- a/src/bezier.cpp +++ b/src/bezier.cpp @@ -54,11 +54,11 @@ static void CubicSolveSegment(vector & roots, const Real & a, const Real & Real l = a*tl*tl*tl + b*tl*tl + c*tl + d; Real u = a*tu*tu*tu + b*tu*tu + c*tu + d; if ((l < 0 && u < 0) || (l > 0 && u > 0)) - Debug("Discarding segment (no roots) l = %f (%f), u = %f (%f)", tl, l, tu, u); + Debug("Discarding segment (no roots) l = %f (%f), u = %f (%f)", Double(tl), Double(l), Double(tu), Double(u)); //return; bool negative = (u < l); // lower point > 0, upper point < 0 - Debug("%ft^3 + %ft^2 + %ft + %f is negative (%f < %f) %d", a,b,c,d,u,l, negative); + Debug("%ft^3 + %ft^2 + %ft + %f is negative (%f < %f) %d", Double(a),Double(b),Double(c),Double(d),Double(u),Double(l), negative); while (tu - tl > delta) { Real t(tu+tl); diff --git a/src/debugscript.cpp b/src/debugscript.cpp index a8bcd78..19b51d7 100644 --- a/src/debugscript.cpp +++ b/src/debugscript.cpp @@ -84,6 +84,11 @@ void DebugScript::ParseAction() { currentAction.type = AT_Quit; } + else if (actionType == "loadsvg") + { + currentAction.type = AT_LoadSVG; + inp >> currentAction.filename; + } } bool DebugScript::Execute(View *view, Screen *scr) @@ -121,6 +126,19 @@ bool DebugScript::Execute(View *view, Screen *scr) case AT_DisableLazyRendering: view->SetLazyRendering(false); break; + case AT_LoadSVG: + #ifdef TRANSFORM_OBJECTS_NOT_VIEW + view->Doc().LoadSVG(currentAction.filename, Rect(Real(1)/Real(2),Real(1)/Real(2),Real(1)/Real(800),Real(1)/Real(600))); + #else + Rect & bounds = view->GetBounds(); + view->Doc().LoadSVG(currentAction.filename, Rect(bounds.x+bounds.w/Real(2),bounds.y+bounds.h/Real(2),bounds.w/Real(800),bounds.h/Real(600))); + #endif + currentAction.type = AT_WaitFrame; + view->ForceRenderDirty(); + view->ForceBufferDirty(); + view->ForceBoundsDirty(); + currentAction.loops = 0; + break; default: Fatal("Unknown script command in queue."); } diff --git a/src/debugscript.h b/src/debugscript.h index 9e4dce8..3697201 100644 --- a/src/debugscript.h +++ b/src/debugscript.h @@ -30,6 +30,7 @@ private: AT_SetGPURendering, AT_EnableLazyRendering, AT_DisableLazyRendering, + AT_LoadSVG, AT_Quit }; @@ -41,6 +42,7 @@ private: Real z; int iz; int loops; + std::string filename; Action() : type(AT_WaitFrame), x(0), y(0), ix(0), iy(0), z(0), loops(0) {} }; diff --git a/src/document.cpp b/src/document.cpp index 71f4205..9b94ba2 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -731,7 +731,7 @@ void Document::LoadSVG(const string & filename, const Rect & bounds) if (!result) Error("Couldn't load \"%s\" - %s", filename.c_str(), result.description()); - Debug("Loaded XML - %s", result.description()); + Debug("Loaded XML from \"%s\" - %s", filename.c_str(), result.description()); input.close(); // a c e, b d f diff --git a/src/paranoidnumber.cpp b/src/paranoidnumber.cpp index efae860..6b602c0 100644 --- a/src/paranoidnumber.cpp +++ b/src/paranoidnumber.cpp @@ -29,7 +29,7 @@ ParanoidNumber::~ParanoidNumber() ParanoidNumber::ParanoidNumber(const string & str) : m_value(0), m_next() { #ifdef PARANOID_SIZE_LIMIT - m_size = 0; + m_size = 1; #endif #ifdef PARANOID_CACHE_RESULTS m_cached_result = NAN; @@ -430,15 +430,15 @@ ParanoidNumber * ParanoidNumber::OperationTerm(ParanoidNumber * b, Optype op, Pa m_cached_result = NAN; #endif #ifdef PARANOID_SIZE_LIMIT - if (m_size >= PARANOID_SIZE_LIMIT) + if (m_size + b->m_size >= PARANOID_SIZE_LIMIT) { this->operator=(this->Digit()); if (op == ADD) m_value += b->Digit(); else m_value -= b->Digit(); - m_size = 0; - Debug("Cut off %p", this); + m_size = 1; + //Debug("Cut off %p", this); return b; } //Debug("At size limit %d", m_size); @@ -541,7 +541,7 @@ ParanoidNumber * ParanoidNumber::OperationTerm(ParanoidNumber * b, Optype op, Pa //merge->m_next[*merge_op].push_back(b); m_next[op].push_back(b); #ifdef PARANOID_SIZE_LIMIT - m_size += 1+b->m_size; + m_size += b->m_size; #endif } else @@ -564,16 +564,16 @@ ParanoidNumber * ParanoidNumber::OperationFactor(ParanoidNumber * b, Optype op, m_cached_result = NAN; #endif #ifdef PARANOID_SIZE_LIMIT - if (m_size >= PARANOID_SIZE_LIMIT) + if (m_size + b->m_size >= PARANOID_SIZE_LIMIT) { this->operator=(this->Digit()); if (op == MULTIPLY) m_value *= b->Digit(); else m_value /= b->Digit(); - m_size = 0; + m_size = 1; - Debug("Cut off %p", this); + //Debug("Cut off %p", this); return b; } @@ -690,7 +690,7 @@ ParanoidNumber * ParanoidNumber::OperationFactor(ParanoidNumber * b, Optype op, delete(sub->OperationFactor(new ParanoidNumber(*cpy_b), op)); #ifdef PARANOID_SIZE_LIMIT - m_size += 1+b->m_size; + m_size += b->m_size; #endif } //assert(SanityCheck()); @@ -783,7 +783,7 @@ bool ParanoidNumber::Simplify(Optype op) if (result != NULL) { #ifdef PARANOID_SIZE_LIMIT - m_size -= (1+result->m_size); + m_size -= result->m_size; #endif *m = NULL; delete(result); @@ -800,7 +800,7 @@ bool ParanoidNumber::Simplify(Optype op) #ifdef PARANOID_SIZE_LIMIT if (Operation(n, op) == n) { - m_size -= (1+n->m_size); + m_size -= n->m_size; delete n; } #else diff --git a/src/paranoidnumber.h b/src/paranoidnumber.h index 47dbdc9..041e445 100644 --- a/src/paranoidnumber.h +++ b/src/paranoidnumber.h @@ -87,7 +87,7 @@ namespace IPDF ParanoidNumber(PARANOID_DIGIT_T value=0) : m_value(value), m_next() { #ifdef PARANOID_SIZE_LIMIT - m_size = 0; + m_size = 1; #endif #ifdef PARANOID_CACHE_RESULTS m_cached_result = value; diff --git a/src/real.h b/src/real.h index adb9503..e35d952 100644 --- a/src/real.h +++ b/src/real.h @@ -178,7 +178,15 @@ namespace IPDF inline Real RealFromStr(const std::string & str) {return RealFromStr(str.c_str());} - inline void DebugRealInfo() {Debug("Compiled with REAL = %d => \"%s\" sizeof(Real) == %d bytes", REALTYPE, g_real_name[REALTYPE], sizeof(Real));} + inline void DebugRealInfo() + { + Debug("Compiled with REAL = %d => \"%s\" sizeof(Real) == %d bytes", REALTYPE, g_real_name[REALTYPE], sizeof(Real)); + #if REALTYPE == REAL_PARANOIDNUMBER + #ifdef PARANOID_SIZE_LIMIT + Debug("Size limit of %d is being enforced", PARANOID_SIZE_LIMIT); + #endif + #endif + } } diff --git a/src/test.script b/src/test.script index 302267a..42b6b40 100644 --- a/src/test.script +++ b/src/test.script @@ -1,4 +1,5 @@ # Test script for IPDF automation. +# loadsvg svg-tests/rabbit_simple.svg gpu nolazy loop 50 pxzoom 400 300 1 @@ -7,4 +8,5 @@ loop 100 wait cpu lazy loop 90 zoom 0.5 0.5 1.05 -quit +loadsvg svg-tests/rabbit_simple.svg +wait diff --git a/src/view.h b/src/view.h index 6be1ebf..796ce45 100644 --- a/src/view.h +++ b/src/view.h @@ -69,6 +69,8 @@ namespace IPDF void SaveCPUBMP(const char * filename); void SaveGPUBMP(const char * filename); + Document & Doc() {return m_document;} + private: struct GPUObjBounds {