00001 #include "text.h"
00002 #include "image.h"
00003 #include "runtime.h"
00004 #include "point.h"
00005
00013 Value * Runtime::add(Value * a, Value * b)
00014 {
00015 if (!a || !b) return NULL;
00016 if (typeid(*a)==typeid(TextValue) && typeid(*b)==typeid(TextValue))
00017 {
00018 TextValue * A = (TextValue*)a;
00019 TextValue * B = (TextValue*)b;
00020 return new TextValue(A->number()+B->number());
00021 }
00022 if (typeid(*a)==typeid(ImageValue) && typeid(*b)==typeid(ImageValue))
00023 {
00024 ImageValue * A = (ImageValue*)a;
00025 ImageValue * B = (ImageValue*)b;
00026
00027 PointValue topleft = min(A->topleft(),B->topleft());
00028 PointValue bottomright = max(A->bottomright(),B->bottomright());
00029 PointValue maxres = max(A->scale,B->scale);
00030 int cs = max(A->channelcount(),B->channelcount());
00031 ImageValue * O = new ImageValue(topleft,bottomright,maxres,cs);
00032 printf("O1: %g - %g\n",O->minz(),O->maxz());
00033 O->clear(0);
00034 printf("O2: %g - %g\n",O->minz(),O->maxz());
00035 printf("A: %g - %g\n",A->minz(),A->maxz());
00036 O->addFrom(A);
00037 printf("O3: %g - %g\n",O->minz(),O->maxz());
00038 printf("B: %g - %g\n",B->minz(),B->maxz());
00039 O->addFrom(B);
00040 printf("O4: %g - %g\n",O->minz(),O->maxz());
00041 return O;
00042 }
00043 if (typeid(*a)==typeid(PointValue) && typeid(*b)==typeid(PointValue))
00044 {
00045 PointValue * A = (PointValue*)a;
00046 PointValue * B = (PointValue*)b;
00047 PointValue * R = new PointValue();
00048 R->x=A->x+B->x;
00049 R->y=A->y+B->y;
00050 return R;
00051 }
00052 assert(0);
00053 }
00054
00055 Value * Runtime::add(vector<Value*> values)
00056 {
00057 Value * accumulated = values[0];
00058 for(unsigned int i = 1 ; i < values.size() ; i++)
00059 accumulated=add(accumulated,values[i]);
00060 return accumulated;
00061 }