1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191
|
/*****
* runtime.in
* Tom Prince 2005/4/15
*
* Generate the runtime functions used by the vm::stack machine.
*
*****/
/* Autogenerated routines are specified like this (separated by a formfeed):
type asyname:cname(cparams)
{
C code
}
*/
// Use Void f() instead of void f() to force an explicit Stack argument.
pen => primPen()
pair => primPair()
triple => primTriple()
path => primPath()
path3 => primPath3()
guide* => primGuide()
cycleToken => primCycleToken()
tensionSpecifier => primTensionSpecifier()
curlSpecifier => primCurlSpecifier()
file* => primFile()
picture* => primPicture()
transform => primTransform()
callable* => voidFunction()
callableBp* => breakpointFunction()
callableReal* => realRealFunction()
callableTransform* => transformFunction()
runnable* => primCode()
boolarray* => booleanArray()
Intarray* => IntArray()
Intarray2* => IntArray2()
realarray* => realArray()
realarray2* => realArray2()
pairarray* => pairArray()
pairarray2* => pairArray2()
triplearray* => tripleArray()
triplearray2* => tripleArray2()
patharray* => pathArray()
patharray2* => pathArray2()
guidearray* => guideArray()
transformarray* => transformArray()
penarray* => penArray()
penarray2* => penArray2()
stringarray* => stringArray()
stringarray2* => stringArray2()
#include <cfloat>
#include <iostream>
#include <fstream>
#include <time.h>
#include <sys/times.h>
#include <locale.h>
#include "angle.h"
#include "pair.h"
#include "triple.h"
#include "transform.h"
#include "path.h"
#include "path3.h"
#include "pen.h"
#include "drawpath.h"
#include "guide.h"
#include "picture.h"
#include "fileio.h"
#include "genv.h"
#include "builtin.h"
#include "texfile.h"
#include "pipestream.h"
#include "parser.h"
#include "stack.h"
#include "util.h"
#include "locate.h"
#include "mathop.h"
#include "callable.h"
#include "stm.h"
#include "lexical.h"
#include "process.h"
#include "arrayop.h"
#ifdef __APPLE__
extern "C" int isnan(double);
#endif
#if defined(USEGC) && defined(GC_DEBUG) && defined(GC_BACKTRACE)
extern "C" {
void *GC_generate_random_valid_address(void);
void GC_debug_print_heap_obj_proc(void *);
}
#endif
using namespace vm;
using namespace camp;
using namespace settings;
namespace run {
using camp::pair;
using vm::array;
using vm::frame;
using vm::stack;
using camp::transform;
using absyntax::runnable;
typedef array boolarray;
typedef array Intarray;
typedef array Intarray2;
typedef array realarray;
typedef array realarray2;
typedef array pairarray;
typedef array pairarray2;
typedef array triplearray;
typedef array triplearray2;
typedef array patharray;
typedef array patharray2;
typedef array guidearray;
typedef array transformarray;
typedef array penarray;
typedef array penarray2;
typedef array stringarray;
typedef array stringarray2;
typedef callable callableBp;
typedef callable callableReal;
typedef callable callableTransform;
}
using vm::array;
using types::function;
#define PRIMITIVE(name,Name,asyName) using types::prim##Name;
#include <primitives.h>
#undef PRIMITIVE
using types::booleanArray;
using types::IntArray;
using types::IntArray2;
using types::realArray;
using types::realArray2;
using types::pairArray;
using types::pairArray2;
using types::tripleArray;
using types::tripleArray2;
using types::pathArray;
using types::pathArray2;
using types::guideArray;
using types::transformArray;
using types::penArray;
using types::penArray2;
using types::stringArray;
using types::stringArray2;
using types::formal;
function *realRealFunction()
{
return new function(primReal(),primReal());
}
function *realTripleFunction()
{
return new function(primReal(),primTriple());
}
const size_t camp::ColorComponents[]={0,0,1,3,4,0};
namespace vm {
#if COMPACT
const Int DefaultValue=0x7fffffffffffffffLL;
const Int Undefined=0x7ffffffffffffffeLL;
const Int BoolTruthValue=0xABABABABABABABACLL;
const Int BoolFalseValue=0xABABABABABABABABLL;
const item Default=DefaultValue;
#else
const item Default=item(default_t());
#endif
}
namespace run {
const char *arrayempty="cannot take min or max of empty array";
const char *noruntime="no runtime environment for embedded eval";
void writestring(stack *s)
{
callable *suffix=pop<callable *>(s,NULL);
string S=pop<string>(s);
vm::item it=pop(s);
bool defaultfile=isdefault(it);
camp::file *f=defaultfile ? &camp::Stdout : vm::get<camp::file*>(it);
if(!f->isOpen()) return;
if(S != "") f->write(S);
if(f->text()) {
if(suffix) {
s->push(f);
suffix->call(s);
} else if(defaultfile) f->writeline();
}
}
string emptystring;
pair zero;
}
static string defaulttransparency=string("Compatible");
void unused(void *)
{
}
// Autogenerated routines:
// Initializers
Int :IntZero()
{
return 0;
}
real :realZero()
{
return 0.0;
}
bool :boolFalse()
{
return false;
}
bool isnan(real x)
{
return isnan(x);
}
array* :pushNullArray()
{
return 0;
}
frame* :pushNullRecord()
{
return 0;
}
item :pushNullFunction()
{
return nullfunc::instance();
}
// Default operations
// Put the default value token on the stack (in place of an argument when
// making a function call).
item :pushDefault()
{
return Default;
}
// Test if the value on the stack is the default value token.
bool :isDefault(item i)
{
return isdefault(i);
}
// Casts
guide* :pairToGuide(pair z)
{
return new pairguide(z);
}
guide* :pathToGuide(path p)
{
return new pathguide(p);
}
path :guideToPath(guide *g)
{
return g->solve();
}
// Pen operations
pen :newPen()
{
return pen();
}
bool ==(pen a, pen b)
{
return a == b;
}
bool !=(pen a, pen b)
{
return a != b;
}
pen +(pen a, pen b)
{
return a+b;
}
pen Operator *(real a, pen b)
{
return a*b;
}
pen Operator *(pen a, real b)
{
return b*a;
}
pair max(pen p)
{
return p.bounds().Max();
}
pair min(pen p)
{
return p.bounds().Min();
}
// Reset the meaning of pen default attributes.
void resetdefaultpen()
{
processData().defaultpen=camp::pen::initialpen();
}
void defaultpen(pen p)
{
processData().defaultpen=pen(resolvepen,p);
}
pen defaultpen()
{
return processData().defaultpen;
}
bool invisible(pen p)
{
return p.invisible();
}
pen invisible()
{
return pen(invisiblepen);
}
pen gray(pen p)
{
p.togrey();
return p;
}
pen rgb(pen p)
{
p.torgb();
return p;
}
pen cmyk(pen p)
{
p.tocmyk();
return p;
}
pen interp(pen a, pen b, real t)
{
return interpolate(a,b,t);
}
pen rgb(real r, real g, real b)
{
return pen(r,g,b);
}
pen cmyk(real c, real m, real y, real k)
{
return pen(c,m,y,k);
}
pen gray(real gray)
{
return pen(gray);
}
realarray *colors(pen p)
{
size_t n=ColorComponents[p.colorspace()];
array *a=new array(n);
switch(n) {
case 0:
break;
case 1:
(*a)[0]=p.gray();
break;
case 3:
(*a)[0]=p.red();
(*a)[1]=p.green();
(*a)[2]=p.blue();
break;
case 4:
(*a)[0]=p.cyan();
(*a)[1]=p.magenta();
(*a)[2]=p.yellow();
(*a)[3]=p.black();
break;
default:
break;
}
return a;
}
string hex(pen p)
{
return p.hex();
}
Int byte(real x)
{
return byte(x);
}
string colorspace(pen p)
{
string s=ColorDeviceSuffix[p.colorspace()];
std::transform(s.begin(),s.end(),s.begin(),tolower);
return s;
}
pen pattern(string *s)
{
return pen(setpattern,*s);
}
string pattern(pen p)
{
return p.fillpattern();
}
pen fillrule(Int n)
{
return pen(n >= 0 && n < nFill ? (FillRule) n : DEFFILL);
}
Int fillrule(pen p)
{
return p.Fillrule();
}
pen opacity(real opacity=1.0, string blend=defaulttransparency)
{
for(Int i=0; i < nBlendMode; ++i)
if(blend == BlendMode[i]) return pen(Transparency(blend,opacity));
ostringstream buf;
buf << "Unknown blend mode: " << "'" << blend << "'";
error(buf);
}
real opacity(pen p)
{
return p.opacity();
}
string blend(pen p)
{
return p.blend();
}
pen linetype(realarray *pattern, real offset=0, bool scale=true,
bool adjust=true)
{
size_t size=checkArray(pattern);
array *a=new array(size);
for(size_t i=0; i < size; ++i)
(*a)[i]=::max(vm::read<double>(pattern,i),0.0);
return pen(LineType(*a,offset,scale,adjust));
}
realarray *linetype(pen p=CURRENTPEN)
{
array a=p.linetype()->pattern;
return copyArray(&a);
}
real offset(pen p)
{
return p.linetype()->offset;
}
bool scale(pen p)
{
return p.linetype()->scale;
}
bool adjust(pen p)
{
return p.linetype()->adjust;
}
pen adjust(pen p, real arclength, bool cyclic)
{
return adjustdash(p,arclength,cyclic);
}
pen linecap(Int n)
{
return pen(setlinecap,n >= 0 && n < nCap ? n : DEFCAP);
}
Int linecap(pen p=CURRENTPEN)
{
return p.cap();
}
pen linejoin(Int n)
{
return pen(setlinejoin,n >= 0 && n < nJoin ? n : DEFJOIN);
}
Int linejoin(pen p=CURRENTPEN)
{
return p.join();
}
pen miterlimit(real x)
{
return pen(setmiterlimit,x >= 1.0 ? x : DEFJOIN);
}
real miterlimit(pen p=CURRENTPEN)
{
return p.miter();
}
pen linewidth(real x)
{
return pen(setlinewidth,x >= 0.0 ? x : DEFWIDTH);
}
real linewidth(pen p=CURRENTPEN)
{
return p.width();
}
pen fontcommand(string *s)
{
return pen(setfont,*s);
}
string font(pen p=CURRENTPEN)
{
return p.Font();
}
pen fontsize(real size, real lineskip)
{
return pen(setfontsize,size > 0.0 ? size : 0.0,
lineskip > 0.0 ? lineskip : 0.0);
}
real fontsize(pen p=CURRENTPEN)
{
return p.size();
}
real lineskip(pen p=CURRENTPEN)
{
return p.Lineskip();
}
pen overwrite(Int n)
{
return pen(setoverwrite,n >= 0 && n < nOverwrite ? (overwrite_t) n :
DEFWRITE);
}
Int overwrite(pen p=CURRENTPEN)
{
return p.Overwrite();
}
pen basealign(Int n)
{
return pen(n >= 0 && n < nBaseLine ? (BaseLine) n : DEFBASE);
}
Int basealign(pen p=CURRENTPEN)
{
return p.Baseline();
}
transform transform(pen p)
{
return p.getTransform();
}
path nib(pen p)
{
return p.Path();
}
pen makepen(path p)
{
return pen(p);
}
pen colorless(pen p)
{
p.colorless();
return p;
}
// Interactive mode
bool interactive()
{
return interact::interactive;
}
bool uptodate()
{
return interact::uptodate;
}
// System commands
Int system(stringarray *s)
{
if(safe) error("system() call disabled; override with option -nosafe");
size_t size=checkArray(s);
if(size == 0) return 0;
mem::vector<string> cmd;
for(size_t i=0; i < size; ++i)
cmd.push_back(read<string>(s,i));
return System(cmd);
}
bool view()
{
return view();
}
string asydir()
{
return systemDir;
}
string locale(string s=emptystring)
{
char *L=setlocale(LC_ALL,s.empty() ? NULL : s.c_str());
return L != NULL ? string(L) : "";
}
void abort(string s=emptystring)
{
if(s.empty()) throw handled_error();
error(s.c_str());
}
void exit()
{
throw quit();
}
void assert(bool b, string s=emptystring)
{
flush(cout);
if(!b) {
ostringstream buf;
buf << "assert FAILED";
if(s != "") buf << ": " << s;
error(buf);
}
}
void sleep(Int seconds)
{
if(seconds <= 0) return;
sleep(seconds);
}
void usleep(Int microseconds)
{
if(microseconds <= 0) return;
usleep((unsigned long) microseconds);
}
void _eval(string *s, bool embedded, bool interactiveWrite=false)
{
if(embedded) {
trans::coenv *e=Stack->getEnvironment();
vm::interactiveStack *is=dynamic_cast<vm::interactiveStack *>(Stack);
if(e && is)
runStringEmbedded(*s, *e, *is);
else
error(noruntime);
} else
runString(*s,interactiveWrite);
}
void _eval(runnable *s, bool embedded)
{
absyntax::block *ast=new absyntax::block(s->getPos(), false);
ast->add(s);
if(embedded) {
trans::coenv *e=Stack->getEnvironment();
vm::interactiveStack *is=dynamic_cast<vm::interactiveStack *>(Stack);
if(e && is)
runCodeEmbedded(ast, *e, *is);
else
error(noruntime);
} else
runCode(ast);
}
string location() {
ostringstream buf;
buf << getPos();
return buf.str();
}
// Wrapper for the stack::load() method.
void :loadModule(string *index)
{
Stack->load(*index);
}
string cd(string s=emptystring)
{
if(!s.empty() && !globalwrite()) {
string outname=getSetting<string>("outname");
string dir=stripDir(outname);
if(dir.empty()) Setting("outname")=getPath()+dirsep+outname;
}
return setPath(s.c_str());
}
void list(string *s, bool imports=false)
{
if(*s == "-") return;
trans::genv ge;
symbol name=symbol::trans(*s);
record *r=ge.getModule(name,*s);
r->e.list(imports ? 0 : r);
}
// Guide operations
guide* :nullGuide()
{
return new pathguide(path());
}
guide* :dotsGuide(guidearray *a)
{
guidevector v;
size_t size=checkArray(a);
for (size_t i=0; i < size; ++i)
v.push_back(a->read<guide*>(i));
return new multiguide(v);
}
guide* :dashesGuide(guidearray *a)
{
static camp::curlSpec curly;
static specguide curlout(&curly, camp::OUT);
static specguide curlin(&curly, camp::IN);
size_t n=checkArray(a);
// a--b is equivalent to a{curl 1}..{curl 1}b
guidevector v;
if (n > 0)
v.push_back(a->read<guide*>(0));
if (n==1) {
v.push_back(&curlout);
v.push_back(&curlin);
}
else
for (size_t i=1; i<n; ++i) {
v.push_back(&curlout);
v.push_back(&curlin);
v.push_back(a->read<guide*>(i));
}
return new multiguide(v);
}
cycleToken :newCycleToken()
{
return cycleToken();
}
guide *operator cast(cycleToken tok)
{
// Avoid unused variable warning messages.
unused(&tok);
return new cycletokguide();
}
guide* operator spec(pair z, Int p)
{
camp::side d=(camp::side) p;
camp::dirSpec *sp=new camp::dirSpec(z);
return new specguide(sp,d);
}
curlSpecifier operator curl(real gamma, Int p)
{
camp::side s=(camp::side) p;
return curlSpecifier(gamma,s);
}
real :curlSpecifierValuePart(curlSpecifier spec)
{
return spec.getValue();
}
Int :curlSpecifierSidePart(curlSpecifier spec)
{
return spec.getSide();
}
guide *operator cast(curlSpecifier spec)
{
return new specguide(spec);
}
tensionSpecifier operator tension(real tout, real tin, bool atleast)
{
return tensionSpecifier(tout, tin, atleast);
}
real :tensionSpecifierOutPart(tensionSpecifier t)
{
return t.getOut();
}
real :tensionSpecifierInPart(tensionSpecifier t)
{
return t.getIn();
}
bool :tensionSpecifierAtleastPart(tensionSpecifier t)
{
return t.getAtleast();
}
guide *operator cast(tensionSpecifier t)
{
return new tensionguide(t);
}
guide* operator controls(pair zout, pair zin)
{
return new controlguide(zout, zin);
}
Int size(guide *g)
{
flatguide f;
g->flatten(f,false);
return f.size();
}
Int length(guide *g)
{
flatguide f;
g->flatten(f,false);
return g->cyclic() ? f.size() : f.size()-1;
}
bool cyclic(guide *g)
{
flatguide f;
g->flatten(f,false);
return g->cyclic();
}
pair point(guide *g, Int t)
{
flatguide f;
g->flatten(f,false);
return f.Nodes(adjustedIndex(t,f.size(),g->cyclic())).z;
}
pairarray *dirSpecifier(guide *g, Int t)
{
flatguide f;
g->flatten(f,false);
Int n=f.size();
if(!g->cyclic() && (t < 0 || t >= n-1)) return new array(0);
array *c=new array(2);
(*c)[0]=f.Nodes(t).out->dir();
(*c)[1]=f.Nodes(t+1).in->dir();
return c;
}
pairarray *controlSpecifier(guide *g, Int t)
{
flatguide f;
g->flatten(f,false);
Int n=f.size();
if(!g->cyclic() && (t < 0 || t >= n-1)) return new array(0);
knot curr=f.Nodes(t);
knot next=f.Nodes(t+1);
if(curr.out->controlled()) {
assert(next.in->controlled());
array *c=new array(2);
(*c)[0]=curr.out->control();
(*c)[1]=next.in->control();
return c;
} else return new array(0);
}
tensionSpecifier tensionSpecifier(guide *g, Int t)
{
flatguide f;
g->flatten(f,false);
Int n=f.size();
if(!g->cyclic() && (t < 0 || t >= n-1)) return tensionSpecifier(1.0,1.0,false);
knot curr=f.Nodes(t);
return tensionSpecifier(curr.tout.val,f.Nodes(t+1).tin.val,curr.tout.atleast);
}
realarray *curlSpecifier(guide *g, Int t)
{
flatguide f;
g->flatten(f,false);
Int n=f.size();
if(!g->cyclic() && (t < 0 || t >= n-1)) return new array(0);
array *c=new array(2);
real c0=f.Nodes(t).out->curl();
real c1=f.Nodes(t+1).in->curl();
(*c)[0]=c0 >= 0.0 ? c0 : 1.0;
(*c)[1]=c1 >= 0.0 ? c1 : 1.0;
return c;
}
guide *reverse(guide *g)
{
flatguide f;
g->flatten(f,false);
if(f.precyclic())
return new pathguide(g->solve().reverse());
size_t n=f.size();
bool cyclic=g->cyclic();
guidevector v;
size_t start=cyclic ? n : n-1;
knot curr=f.Nodes(start);
knot next;
for(size_t i=start; i > 0; --i) {
next=f.Nodes(i-1);
v.push_back(new pairguide(curr.z));
if(next.out->controlled()) {
assert(curr.in->controlled());
v.push_back(new controlguide(curr.in->control(),next.out->control()));
} else {
pair d=curr.in->dir();
if(d != zero)
v.push_back(new specguide(new dirSpec(-d),camp::OUT));
else {
real C=curr.in->curl();
if(C >= 0.0)
v.push_back(new specguide(new curlSpec(C),camp::OUT));
}
real tout=curr.tin.val;
real tin=next.tout.val;
bool atleast=next.tout.atleast;
if(tout != 1.0 || tin != 1.0 || next.tout.atleast)
v.push_back(new tensionguide(tensionSpecifier(tout,tin,atleast)));
d=next.out->dir();
if(d != zero)
v.push_back(new specguide(new dirSpec(-d),camp::IN));
else {
real C=next.out->curl();
if(C >= 0.0)
v.push_back(new specguide(new curlSpec(C),camp::IN));
}
}
curr=next;
}
if(cyclic)
v.push_back(new cycletokguide());
else
v.push_back(new pairguide(next.z));
return new multiguide(v);
}
realarray *_cputime()
{
static const real ticktime=1.0/sysconf(_SC_CLK_TCK);
struct tms buf;
::times(&buf);
array *t=new array(4);
(*t)[0] = ((real) buf.tms_utime)*ticktime;
(*t)[1] = ((real) buf.tms_stime)*ticktime;
(*t)[2] = ((real) buf.tms_cutime)*ticktime;
(*t)[3] = ((real) buf.tms_cstime)*ticktime;
return t;
}
// Transforms
bool ==(transform a, transform b)
{
return a == b;
}
bool !=(transform a, transform b)
{
return a != b;
}
transform +(transform a, transform b)
{
return a+b;
}
transform Operator *(transform a, transform b)
{
return a*b;
}
pair Operator *(transform t, pair z)
{
return t*z;
}
path Operator *(transform t, path g)
{
return transformed(t,g);
}
pen Operator *(transform t, pen p)
{
return transformed(t,p);
}
picture * Operator *(transform t, picture *f)
{
return transformed(t,f);
}
picture * Operator *(realarray2 *t, picture *f)
{
return transformed(*t,f);
}
transform ^(transform t, Int n)
{
transform T;
if(n < 0) {
n=-n;
t=inverse(t);
}
for(Int i=0; i < n; i++) T=T*t;
return T;
}
real :transformXPart(transform t)
{
return t.getx();
}
real :transformYPart(transform t)
{
return t.gety();
}
real :transformXXPart(transform t)
{
return t.getxx();
}
real :transformXYPart(transform t)
{
return t.getxy();
}
real :transformYXPart(transform t)
{
return t.getyx();
}
real :transformYYPart(transform t)
{
return t.getyy();
}
transform :real6ToTransform(real x, real y, real xx, real xy,
real yx, real yy)
{
return transform(x,y,xx,xy,yx,yy);
}
transform shift(transform t)
{
return transform(t.getx(),t.gety(),0,0,0,0);
}
transform shiftless(transform t)
{
return transform(0,0,t.getxx(),t.getxy(),t.getyx(),t.getyy());
}
transform identity:transformIdentity()
{
return identity;
}
transform inverse(transform t)
{
return inverse(t);
}
transform shift(pair z)
{
return shift(z);
}
transform shift(real x, real y)
{
return shift(pair(x,y));
}
transform xscale(real x)
{
return xscale(x);
}
transform yscale(real y)
{
return yscale(y);
}
transform scale(real x)
{
return scale(x);
}
transform scale(real x, real y)
{
return scale(x,y);
}
transform slant(real s)
{
return slant(s);
}
transform rotate(real angle, pair z=0)
{
return rotatearound(z,radians(angle));
}
transform reflect(pair a, pair b)
{
return reflectabout(a,b);
}
|