Пример #1
0
void sierpinskiiterate(Draw *fractal, SDL_Win *window, Shape current, 
                           int iterations, int limit) {
    if (current.size < 2 || iterations == limit) {
        draw_sdl(window, fractal, current.x, current.y, 
                     current.size/2, current.rotation, iterations);
        return;
    }

    Shape top, left, right;
    float l_angle = fractal->angle - ((2*M_PI)/3.0);
    float r_angle = fractal->angle + ((2*M_PI)/3.0);

    make_shape(&top, current.x + ((current.size/4)*sin(fractal->angle)), 
                     current.y - ((current.size/4)*cos(fractal->angle)), 
                     current.size / 2, current.height/2, fractal->angle);

    make_shape(&left, current.x + ((current.size/4))*sin(l_angle),
                      current.y - ((current.size/4))*cos(l_angle), 
                      current.size/2, current.height/2, l_angle);

    make_shape(&right, current.x + ((current.size/4))*sin(r_angle),
                       current.y - ((current.size/4))*cos(r_angle),
                       current.size/2, current.height/2, r_angle);

    iterations++;

    sierpinskiiterate(fractal, window, top, iterations, limit);
    sierpinskiiterate(fractal, window, left, iterations, limit);
    sierpinskiiterate(fractal, window, right, iterations, limit);
}
Пример #2
0
void treeiterate(Draw *fractal, SDL_Win *window, Shape current, 
                     int iterations, int limit, float angle, int bx, int by) {
    if(current.size < 2 || iterations == limit) {
        return;
    }

    float newangle;
    int cx, cy;
    Shape *shapes = malloc(fractal->splits[iterations]*sizeof(Shape));
    int newsize = current.size/fractal->splits[iterations];

    iterations++; 
 
    for(int i=0; i<fractal->splits[iterations]/2; i++) {
        newangle = angle - (fractal->anglerange/2.0) + 
                       i*(fractal->anglerange/fractal->splits[iterations]);
        cx = bx + ((newsize)*sin(newangle));
        cy = by - ((newsize)*cos(newangle));
        make_shape(&shapes[i], cx, cy, 
                       newsize, 
                       current.height/fractal->splits[iterations], newangle);
        draw_sdl(window, fractal, cx, cy, 
                     newsize, 
                     newangle, iterations);

        newangle = angle + (fractal->anglerange/2.0) - 
                       i*(fractal->anglerange/fractal->splits[iterations]);
        cx = bx + (sin(newangle)*(newsize));
        cy = by - (cos(newangle)*(newsize));
        make_shape(&shapes[fractal->splits[iterations]-1-i], cx, cy, 
                       newsize, 
                       current.height/fractal->splits[iterations], newangle);
        draw_sdl(window, fractal, cx, cy, 
                     newsize, 
                     newangle, iterations);
    }

    for(int i=0; i<fractal->splits[iterations]/2; i++) {
        newangle = angle - (fractal->anglerange/2.0) + 
                       i*(fractal->anglerange/fractal->splits[iterations]);
        treeiterate(fractal, window, shapes[i], 
                        iterations, limit, newangle, 
                        bx + (sin(newangle)*2*newsize), 
                        by - (cos(newangle)*2*newsize));

        newangle = angle + (fractal->anglerange/2.0) - 
                       i*(fractal->anglerange/fractal->splits[iterations]);
        treeiterate(fractal, window, shapes[fractal->splits[iterations]-1-i], 
                        iterations, limit, newangle, 
                        bx + (sin(newangle)*2*newsize), 
                        by - (cos(newangle)*2*newsize));
    }
    free(shapes);
    return;
}
Пример #3
0
void stariterate(Draw *fractal, SDL_Win *window, Shape current, 
                     int iterations, int limit, float angle) {
    draw_sdl(window, fractal, current.x, current.y, 
                 current.size, angle, iterations);

    if(current.size < 1 || iterations == limit) {
        return;
    }

    int x, y; 
    float newangle;
    Shape *shapes = malloc(fractal->splits[iterations]*sizeof(Shape)); 

    iterations++;

    for(int i=0; i<fractal->splits[iterations]; i++) {
        newangle = ((i*2.0*M_PI)/fractal->splits[iterations]) + fractal->angle;
        x = current.x + (current.size*sin(newangle)/sqrt(2));
        y = current.y - (current.size*cos(newangle)/sqrt(2));
        make_shape(&shapes[i], x, y, current.size/fractal->splits[iterations], 
                       current.height/fractal->splits[iterations], newangle);
        stariterate(fractal, window, shapes[i], iterations, limit, newangle);
    }
    free(shapes);
}
Пример #4
0
void OpenSpace::initialize()
{

	maxProgress(200);
	setAllEdges(false);
	world().SetGravity(b2Vec2(0, 10));

	upper = makePlatform(10, -25);
	addProgress(25);
	middle = makePlatform(50, -25);
	addProgress(25);
	
	auto pd = physicsDimensions();

	for(int i = 0; i < 150; ++i)
	{
		polygonDef def;
		def.bodyDef.position.Set(randuniform(pd.x, pd.x + 30), randuniform(-30, pd.y-30));
		def.bodyDef.angle = to_radians(randuniform(0, 360));
		def.bodyDef.type = b2_dynamicBody;
		def.shape.SetAsBox(1, 5);
		def.fixtureDef.restitution = 0.5;
		def.fixtureDef.density = 4;
		bodies.push_back(make_shape(world(), def));
		addProgress(1);
	}
}
Пример #5
0
void tree(Draw *fractal, SDL_Win *window, int limit) {
    Shape trunk;
    make_shape(&trunk, 
                 fractal->startx + ((fractal->size[0]/4)*sin(fractal->angle)), 
                 fractal->starty - ((fractal->size[0]/4)*cos(fractal->angle)), 
                     fractal->size[0]/2, fractal->height[0]/2, fractal->angle);
    Shape current = trunk;

    int iterations = 1;
    for(int i=0; i<10; i++) {
        fractal->splits[i] = 2;
    }

    fractal->anglerange = 1;
  
    draw_sdl(window, fractal, current.x, current.y, 
                 current.size/fractal->splits[0], fractal->angle, iterations);

    int bx= current.x + ((current.size*sin(fractal->angle))/fractal->splits[0]);
    int by= current.y - ((current.size*cos(fractal->angle))/fractal->splits[0]);

    treeiterate(fractal, window, current, iterations, limit, 
                  fractal->angle, bx, by);
    SDL_RenderPresent(window->renderer);
    SDL_UpdateWindowSurface(window->win);
}
Пример #6
0
auto inverse(const tensor_base<ET, tensor_shape<ST, MT, NT>, T> &A,
             bool *succeed = nullptr) {
  assert(A.cols() == A.rows());
  blas_int n = (blas_int)A.rows();
  assert(n > 0);
  blas_int lda = n;
  auto Adata = A.t().eval();

  std::vector<blas_int> ipiv(n);
  blas_int info = 0;

  // lu factorization
  lapack::getrf(&n, &n, Adata.ptr(), &lda, ipiv.data(), &info);
  if (succeed) {
    *succeed = info == 0;
  }

  if (info == 0) {
    blas_int lwork = n;
    vecx_<ET> work(make_shape(lwork));

    // inverse
    lapack::getri(&n, Adata.ptr(), &lda, ipiv.data(), work.ptr(), &lwork,
                  &info);
    if (succeed) {
      *succeed = info == 0;
    }
  }

  return std::move(Adata).t();
}
Пример #7
0
void Flat::initialize()
{
	const int num_things = 75;

	maxProgress(num_things * 3);

	for(int i = 0; i < num_things; ++i)
	{
		polygonDef def;
		def.bodyDef.position.Set(randuniform(50, 100), randuniform(0, 80));
		def.bodyDef.angle = 0;
		def.bodyDef.fixedRotation = true;
		def.bodyDef.type = b2_dynamicBody;
		def.shape.SetAsBox(1*1.2, 5*1.2);
		def.fixtureDef.density = 1;
		(make_shape(back1, def));
		addProgress(1);
	}
	for(int i = 0; i < num_things; ++i)
	{
		polygonDef def;
		def.bodyDef.position.Set(randuniform(50, 100), randuniform(0, 80));
		def.bodyDef.angle = to_radians(randuniform(0, 360));
		def.bodyDef.type = b2_dynamicBody;
		def.shape.SetAsBox(1, 5);
		def.fixtureDef.density = 1;
		(make_shape(back2, def));
		addProgress(1);
	}
	for(int i = 0; i < num_things; ++i)
	{
		polygonDef def;
		def.bodyDef.position.Set(randuniform(50, 100), randuniform(0, 80));
		def.bodyDef.angle = 0;
		def.bodyDef.fixedRotation = true;
		def.bodyDef.type = b2_dynamicBody;
		def.shape.SetAsBox(1*0.8, 5*0.8);
		def.fixtureDef.density = 1;
		(make_shape(back3, def));
		addProgress(1);
	}
}
Пример #8
0
void sierpinski(Draw *fractal, SDL_Win *window, int limit) {
    Shape shape;
    make_shape(&shape, fractal->startx, fractal->starty, fractal->size[0],
                   fractal->height[0], fractal->angle);

    int iterations = 1; //One iteration is just the shape.

    sierpinskiiterate(fractal, window, shape, iterations, limit);
    SDL_RenderPresent(window->renderer);
    SDL_UpdateWindowSurface(window->win);
}
Пример #9
0
b2Body* OpenSpace::makePlatform(float ycenter, float angle)
{
	auto pd = physicsDimensions();
	polygonDef def;
	def.bodyDef.position.Set(pd.x, ycenter);
	def.bodyDef.type = b2_staticBody;
	def.bodyDef.angle = to_radians(angle);
	def.bodyDef.fixedRotation = true;
	def.shape.SetAsBox(pd.x-40, 2);
	def.fixtureDef.density = 1;
	def.fixtureDef.friction = 0.4;
	return make_shape(world(), def);
}
Пример #10
0
// Generic Fourier test function for different ranks
template <int TARGET_RANK> void test_fourier(statistic_enum statistic) {
  double precision = 1e-8;
  triqs::clef::placeholder<0> iw_;
  double beta = 10;
  int N_iw    = 1000;
  int N_tau   = 10000;
  double E    = -1;

  mini_vector<size_t, TARGET_RANK> shape{};

  if constexpr (TARGET_RANK == 2) // Matrix_valued
    shape = make_shape(2, 2);
  else if constexpr (TARGET_RANK == 3) // Tensor_valued<3>
Пример #11
0
auto solve(const tensor_base<ET, tensor_shape<ST1, MT1, NT1>, T1> &A,
           const tensor_base<ET, tensor_shape<ST2, MT2, NT2>, T2> &B,
           bool *succeed = nullptr) {
  char trans = 'N'; // 'T' if is transposed
  blas_int m = (blas_int)A.rows();
  blas_int n = (blas_int)A.cols();
  assert(m > 0 && n > 0);
  blas_int lda = m;
  // Adata: lda x n
  auto Adata = A.t().eval();

  assert(m == B.rows());
  blas_int nrhs = (blas_int)B.cols();
  blas_int ldb = max(1, m, n);
  // Bdata: ldb x nrhs
  tensor<ET, tensor_shape<size_t, size_t, size_t>> Bdata;
  if (ldb == m) {
    Bdata = B.t();
  } else {
    Bdata =
        cat_at(const_index<0>(), B.derived(), zeros(make_shape(ldb - m, nrhs)))
            .t();
  }

  // work
  blas_int lwork = max(1, min(m, n) + max(min(m, n), nrhs) * 1);
  vecx_<ET> work(make_shape(lwork));

  blas_int info = 0;
  lapack::gels(&trans, &m, &n, &nrhs, Adata.ptr(), &lda, Bdata.ptr(), &ldb,
               work.ptr(), &lwork, &info);
  if (succeed) {
    *succeed = info == 0;
  }

  return std::move(Bdata).t().block(iota(n), iota(tags::length));
}
Пример #12
0
void TreeSystem::make_ground(
	float thickness,
	float base_angle,
	float delta_angle,
	const sf::Color& base_color,
	const ColorTransform& deltas)
{
	const float density_factor = 1.5;
	const float block_w = 5;
	const float block_h = 1;
	const float block_area = block_w * block_h;
	const float underground_depth = 5;

	auto phys = physicsDimensions();
	auto phys2 = physicsHalfDimensions();
	const float area = (thickness + underground_depth) * phys.x;
	const unsigned density = (area * density_factor) / block_area;

	blocks.reserve(blocks.size() + density + 1);

	polygonDef def;
	def.bodyDef.active = false;
	def.bodyDef.fixedRotation = true;
	def.bodyDef.type = b2_staticBody;
	def.shape.SetAsBox(phys2.x, thickness/2);
	def.bodyDef.angle = 0;
	def.bodyDef.position.Set(phys2.x, phys.y - (thickness/2));

	blocks.emplace_back(
		make_shape(world(), def),
		base_color);
	
	def.shape.SetAsBox(block_w, block_h);
	addProgress(1);

	const b2Vec2 topLeft(0, phys.y - thickness);
	const b2Vec2 bottomRight(phys.x, phys.y + underground_depth);

	maxProgress(blocks.size() + density + 1);
	setProgress(blocks.size());

	for(int i = 0; i < density; ++i)
	{
		def.bodyDef.position = random_in(topLeft, bottomRight);
		def.bodyDef.angle = to_radians(randcentered(base_angle, delta_angle));
		add_block(def, deltas.apply(base_color));
		addProgress(1);
	}
}
Пример #13
0
TEST(Array, Create) {

  array<long, 2> A;
  A.resize(make_shape(3, 3));
  EXPECT_EQ(A.shape(), (mini_vector<size_t, 2>{3, 3}));

  matrix<double> M;
  M.resize(3, 3);

  EXPECT_EQ(M.shape(), (mini_vector<size_t, 2>{3, 3}));

  vector<double> V;
  V.resize(10);

  EXPECT_EQ(V.shape(), (mini_vector<size_t, 1>{10}));
}
Пример #14
0
void star(Draw *fractal, SDL_Win *window, int limit) {
    Shape centre;
    make_shape(&centre, fractal->startx, fractal->starty, 
                   fractal->size[0]/2, fractal->height[0]/2, fractal->angle);

    int iterations = 1;

    for(int i=0; i<10; i++) {
        fractal->splits[i] = 6;
    }

    stariterate(fractal, window, centre, iterations, limit, fractal->angle);
  
    SDL_RenderPresent(window->renderer);
    SDL_UpdateWindowSurface(window->win);
}
Пример #15
0
verdict test_randomized()
{
#if !defined(NO_RANDOMIZATION)
    srand (unsigned(get_time_stamp()/get_frequency())); // Randomize pseudo random number generator
#endif
    std::cout << "=================== Randomized Test ===================" << std::endl;

    size_t a1 = 0, a2 = 0;
    std::vector<long long> mediansV(K); // Final verdict of medians for each of the K experiments with visitors
    std::vector<long long> mediansM(K); // Final verdict of medians for each of the K experiments with matching
    std::vector<long long> timingsV(M);
    std::vector<long long> timingsM(M);
    std::vector<Shape*>    shapes(N);

    for (size_t k = 0; k < K; ++k)
    {
        for (size_t i = 0; i < N; ++i)
            shapes[i] = make_shape(rand());

        run_timings(shapes, timingsV, timingsM, a1, a2);
        mediansV[k] = display("AreaVisRnd", timingsV);
        mediansM[k] = display("AreaMatRnd", timingsM);
        std::cout << "\t\t" << verdict(mediansV[k], mediansM[k]) << std::endl;

        for (size_t i = 0; i < N; ++i)
        {
            delete shapes[i];
            shapes[i] = 0;
        }
    }

    if (a1 != a2)
    {
        std::cout << "ERROR: Invariant " << a1 << "==" << a2 << " doesn't hold." << std::endl;
        exit(42);
    }

    std::sort(mediansV.begin(), mediansV.end());
    std::sort(mediansM.begin(), mediansM.end());
    return verdict(mediansV[K/2],mediansM[K/2]);
}
Пример #16
0
verdict test_repetitive()
{
    std::cout << "=================== Repetitive Test ===================" << std::endl;

    size_t a1 = 0, a2 = 0;
    std::vector<long long> mediansV(K); // Final verdict of medians for each of the K experiments with visitors
    std::vector<long long> mediansM(K); // Final verdict of medians for each of the K experiments with matching
    std::vector<long long> timingsV(M);
    std::vector<long long> timingsM(M);
    std::vector<Shape*>    shapes(N);

    for (size_t k = 0; k < K; ++k)
    {
        for (size_t i = 0; i < N; ++i)
            shapes[i] = make_shape((k+i)*2-k-2*i);

        run_timings(shapes, timingsV, timingsM, a1, a2);
        mediansV[k] = display("AreaVisRep", timingsV);
        mediansM[k] = display("AreaMatRep", timingsM);
        std::cout << "\t\t" << verdict(mediansV[k], mediansM[k]) << std::endl;

        for (size_t i = 0; i < N; ++i)
        {
            delete shapes[i];
            shapes[i] = 0;
        }
    }

    if (a1 != a2)
    {
        std::cout << "ERROR: Invariant " << a1 << "==" << a2 << " doesn't hold." << std::endl;
        exit(42);
    }

    std::sort(mediansV.begin(), mediansV.end());
    std::sort(mediansM.begin(), mediansM.end());
    return verdict(mediansV[K/2],mediansM[K/2]);
}
Пример #17
0
template <class... Ts, class... TTs> constexpr auto _cart_prod(TTs &&... tts) {
    using shape_t = decltype(make_shape(tts.numel()...));
    return cart_prod_result<
           std::tuple<typename _get_value_type_helper<TTs>::type...>, shape_t,
           TTs...>(std::forward<TTs>(tts)...);
}
Пример #18
0
constexpr decltype(auto)
_shape_of_cart_prod_result_seq(CartProdT &cp,
                               const const_ints<size_t, Is...> &) {
    return make_shape(std::get<Is>(cp.inputs).numel()...);
}
Пример #19
0
// Generic Fourier test function for different ranks
template <int TARGET_RANK> void test_fourier(statistic_enum statistic) {
  double precision = 1e-8;
  triqs::clef::placeholder<0> iw_;
  double beta = 10;
  int N_iw    = 1000;
  int N_tau   = 10000;
  double E    = -1;

  mini_vector<size_t, TARGET_RANK> shape{};

  if constexpr (TARGET_RANK == 2) // Matrix_valued
    shape = make_shape(2, 2);
  else if constexpr (TARGET_RANK == 3) // Tensor_valued<3>
    shape = make_shape(2, 2, 2);
  else if constexpr (TARGET_RANK == 4) // Tensor_valued<4>
    shape = make_shape(2, 2, 2, 2);

  using target_t = typename _target_from_type_rank<dcomplex, TARGET_RANK>::type;

  // === Test a Green function with a Single Pole ===

  auto Gw1 = gf<imfreq, target_t>{{beta, statistic, N_iw}, shape};
  Gw1(iw_) << 1 / (iw_ - E) + 1 / (iw_ + 2 * E) - 4.5 / (iw_ - 1.25 * E);

  auto Gt1 = gf<imtime, target_t>{{beta, statistic, N_tau}, shape};
  Gt1()    = fourier(Gw1);

  ///verification that TF(TF^-1)=Id
  auto Gw1b = gf<imfreq, target_t>{{beta, statistic, N_iw}, shape};
Пример #20
0
int
main(int argc, char *argv[])
{
    int opt;
    size_t i;
    const char *argv0 = argv[0];
    struct rt_wdb *fd_out;
    struct bu_vls vls_in = BU_VLS_INIT_ZERO;
    struct bu_vls vls_out = BU_VLS_INIT_ZERO;

    int opt_debug = 0;
    int opt_verbose = 0;

    /* shapelib vars */
    SHPHandle shapefile;
    size_t shp_num_invalid = 0;
    int shp_num_entities = 0;
    int shp_type = 0;

    /* intentionally double for scan */
    double shp_min[4] = HINIT_ZERO;
    double shp_max[4] = HINIT_ZERO;

    /* geometry */
    point2d_t *verts = NULL;
    size_t num_verts = 0;

    if (argc < 2) {
	usage(argv0);
	bu_exit(1, NULL);
    }

    while ((opt = bu_getopt(argc, argv, "dxv")) != -1) {
	switch (opt) {
	    case 'd':
		opt_debug = 1;
		break;
	    case 'x':
		sscanf(bu_optarg, "%x", (unsigned int *) &RTG.debug);
		bu_printb("librt RT_G_DEBUG", RT_G_DEBUG, DEBUG_FORMAT);
		bu_log("\n");
		break;
	    case 'v':
		opt_verbose++;
		break;
	    default:
		usage(argv0);
		bu_exit(1, NULL);
		break;
	}
    }
    argv += bu_optind;
    argc -= bu_optind;

    if (opt_verbose)
	bu_log("Verbose output enabled.\n");

    if (opt_debug)
	bu_log("Debugging output enabled.\n");

    /* validate input/output file specifiers */
    if (argc < 1) {
	usage(argv0);
	bu_exit(1, "ERROR: Missing input and output file names\n");
    }

    bu_vls_strcat(&vls_in, argv[0]);

    if (argc < 2) {
	bu_vls_printf(&vls_out, "%s.g", argv[0]);
    } else {
	bu_vls_strcat(&vls_out, argv[1]);
    }

    if (opt_verbose) {
	bu_log("Reading from [%s]\n", bu_vls_addr(&vls_in));
	bu_log("Writing to [%s]\n\n", bu_vls_addr(&vls_out));
    }

    /* initialize single threaded resource */
    rt_init_resource(&rt_uniresource, 0, NULL);

    /* open the input */
    shapefile = SHPOpen(bu_vls_addr(&vls_in), "rb");
    if (!shapefile) {
	bu_log("ERROR: Unable to open shapefile [%s]\n", bu_vls_addr(&vls_in));
	bu_vls_free(&vls_in);
	bu_vls_free(&vls_out);
	bu_exit(4, NULL);    }

    /* print shapefile details */
    if (opt_verbose) {
	SHPGetInfo(shapefile, &shp_num_entities, &shp_type, shp_min, shp_max);

	bu_log("Shapefile Type: %s\n", SHPTypeName(shp_type));
	bu_log("# of Shapes: %d\n\n", shp_num_entities);
	bu_log("File Bounds: (%12.3f,%12.3f, %.3g, %.3g)\n"
	       "         to  (%12.3f,%12.3f, %.3g, %.3g)\n",
	       shp_min[0], shp_min[1], shp_min[2], shp_min[3],
	       shp_max[0], shp_max[1], shp_max[2], shp_max[3]);
    }

    /* open the .g for writing */
    if ((fd_out = wdb_fopen(bu_vls_addr(&vls_out))) == NULL) {
	bu_log("ERROR: Unable to open shapefile [%s]\n", bu_vls_addr(&vls_out));
	bu_vls_free(&vls_in);
	bu_vls_free(&vls_out);
	perror(argv0);
	bu_exit(5, NULL);
    }

    /* iterate over all entities */
    for (i=0; i < (size_t)shp_num_entities; i++) {
	SHPObject *object;
	int shp_part;
	size_t j;

	object = SHPReadObject(shapefile, i);
	if (!object) {
	    if (opt_debug)
		bu_log("Shape %zu of %zu is missing, skipping.\n", i+1, (size_t)shp_num_entities);
	    continue;
	}

	/* validate the object */
	if (opt_debug) {
	    int shp_altered = SHPRewindObject(shapefile, object);
	    if (shp_altered > 0) {
		bu_log("WARNING: Shape %zu of %zu has [%d] bad loop orientations.\n", i+1, (size_t)shp_num_entities, shp_altered);
		shp_num_invalid++;
	    }
	}

	/* print detail header */
	if (opt_verbose) {
	    if (object->bMeasureIsUsed) {
		bu_log("\nShape:%zu (%s)  nVertices=%d, nParts=%d\n"
		       "  Bounds:(%12.3f,%12.3f, %g, %g)\n"
		       "      to (%12.3f,%12.3f, %g, %g)\n",
		       i+1, SHPTypeName(object->nSHPType), object->nVertices, object->nParts,
		       object->dfXMin, object->dfYMin, object->dfZMin, object->dfMMin,
		       object->dfXMax, object->dfYMax, object->dfZMax, object->dfMMax);
	    } else {
		bu_log("\nShape:%zu (%s)  nVertices=%d, nParts=%d\n"
		       "  Bounds:(%12.3f,%12.3f, %g)\n"
		       "      to (%12.3f,%12.3f, %g)\n",
		       i+1, SHPTypeName(object->nSHPType), object->nVertices, object->nParts,
		       object->dfXMin, object->dfYMin, object->dfZMin,
		       object->dfXMax, object->dfYMax, object->dfZMax);
	    }

	    if (object->nParts > 0 && object->panPartStart[0] != 0) {
		if (opt_debug)
		    bu_log("Shape %zu of %zu: panPartStart[0] = %d, not zero as expected.\n", i+1, (size_t)shp_num_entities, object->panPartStart[0]);
		continue;
	    }
	}

	num_verts = 0;
	verts = (point2d_t *)bu_calloc((size_t)object->nVertices, sizeof(point2d_t), "alloc point array");

	for (j = 0, shp_part = 1; j < (size_t)object->nVertices; j++) {
	    if (shp_part < object->nParts
		&& j == (size_t)object->panPartStart[shp_part]) {
		shp_part++;
		bu_log("Shape %zu of %zu: End of Loop\n", i+1, (size_t)shp_num_entities);
		make_shape(fd_out, opt_verbose, opt_debug, i, num_verts, verts);

		/* reset for next loop */
		memset(verts, 0, sizeof(point2d_t) * object->nVertices);
		num_verts = 0;
	    }
	    bu_log("%zu/%zu:%zu/%zu\t\t", i+1, (size_t)shp_num_entities, j+1, (size_t)object->nVertices);
	    bu_log("(%12.4f, %12.4f, %12.4f, %g)\n", object->padfX[j], object->padfY[j], object->padfZ[j], object->padfM[j]);

	    V2SET(verts[num_verts], object->padfX[j], object->padfY[j]);
	    num_verts++;
	}
	bu_log("Shape %zu of %zu: End of Loop\n", i+1, (size_t)shp_num_entities);
	make_shape(fd_out, opt_verbose, opt_debug, i, num_verts, verts);

	bu_free(verts, "free point array");
	verts = NULL;
	num_verts = 0;

	SHPDestroyObject(object);
	object = NULL;
    }

    if (opt_verbose) {
	if (shp_num_invalid > 0) {
	    bu_log("WARNING: %zu of %zu shape(s) had bad loop orientations.\n", shp_num_invalid, (size_t)shp_num_entities);
	}
	bu_log("\nDone.\n");
    }

    /* close up our files */
    SHPClose(shapefile);
    wdb_close(fd_out);

    /* free up allocated resources */
    bu_vls_free(&vls_in);
    bu_vls_free(&vls_out);

    return 0;
}
Пример #21
0
 array_view<V, sizeof...(I), Opt> reinterpret (array<V,R,Opt,To> const & a, I ... index) { 
  return { {make_shape(index...)}, a.storage() };
 }
Пример #22
0
int
main(int argc, char** argv)
{
  
  SWFMovie mo;
  SWFMovieClip dejagnuclip;
  SWFMorph morph;
  SWFShape startShape, endShape;
  SWFDisplayItem it;
  float ratio;


  const char *srcdir=".";
  if ( argc>1 ) 
    srcdir=argv[1];
  else
  {
      fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
      return 1;
  }

  Ming_init();
  mo = newSWFMovieWithVersion(OUTPUT_VERSION);
  SWFMovie_setDimension(mo, 800, 600);
  SWFMovie_setRate (mo, 1.0);

  // _root.frame1
  dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
  SWFMovie_add(mo, (SWFBlock)dejagnuclip);
  SWFMovie_nextFrame(mo); 

  // _root.frame2, define and place a morph
  morph =  newSWFMorphShape();
  startShape = SWFMorph_getShape1(morph);
  make_shape(startShape, 0, 0, 100, 100, 255, 0 ,0);
  endShape = SWFMorph_getShape2(morph);
  make_shape(endShape, 700, 500, 100, 100, 0, 255 ,0);

  it = SWFMovie_add(mo, (SWFBlock)morph); 
  SWFMovie_nextFrame(mo); 
  
  // update the morph with different ratios
  for(ratio=0.2; ratio<1.01; ratio+=0.2)
  {
     SWFDisplayItem_remove(it);
     it = SWFMovie_add(mo, (SWFBlock)morph);
     SWFDisplayItem_setRatio(it, ratio);
     SWFMovie_nextFrame(mo);     
  }

  /* Test for #39989 by adding an empty morph shape. */
  morph = newSWFMorphShape();
  startShape = SWFMorph_getShape1(morph);
  endShape = SWFMorph_getShape2(morph);
  it = SWFMovie_add(mo, (SWFBlock)morph);
  SWFMovie_nextFrame(mo);
  
  //Output movie
  puts("Saving " OUTPUT_FILENAME );
  SWFMovie_save(mo, OUTPUT_FILENAME);

  return 0;
}
Пример #23
0
 std::conditional_t<A::is_const, array_const_view<typename A::value_type, A::rank + 2>, array_view<typename A::value_type, A::rank + 2>>
 reinterpret_array_add_1x1(A const &d) {
   auto &imap = d.indexmap();
   typename array_view<typename A::value_type, A::rank + 2>::indexmap_type index_map(join(imap.lengths(), make_shape(1, 1)),
                                                                                     join(imap.strides(), make_shape(1, 1)), imap.start_shift());
   return {index_map, d.storage()};
 };
Пример #24
0
//------------------------------------------------------------------------------
// Name: GraphNode
// Desc:
//------------------------------------------------------------------------------
GraphNode::GraphNode(const GraphWidget *graph, node_t *node) : QGraphicsPathItem(make_shape(node)), name(QString::fromUtf8(agnameof(node))), graph_(graph) {

	draw_label(ND_label(node));
}
Пример #25
0
 array_view<V, sizeof...(I), Opt,indexmaps::mem_layout::c_order(sizeof...(I))> reinterpret_array_view (array_view<V,R,Opt,To,B> const & a, I ... index) { 
  if (!has_contiguous_data(a)) TRIQS_RUNTIME_ERROR << "reinterpretation failure : data of the view are not contiguous";
  return { {make_shape(index...)}, a.storage() };
 }
Пример #26
0
 tail_impl(int N1, int N2, int size_, int order_min)
    : omin(order_min), _mask(arrays::make_shape(N1, N2)), _data(make_shape(size_, N1, N2)) {
  _mask() = order_min + size_ - 1;
  _data() = 0;
 }