summaryrefslogtreecommitdiff
path: root/Master/texmf/asymptote/plain_xasy.asy
blob: 162cbfb35ad3bf888384c740225a2ed9a6c9715b (plain)
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
restricted bool inXasyMode=false;
bool diagnostics=false;
void report(string text)
{
 if(diagnostics)
  write(text);
}
void report(transform t)
{
 if(diagnostics)
  write(t);
}
void report(int i)
{
 if(diagnostics)
  write(i);
}
void initXasyMode()
{
  size(0,0);
  inXasyMode=true;
}

void exitXasyMode()
{
  inXasyMode=false;
}
private picture[] tempStore;
private picture newPic;
void startScript()
{
  tempStore.push(currentpicture.copy());
  newPic=new picture;
  currentpicture=newPic;
}

void endScript()
{
  if(tempStore.length < 1) {
    abort("endScript() without matching beginScript()");
  } else {
    currentpicture=tempStore.pop();
    add(currentpicture,newPic.fit(),group=false);
  }
  shipped=false;
}

struct indexedTransform {
  int index;
  transform t;
  bool active;
  void operator init(int index, transform t, bool active=true) {
    this.index=index;
    this.t=t;
    this.active=active;
  }
}

struct framedTransformStack {
  struct transact {
    transform t;
    bool active;
    void operator init(transform t, bool active=true) {
      this.t=t;
      this.active=active;
    }
    void operator init(indexedTransform i){
      this.t=i.t;
      this.active=i.active;
    }
    void operator init() {
      this.t=identity();
      this.active=true;
    }
  }
  private transact[] stack;
  private int[] frames;
  private int stackBase=0;
  transform pop() {
    if(stack.length == 0)
      return identity();
    else {
      transform popped=stack[0].t;
      stack.delete(0);
      report("Popped");
      report(popped);
      return popped;
    }
  }

  transform pop0() {
    if(stack.length == 0)
      return identity();
    else {
      static transform zerotransform=(0,0,0,0,0,0);
      transform popped=stack[0].active ? stack[0].t : zerotransform;
      stack.delete(0);
      report("Popped");
      report(popped);
      return popped;
    }
  }

  void push(transform t, bool Active=true) {
    report("Pushed");
    report(t);
    stack.push(transact(t,Active));
  }

  void add(... indexedTransform[] tList) {
    transact[] toPush;
    for(int a=0; a < tList.length; ++a)
      toPush[tList[a].index]=transact(tList[a]);
    for(int a=0; a < toPush.length; ++a)
      if(!toPush.initialized(a))
	toPush[a]=transact();
    report("Added");
    report(toPush.length);
    stack.append(toPush);
  }
}

framedTransformStack xformStack;

void deconstruct(picture pic=currentpicture, real magnification=1)
{
  deconstruct(pic.fit(),currentpatterns,magnification,xformStack.pop);
}