Add loadsvg script command, fix ParanoidNumber size limiting*
authorSam Moore <[email protected]>
Thu, 25 Sep 2014 12:16:13 +0000 (20:16 +0800)
committerSam Moore <[email protected]>
Thu, 25 Sep 2014 12:16:13 +0000 (20:16 +0800)
Need to write some scripts and performance test them now I guess?
Maybe add commands for scripts to output information for plotting.

src/bezier.cpp
src/debugscript.cpp
src/debugscript.h
src/document.cpp
src/paranoidnumber.cpp
src/paranoidnumber.h
src/real.h
src/test.script
src/view.h

index 67b384c..cb92697 100644 (file)
@@ -54,11 +54,11 @@ static void CubicSolveSegment(vector<Real> & 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))
        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
                //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);
        while (tu - tl > delta)
        {
                Real t(tu+tl);
index a8bcd78..19b51d7 100644 (file)
@@ -84,6 +84,11 @@ void DebugScript::ParseAction()
        {
                currentAction.type = AT_Quit;
        }
        {
                currentAction.type = AT_Quit;
        }
+       else if (actionType == "loadsvg")
+       {
+               currentAction.type = AT_LoadSVG;
+               inp >> currentAction.filename;
+       }
 }
 
 bool DebugScript::Execute(View *view, Screen *scr)
 }
 
 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_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.");
        }
        default:
                Fatal("Unknown script command in queue.");
        }
index 9e4dce8..3697201 100644 (file)
@@ -30,6 +30,7 @@ private:
                AT_SetGPURendering,
                AT_EnableLazyRendering,
                AT_DisableLazyRendering,
                AT_SetGPURendering,
                AT_EnableLazyRendering,
                AT_DisableLazyRendering,
+               AT_LoadSVG,
                AT_Quit
        };
 
                AT_Quit
        };
 
@@ -41,6 +42,7 @@ private:
                Real z;
                int iz;
                int loops;
                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) {}
        };
 
                Action() : type(AT_WaitFrame), x(0), y(0), ix(0), iy(0), z(0), loops(0) {}
        };
 
index 71f4205..9b94ba2 100644 (file)
@@ -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());
                
        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
        
        input.close();
                                                // a c e, b d f
index efae860..6b602c0 100644 (file)
@@ -29,7 +29,7 @@ ParanoidNumber::~ParanoidNumber()
 ParanoidNumber::ParanoidNumber(const string & str) : m_value(0), m_next()
 {
        #ifdef PARANOID_SIZE_LIMIT
 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;
        #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
        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();
                {
                        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);
                        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
                //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
                #endif  
        }
        else
@@ -564,16 +564,16 @@ ParanoidNumber * ParanoidNumber::OperationFactor(ParanoidNumber * b, Optype op,
        m_cached_result = NAN;
        #endif
        #ifdef PARANOID_SIZE_LIMIT
        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();
                {
                        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;
                        
                }
                        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
                        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());
                #endif  
        }
        //assert(SanityCheck());
@@ -783,7 +783,7 @@ bool ParanoidNumber::Simplify(Optype op)
                        if (result != NULL)
                        {
                                #ifdef PARANOID_SIZE_LIMIT
                        if (result != NULL)
                        {
                                #ifdef PARANOID_SIZE_LIMIT
-                                       m_size -= (1+result->m_size);
+                                       m_size -= result->m_size;
                                #endif
                                *m = NULL;
                                delete(result);
                                #endif
                                *m = NULL;
                                delete(result);
@@ -800,7 +800,7 @@ bool ParanoidNumber::Simplify(Optype op)
                        #ifdef PARANOID_SIZE_LIMIT
                                if (Operation(n, op) == n)
                                {
                        #ifdef PARANOID_SIZE_LIMIT
                                if (Operation(n, op) == n)
                                {
-                                       m_size -= (1+n->m_size);
+                                       m_size -= n->m_size;
                                        delete n;
                                }
                        #else   
                                        delete n;
                                }
                        #else   
index 47dbdc9..041e445 100644 (file)
@@ -87,7 +87,7 @@ namespace IPDF
                        ParanoidNumber(PARANOID_DIGIT_T value=0) : m_value(value), m_next()
                        {
                                #ifdef PARANOID_SIZE_LIMIT
                        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;
                                #endif
                                #ifdef PARANOID_CACHE_RESULTS
                                        m_cached_result = value;
index adb9503..e35d952 100644 (file)
@@ -178,7 +178,15 @@ namespace IPDF
        inline Real RealFromStr(const std::string & str) {return RealFromStr(str.c_str());}
 
 
        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
+       }
 
 }
 
 
 }
 
index 302267a..42b6b40 100644 (file)
@@ -1,4 +1,5 @@
 # Test script for IPDF automation.
 # Test script for IPDF automation.
+# loadsvg svg-tests/rabbit_simple.svg
 gpu
 nolazy
 loop 50 pxzoom 400 300 1
 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
 cpu
 lazy
 loop 90 zoom 0.5 0.5 1.05
-quit
+loadsvg svg-tests/rabbit_simple.svg
+wait
index 6be1ebf..796ce45 100644 (file)
@@ -69,6 +69,8 @@ namespace IPDF
                        void SaveCPUBMP(const char * filename);
                        void SaveGPUBMP(const char * filename);
 
                        void SaveCPUBMP(const char * filename);
                        void SaveGPUBMP(const char * filename);
 
+                       Document & Doc() {return m_document;}
+
                private:
                        struct GPUObjBounds
                        {
                private:
                        struct GPUObjBounds
                        {

UCC git Repository :: git.ucc.asn.au