Commit b327f1d7 authored by Adam P. Goucher's avatar Adam P. Goucher

Include __copy__() method for patterns

parent f630ed4e
Pipeline #55527350 passed with stages
in 8 minutes and 20 seconds
......@@ -205,6 +205,11 @@ extern "C"
return new(std::nothrow) apg::pattern(ppat->match(*ppat1));
void* CopyPattern(void* pat) {
auto ppat = reinterpret_cast<apg::pattern*>(pat);
return new(std::nothrow) apg::pattern(*ppat);
void* MatchLiveAndDead(void* pat, void* pat1, void* pat0) {
auto ppat = reinterpret_cast<apg::pattern*>(pat);
auto ppat1 = reinterpret_cast<apg::pattern*>(pat1);
......@@ -76,7 +76,7 @@ restypes = {'DeletePattern': None, 'GetBeszelIndex': c_uint64, 'GetUlqomaIndex':
'GetSolidForPattern': c_void_p, 'GetOriginState': c_uint64, 'GetCells': None, 'SetCells': None,
'CreatePatternFromFile': c_void_p, 'MakeSpaceshipStream': c_void_p, 'GetCompiledVersion': None,
'GetCoords': None, 'GetPatternBound': c_uint64, 'GetSubpops': None, 'Hashsoup': c_void_p,
'FindConnectedComponent': c_void_p, 'GetOneCell': c_void_p}
'FindConnectedComponent': c_void_p, 'GetOneCell': c_void_p, 'CopyPattern': c_void_p}
def call_underlying(lifelib, fname_and_args):
......@@ -204,6 +204,11 @@ class Pattern(object):
newptr = self.lifelib('TransformPattern', self.ptr, tfm)
return Pattern(self.session, newptr, self.owner)
def __copy__(self):
newptr = self.lifelib('CopyPattern', self.ptr)
return Pattern(self.session, newptr, self.owner)
def shift(self, x, y, exponent=0):
if not isinstance(x, Integral):
......@@ -36,6 +36,17 @@ $3b3o3b2o3b2o3bo2bo7bo2bo12b3o$3bo2bo2b2o3b2o2bo3bo7bob2o12bo2bo$3bo
ncomps = len(pat.components())
self.assertEqual(ncomps, 41)
def test_copy(self):
pat ='xp40_33zxs48g69gvzx3021zy833')
pat2 = pat.__copy__()
self.assertEqual(pat, pat2)
pat += pat(1093, 3511)
self.assertNotEqual(pat, pat2)
pat2 += pat2(1093, 3511)
self.assertEqual(pat, pat2)
def test_samples(self):
pat ='xp40_33zxs48g69gvzx3021zy833')
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