def get_hilbert_curve(): """Example of fractal curve due to D.Hilbert.""" proto = [(0, 0), (0, 1), (1, 1), (1, 0)] base_maps = [ BaseMap.parse('(x,y)->(y,x)'), BaseMap.id_map(2), BaseMap.id_map(2), BaseMap.parse('(x,y)->(1-y,1-x)'), ] return Curve(dim=2, div=2, patterns=[(proto, base_maps)])
def test_apply_base_map_unit(self): """Test that the application of a sequence of base_maps with unit product does not change the curve.""" rot_90 = BaseMap([(1,True), (0,False)]) # поворот на 90 градусов rot_90_t = BaseMap.parse('jI~') bms_list = [ [rot_90] * 3, [rot_90_t] * 3, [ BaseMap([(1,False), (0,False)], time_rev=True), BaseMap([(0,True), (1,False)]), ], [ BaseMap([(0,True),(2,False),(1,True)], time_rev=True), BaseMap([(1,False),(0,True),(2,True)], time_rev=True), ], ] for bms in bms_list: # will make bms[0] * bms[1] * ... * bms[-1] * last_map = id <=> last_map = bms[-1]^{-1} * ... * bms[0]^{-1} last_map = BaseMap.id_map(dim=bms[0].dim) for bm in bms: last_map = bm**(-1) * last_map for curve in self.curves: if curve.dim != bms[0].dim: continue orig = curve current = curve for bm in reversed(bms + [last_map]): current = bm * current self.assertEqual(orig.proto, current.proto) self.assertEqual(orig.specs, current.specs)
def get_scepin_bauman_curve(): """ Minimal 3*3 Peano Curve by E.V. Shchepin and K.E. Bauman. Proceedings of the Steklov Institute of Mathematics, 2008, Vol. 263, pp. 236--256. """ proto = ( # as in peano curve (0, 0), (0, 1), (0, 2), (1, 2), (1, 1), (1, 0), (2, 0), (2, 1), (2, 2), ) base_maps = [ BaseMap.id_map(dim=2), BaseMap.parse('jI'), BaseMap.parse('ji'), BaseMap.parse('iJ'), BaseMap.parse('JI'), BaseMap.parse('Ji'), BaseMap.id_map(dim=2), BaseMap.parse('jI'), BaseMap.parse('ji'), ] return Curve(dim=2, div=3, patterns=[(proto, base_maps)])
def test_ye_dilation(self): # TODO: use ye curve from examples ? good_proto = Proto(dim=2, div=5, cubes=[ (0, 0), (0, 1), (1, 1), (1, 0), (2, 0), (2, 1), (2, 2), (1, 2), (0, 2), (0, 3), (0, 4), (1, 4), (1, 3), (2, 3), (2, 4), (3, 4), (4, 4), (4, 3), (3, 3), (3, 2), (4, 2), (4, 1), (3, 1), (3, 0), (4, 0), ]) # in new version we have (0,0)->(0,1) gate good_proto = BaseMap.parse('ji') * good_proto paths_gen = PathsGenerator(dim=2, div=5, hdist=1, max_cdist=1) for paths in paths_gen.generate_paths(): if paths[0].proto == good_proto: path0 = paths[0] break pcurve = PathFuzzyCurve.init_from_paths([path0]) estimator = Estimator(utils.ratio_l2_squared) curve = estimator.estimate_dilation(pcurve, rel_tol_inv=10000, verbose=False)['curve'] dilation = estimator.estimate_dilation(curve, rel_tol_inv=10000, use_vertex_brkline=True, verbose=False, max_depth=5) assert dilation['lo'] == (Rational(408, 73)**2)
def get_scepin_bauman_curve(): proto = ( (0, 0), (0, 1), (0, 2), (1, 2), (1, 1), (1, 0), (2, 0), (2, 1), (2, 2), ) base_maps = [ BaseMap.id_map(dim=2), BaseMap([(1, True), (0, False)]), # rot(90) BaseMap.parse('(x,y)->(y,x)'), BaseMap.parse('(x,y)->(x,1-y)'), BaseMap.parse('(x,y)->(1-y,1-x)'), BaseMap([(1, False), (0, True)]), # rot(-90) BaseMap.id_map(dim=2), BaseMap([(1, True), (0, False)]), # rot(90) BaseMap([(1, False), (0, False)]), # (x,y)->(y,x) ] return Curve(dim=2, div=3, patterns=[(proto, base_maps)])
def test_mul(self): bm1 = BaseMap.parse('Ij') bm2 = BaseMap.parse('ji') self.assertEqual(bm1 * bm2, BaseMap.parse('jI')) self.assertEqual(bm2 * bm1, BaseMap.parse('Ji'))
def get_peano5_curve(): """5-div analog of original Peano curve.""" id_map = BaseMap.id_map(2) x_map = BaseMap.parse('Ij') y_map = BaseMap.parse('iJ') xy_map = BaseMap.parse('IJ') proto = [ (0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (1, 4), (1, 3), (1, 2), (1, 1), (1, 0), (2, 0), (2, 1), (2, 2), (2, 3), (2, 4), (3, 4), (3, 3), (3, 2), (3, 1), (3, 0), (4, 0), (4, 1), (4, 2), (4, 3), (4, 4), ] base_maps = [ id_map, x_map, id_map, x_map, id_map, y_map, xy_map, y_map, xy_map, y_map, id_map, x_map, id_map, x_map, id_map, y_map, xy_map, y_map, xy_map, y_map, id_map, x_map, id_map, x_map, id_map, ] return Curve(dim=2, div=5, patterns=[(proto, base_maps)])