Example #1
0
    def testVectors(self):
        siteobj = FractalSite()
        site = fract4dc.site_create(siteobj)

        file = self.compileColorDiagonal()
        handle = fract4dc.pf_load(file)
        pfunc = fract4dc.pf_create(handle)
        fract4dc.pf_init(pfunc, pos_params, self.color_diagonal_params)

        (w, h, tw, th) = (40, 20, 40, 20)
        im = image.T(w, h)

        cmap = fract4dc.cmap_create([(1.0, 255, 255, 255, 255)])

        fw = fract4dc.fw_create(1, pfunc, cmap, im._img, site)

        ff = fract4dc.ff_create(
            [0.0, 0.0, 0.0, 0.0,
             4.0,
             0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
            2,
            100,
            0,
            1,
            pfunc,
            cmap,
            0,
            1,
            0,
            im._img,
            site,
            fw,
            False,
            1.0E-9)

        # check dx, dy and topleft
        dx = fract4dc.ff_get_vector(ff, fract4dc.DELTA_X)
        self.assertNearlyEqual(dx, [4.0 / tw, 0.0, 0.0, 0.0])

        dy = fract4dc.ff_get_vector(ff, fract4dc.DELTA_Y)
        self.assertNearlyEqual(dy, [0.0, -2.0 / th, 0.0, 0.0])

        topleft = fract4dc.ff_get_vector(ff, fract4dc.TOPLEFT)
        self.assertNearlyEqual(
            topleft, [-2.0 + 4.0 / (tw * 2), 1.0 - 2.0 / (th * 2), 0.0, 0.0])

        # check they are updated if image is bigger
        (w, h, tw, th) = (40, 20, 400, 200)
        im = image.T(w, h, tw, th)

        fw = fract4dc.fw_create(1, pfunc, cmap, im._img, site)

        ff = fract4dc.ff_create(
            [0.0, 0.0, 0.0, 0.0,
             4.0,
             0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
            2,
            100,
            0,
            1,
            pfunc,
            cmap,
            0,
            1,
            0,
            im._img,
            site,
            fw,
            False,
            1.0E-9)

        # check dx, dy and topleft
        dx = fract4dc.ff_get_vector(ff, fract4dc.DELTA_X)
        self.assertNearlyEqual(dx, [4.0 / tw, 0.0, 0.0, 0.0])

        dy = fract4dc.ff_get_vector(ff, fract4dc.DELTA_Y)
        self.assertNearlyEqual(dy, [0.0, -2.0 / th, 0.0, 0.0])

        topleft = fract4dc.ff_get_vector(ff, fract4dc.TOPLEFT)
        self.assertNearlyEqual(
            topleft, [-2.0 + 4.0 / (tw * 2), 1.0 - 2.0 / (th * 2), 0.0, 0.0])

        offx = 40
        offy = 10
        im.set_offset(offx, offy)

        fw = fract4dc.fw_create(1, pfunc, cmap, im._img, site)

        ff = fract4dc.ff_create(
            [0.0, 0.0, 0.0, 0.0,
             4.0,
             0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
            2,
            100,
            0,
            1,
            pfunc,
            cmap,
            0,
            1,
            0,
            im._img,
            site,
            fw,
            False,
            1.0E-9)

        # check dx, dy and topleft
        dx = fract4dc.ff_get_vector(ff, fract4dc.DELTA_X)
        self.assertNearlyEqual(dx, [4.0 / tw, 0.0, 0.0, 0.0])

        dy = fract4dc.ff_get_vector(ff, fract4dc.DELTA_Y)
        self.assertNearlyEqual(dy, [0.0, -2.0 / th, 0.0, 0.0])

        topleft = fract4dc.ff_get_vector(ff, fract4dc.TOPLEFT)
        self.assertNearlyEqual(topleft, [
            -2.0 + dx[0] * (offx + 0.5),
            1.0 + dy[1] * (offy + 0.5),
            0.0, 0.0])
Example #2
0
    def testVectors(self):
        siteobj = FractalSite()
        site = fract4dc.site_create(siteobj)

        file = self.compileColorDiagonal()
        handle = fract4dc.pf_load(file)
        pfunc = fract4dc.pf_create(handle)
        fract4dc.pf_init(pfunc,pos_params,self.color_diagonal_params)

        (w,h,tw,th) = (40,20,40,20)
        im = image.T(w,h)
        
        cmap = fract4dc.cmap_create([(1.0, 255, 255, 255, 255)])

        fw = fract4dc.fw_create(1,pfunc,cmap,im._img,site)
        
        ff = fract4dc.ff_create(
            [0.0, 0.0, 0.0, 0.0,
             4.0,
             0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
            2,
            100,
            0,
            1,
            pfunc,
            cmap,
            0,
            1,
            0,
            im._img,
            site,
            fw,
            False,
            1.0E-9)

        # check dx, dy and topleft
        dx = fract4dc.ff_get_vector(ff, fract4dc.DELTA_X)
        self.assertNearlyEqual(dx, [4.0/tw,0.0,0.0,0.0])

        dy = fract4dc.ff_get_vector(ff, fract4dc.DELTA_Y);
        self.assertNearlyEqual(dy, [0.0,-2.0/th,0.0,0.0])

        topleft = fract4dc.ff_get_vector(ff, fract4dc.TOPLEFT);
        self.assertNearlyEqual(topleft, [-2.0 + 4.0/(tw*2),1.0 - 2.0/(th*2),0.0,0.0])

        # check they are updated if image is bigger
        (w,h,tw,th) = (40,20,400,200)
        im = image.T(w,h,tw,th)
        
        fw = fract4dc.fw_create(1,pfunc,cmap,im._img,site)
        
        ff = fract4dc.ff_create(
            [0.0, 0.0, 0.0, 0.0,
             4.0,
             0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
            2,
            100,
            0,
            1,
            pfunc,
            cmap,
            0,
            1,
            0,
            im._img,
            site,
            fw,
            False,
            1.0E-9)

        # check dx, dy and topleft
        dx = fract4dc.ff_get_vector(ff, fract4dc.DELTA_X)
        self.assertNearlyEqual(dx, [4.0/tw,0.0,0.0,0.0])

        dy = fract4dc.ff_get_vector(ff, fract4dc.DELTA_Y);
        self.assertNearlyEqual(dy, [0.0,-2.0/th,0.0,0.0])

        topleft = fract4dc.ff_get_vector(ff, fract4dc.TOPLEFT);
        self.assertNearlyEqual(topleft, [-2.0 + 4.0/(tw*2),1.0 - 2.0/(th*2),0.0,0.0])

        offx = 40
        offy = 10
        im.set_offset(offx, offy)

        fw = fract4dc.fw_create(1,pfunc,cmap,im._img,site)
        
        ff = fract4dc.ff_create(
            [0.0, 0.0, 0.0, 0.0,
             4.0,
             0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
            2,
            100,
            0,
            1,
            pfunc,
            cmap,
            0,
            1,
            0,
            im._img,
            site,
            fw,
            False,
            1.0E-9)

        # check dx, dy and topleft
        dx = fract4dc.ff_get_vector(ff, fract4dc.DELTA_X)
        self.assertNearlyEqual(dx, [4.0/tw,0.0,0.0,0.0])

        dy = fract4dc.ff_get_vector(ff, fract4dc.DELTA_Y);
        self.assertNearlyEqual(dy, [0.0,-2.0/th,0.0,0.0])

        topleft = fract4dc.ff_get_vector(ff, fract4dc.TOPLEFT);
        self.assertNearlyEqual(topleft, [
            -2.0 + dx[0] * (offx + 0.5),
             1.0 + dy[1] * (offy + 0.5),
            0.0,0.0])