## #11 Improvements for scripted pattern editing

open
nobody
5
2006-06-23
2006-06-23
Dan Hoey
No

The biggesst problem I see is that there is no way of
clearing a rectangle without using the selection.
clearcells(rect-list) would help.

putcells(cell-list, x0, y0, axx, axy, ayx, ayy) could
usefully have an eighth argument, mode: 0 for clear, 1
for set, 2 for xor.

setcell(x, y, state) could also be extended to
setcell(x, y, mode), using mode as above.

Memory usage is also a big problem. Using python's
array package may help. Unfortunately, python has only
one-dimensional arrays, so we have to give a width
(which should divide the array length.

toarray(array,width,x,y,mode) would put cells from the
pattern into the array according to mode;
fromarray(array,width,x,y,mode) would put cells from
the array into the pattern.

The array corresponds to the pattern cells
(x,y), (x+1,y), ..., (x+width-1,y),
(x,y+1), (x+1,y+1), ..., (x+width-1,y+1), ...
(x,y+k), (x+1,y+k), ..., (x+width-1,y+k)
where k = len(array)/width - 1 .

Here, mode is an integer from 0 to 15 as in Common Lisp
BOOLE:
0 0 1 1 source
0 1 0 1 dest
integer op
0 clear 0 0 0 0 dest result
1 and 0 0 0 1
2 andc2 0 0 1 0
3 move 0 0 1 1
4 andc1 0 1 0 0
5 nop 0 1 0 1
6 xor 0 1 1 0
7 or 0 1 1 1
8 nor 1 0 0 0
9 eqv 1 0 0 1
10 comp 1 0 1 0
11 orc2 1 0 1 1
12 movec1 1 1 0 0
13 orc1 1 1 0 1
14 nand 1 1 1 0
15 fill 1 1 1 1

I don't know c++, so I'm not going to implement this,
but it would greatly speed up a script I'm writing.
I assume I contribute scripts by attaching them to

Dan Hoey

## Discussion

• Dan Hoey - 2006-06-23

Logged In: YES
user_id=1372332

Sorry about the BOOLE table. I hope the &lt;pre&gt; tag orks
<pre>
0 0 1 1 source
0 1 0 1 dest
mode op
0 clear 0 0 0 0 dest result
1 and 0 0 0 1
2 andc2 0 0 1 0
3 move 0 0 1 1
4 andc1 0 1 0 0
5 nop 0 1 0 1
6 xor 0 1 1 0
7 or 0 1 1 1
8 nor 1 0 0 0
9 eqv 1 0 0 1
10 comp 1 0 1 0
11 orc2 1 0 1 1
12 movec1 1 1 0 0
13 orc1 1 1 0 1
14 nand 1 1 1 0
15 fill 1 1 1 1
</pre>

• Tomas Rokicki - 2006-06-24

Logged In: YES
user_id=1262668

Howdy! Thanks for the feedback! I don't see the script;
could you either attach it or email it separately? I'm glad
someone's looking at the scripting; it's really cool stuff.

-tom

• Dan Hoey - 2006-06-26

Logged In: YES
user_id=1372332

The script is not ready yet, but I've learned a lot of
python over the weekend and I hope to have a version of the
script in a few days. I now expect that what we want is

putcells_from_buffer(buffer,rect,mode) and
getcells_to_buffer(buffer,rect,mode)

where rect is a rectangle and buffer is a buffer (or perhaps
an array) with enough space to hold the data in the
rectangle. The whole idea is to get a way of reading and
writing the pattern space that doesn't involve new memory
allocation.

For a more modest proposal,
dumpcells_to_file(rect,path) and
would work, with the idea being that we don't mess around
with rle or the like, just a raw bitmap. If the file
exists, dumpcells_to_file would ideally overwrite it in
place rather than allocating new disk space (and it could
even be an error to dumpcells to a file that has a different
size or shape of rectangle.)

I may implement the latter two inefficiently with the
current interface. Then the addition of a c++ method would
be a speedup of a couple of orders of magnitude and avoid
the memory churn inherent in the current methods.

Dan

• Dan Hoey - 2006-06-27

Logged In: YES
user_id=1372332

Here is a python reference implementation of
dumpcells_to_file and loadcells_from_file. I figure moving
this into the c++ core would probably improve performance by
several orders of magnitude.

Another feature request is empty(rectangle) to test whether
a rectangle has any cells set. This could be a compatible
extension of empty(rectangle=None), where None as a
rectangle means the entire plane (as opposed to [], which is
always empty). While I'm at it, I would prefer the name
"isempty" for golly.empty. That's probably best done with
definining "empty" as a deprecated alias.

• Dan Hoey - 2006-06-27

Reference implementation of loadcells_from_file and dumpcells_to_file