Commit 1a7e8723 authored by Adam P. Goucher's avatar Adam P. Goucher

Repair slicing and allow assigning to slices

parent b9f47959
......@@ -128,6 +128,13 @@ extern "C"
return new(std::nothrow) apg::pattern(ppat->advance2(numgens, exponent));
}
void* GetSolidForPattern(void* pat, uint64_t state) {
auto ppat = reinterpret_cast<apg::pattern*>(pat);
auto lab = ppat->getlab();
uint64_t depth = ppat->gethnode().depth;
return new(std::nothrow) apg::pattern(lab, lab->solid(depth, state), ppat->getrule());
}
void* GetSemisolidForPattern(void* pat, int flags) {
auto ppat = reinterpret_cast<apg::pattern*>(pat);
auto lab = ppat->getlab();
......
......@@ -1235,6 +1235,21 @@ namespace apg {
return hnode;
}
hypernode<I> solid(uint32_t depth, uint64_t state) {
nicearray<uint64_t, 4*N> outleaf;
for (uint64_t i = 0; i < N; i++) {
std::memset(outleaf.x + (4*i), (((state >> i) & 1) ? 255 : 0), 32);
}
hypernode<I> hnode(make_leaf(outleaf), 0);
while (hnode.depth < depth) {
nicearray<I, 4> cc = {hnode.index, hnode.index, hnode.index, hnode.index};
hnode = make_nonleaf_hn(hnode.depth + 1, cc);
}
return hnode;
}
hypernode<I> invstring_recurse(std::string &str, uint64_t &loc) {
char ch = str[loc++];
if ((ch >= 'F') && (ch <= 'Z')) {
......
......@@ -84,6 +84,7 @@ namespace apg {
virtual hypernode<I> make_nonleaf_hn(uint32_t depth, nicearray<I, 4> contents) = 0;
virtual I getpop_recurse(hypernode<I> hnode, I modprime, uint64_t layermask) = 0;
virtual hypernode<I> solid(uint32_t depth) = 0;
virtual hypernode<I> solid(uint32_t depth, uint64_t state) = 0;
virtual hypernode<I> getchild(hypernode<I> hnode, uint32_t n) = 0;
virtual uint64_t leafpart(I index, uint32_t part) = 0;
......
......@@ -69,7 +69,8 @@ restypes = {'DeletePattern': None, 'GetBeszelIndex': c_uint64, 'GetUlqomaIndex':
'GetDYOfPattern': c_int64, 'GetApgcodeOfPattern': None, 'SavePatternRLE': None, 'SavePatternMC': None,
'GetPopulationOfPattern': None, 'CreateLifetree': c_void_p, 'CreatePatternFromRLE': c_void_p,
'CreateRectangle': c_void_p, 'DeleteLifetree': None, 'GetPatternBox': None, 'PatternEquality': c_bool,
'PatternNonempty': c_bool, 'MatchLive': c_void_p, 'MatchLiveAndDead': c_void_p, 'GetRuleOfPattern': None}
'PatternNonempty': c_bool, 'MatchLive': c_void_p, 'MatchLiveAndDead': c_void_p, 'GetRuleOfPattern': None,
'GetSolidForPattern': c_void_p}
def call_underlying(lifelib, fname_and_args):
......
......@@ -48,6 +48,11 @@ class Pattern(object):
return temp
def _solid(self, state):
newptr = self.lifelib('GetSolidForPattern', self.ptr, state)
return Pattern(self.session, newptr, self.owner)
def _semisolid(self, flags):
newptr = self.lifelib('GetSemisolidForPattern', self.ptr, flags)
......@@ -358,19 +363,45 @@ class Pattern(object):
bottom = x[1].stop
subrect = self
bigenough = self
onecell = self.owner.pattern("o!", self.getrule())
if left is not None:
bigenough = bigenough + onecell.shift(left, 0)
if right is not None:
bigenough = bigenough + onecell.shift(right-1, 0)
if top is not None:
bigenough = bigenough + onecell.shift(0, top)
if bottom is not None:
bigenough = bigenough + onecell.shift(0, bottom-1)
if left is not None:
subrect = subrect & self._semisolid(10).shift(left, 0)
subrect = subrect & bigenough._semisolid(10).shift(left, 0)
if right is not None:
subrect = subrect & self._semisolid(5).shift(right, 0)
subrect = subrect & bigenough._semisolid(5).shift(right, 0)
if top is not None:
subrect = subrect & self._semisolid(12).shift(0, top)
subrect = subrect & bigenough._semisolid(12).shift(0, top)
if bottom is not None:
subrect = subrect & self._semisolid(3).shift(0, bottom)
subrect = subrect & bigenough._semisolid(3).shift(0, bottom)
return subrect
else:
raise TypeError("operator[] accepts either a generation (int) or a pair of slices")
def __setitem__(self, x, item):
self -= self[x]
if isinstance(item, Integral):
if (item == 0):
return
onecell = self.owner.pattern("o!", self.getrule())
bigenough = onecell(x[0].start, x[1].start) + onecell(x[0].stop - 1, x[1].stop - 1)
item = bigenough._solid(item)
self += item[x]
def getrect(self):
logdiam = self.lifelib('GetDiameterOfPattern', self.ptr)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment