Skip to content

Commit b5db2f8

Browse files
committed
renmatrix: Use stack for variables within the trace loop
1 parent d488cd7 commit b5db2f8

1 file changed

Lines changed: 52 additions & 9 deletions

File tree

src/renmatrix.ps.src

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ begin
9393
% 0|1
9494

9595
% 0 1 0^1
96-
{dir //renmatrix.right eq {down} {up} ifelse} bind % -+ or +-
96+
{dup //renmatrix.right eq {down} {up} ifelse} bind % -+ or +-
9797
% 1v0 1 0
9898

9999
% 0^1
@@ -105,7 +105,7 @@ begin
105105
% 0 0
106106

107107
% 1|0 1 0
108-
{dir //renmatrix.down eq {left} {right} ifelse} bind % <+ or +>
108+
{dup //renmatrix.down eq {left} {right} ifelse} bind % <+ or +>
109109
% 0 1 0|1
110110

111111
% 1|0
@@ -259,10 +259,48 @@ begin
259259
/pack { pixxpad mul add } def % x y -> y*pixxpad+x
260260
/unpack { dup pixxpad mod exch pixxpad idiv } def % packed -> x y
261261

262-
/left {dir //renmatrix.left ne {x y dir cput x y pack} if /x x 1 sub def /dir //renmatrix.left def} def
263-
/right {dir //renmatrix.right ne {x y dir cput x y pack} if /x x 1 add def /dir //renmatrix.right def} def
264-
/up {dir //renmatrix.up ne {x y dir cput x y pack} if /y y 1 sub def /dir //renmatrix.up def} def
265-
/down {dir //renmatrix.down ne {x y dir cput x y pack} if /y y 1 add def /dir //renmatrix.down def} def
262+
%
263+
% Stack: x y dir -> (packed vertex?) x' y' dir'
264+
%
265+
/left {
266+
dup //renmatrix.left ne {
267+
3 copy cput
268+
2 index 2 index pack 4 1 roll
269+
} if
270+
pop
271+
exch 1 sub exch % x--
272+
//renmatrix.left
273+
} def
274+
275+
/right {
276+
dup //renmatrix.right ne {
277+
3 copy cput
278+
2 index 2 index pack 4 1 roll
279+
} if
280+
pop
281+
exch 1 add exch % x++
282+
//renmatrix.right
283+
} def
284+
285+
/up {
286+
dup //renmatrix.up ne {
287+
3 copy cput
288+
2 index 2 index pack 4 1 roll
289+
} if
290+
pop
291+
1 sub % y--
292+
//renmatrix.up
293+
} def
294+
295+
/down {
296+
dup //renmatrix.down ne {
297+
3 copy cput
298+
2 index 2 index pack 4 1 roll
299+
} if
300+
pop
301+
1 add % y++
302+
//renmatrix.down
303+
} def
266304

267305
%
268306
% Walk the outline of a region emitting edge coordinates of the path
@@ -272,9 +310,14 @@ begin
272310
/dir x 1 add y 1 add xyget 1 eq {//renmatrix.up} {//renmatrix.left} ifelse def
273311
/sx x def /sy y def /sdir dir def
274312

275-
mark {
276-
//renmatrix.tracestep x y abcdget get exec
277-
x sx eq y sy eq and dir sdir eq and {exit} if
313+
mark x y dir
314+
{ % [vertex...] x y dir
315+
//renmatrix.tracestep 3 index 3 index abcdget get exec
316+
dup sdir eq {
317+
1 index sy eq {
318+
2 index sx eq { pop pop pop exit } if
319+
} if
320+
} if
278321
} loop
279322
counttomark array astore exch pop
280323

0 commit comments

Comments
 (0)