// comments relate to Sugihara-Iri paper // this is roughly "algorithm A" from the paper, page 15/50 void VoronoiDiagram::addVertexSite(const Point& p) { // only add vertices within the far_radius circle assert( p.xyNorm() < far_radius ); // 1) find the closest face and associated generator gen_count++; HEFace closest_face = fgrid->grid_find_closest_face( p ); // 2) among the vertices on the closest_face // find the seed, which has the lowest detH HEVertex v_seed = findSeedVertex(closest_face, p); g[v_seed].type = IN; VertexVector v0; v0.push_back(v_seed); // 3) augment the vertex set to be deleted // vertex set must remain a tree // must not delete cycles augment_vertex_set_M(v0, p); // 4) add new vertices on all edges that connect v0 IN edges to OUT edges add_new_voronoi_vertices(v0, p); // 5) generate new edges that form a loop around the region to be deleted HEFace newface = split_faces(p); // 6) fix the next-pointers in newface, then remove set v0 remove_vertex_set(v0, newface); // 7) reset IN/OUT/UNDECIDED for verts, and INCIDENT/NONINCIDENT for faces reset_labels(); assert( vdChecker.isValid(this) ); }
void Button_window::action(Button& b) { reset_labels(); b.label = "CLICKED"; ostringstream os; os << '(' << b.loc.x << ',' << b.loc.y << ')'; xy_out.put(os.str()); }
static void add_score() { // Increment and display score state.score++; static char buf[32]; snprintf(buf, 32, "Score: %u", state.score); text_layer_set_text(score_label, buf); if ((state.score % 50) == 0) { state.timeInterval = INITIAL_TIME - state.score; } reset_labels(); }
sensor_panel::sensor_panel(QWidget *parent) : rviz::Panel(parent) // Base class constructor { // Init all variables ros::NodeHandle nh; QVBoxLayout *layout = new QVBoxLayout(); // layouts hold widgets // all labels for displaying data labels["IMU"] = new QLabel("IMU: Disabled\n"); labels["Lidar"] = new QLabel("Lidar: Disabled\n"); labels["Center Camera"] = new QLabel("Center Camera: Disabled\n"); labels["GPS"] = new QLabel("GPS: Disabled\n"); /* *Makes timer that repeats every interval seconds *When timer goes off, it calls the timer method */ sensor_timer = new QTimer(); sensor_timer->setSingleShot(false); // will repeat sensor_timer->setInterval(INTERVAL); // goes off every 250 milliseconds // calls reset_labels whenever sensor_timer goes off QObject::connect(sensor_timer, SIGNAL(timeout()), this, SLOT(reset_labels())); /* Initialize subscribers to listen to topic corresponding with each sensor. * use boost::bind to update labels with each call. */ imu_sub = nh.subscribe<sensor_msgs::Imu>("/imu", 1, boost::bind(&sensor_panel::imu_callback, this, _1, labels["IMU"])); lidar_sub = nh.subscribe<sensor_msgs::PointCloud2>( "/scan/pointcloud", 1, boost::bind(&sensor_panel::lidar_callback, this, _1, labels["Lidar"])); cam_center_sub = nh.subscribe<sensor_msgs::Image>( "/usb_cam_center/image_raw", 1, boost::bind(&sensor_panel::cam_center_callback, this, _1, labels["Center Camera"])); gps_sub = nh.subscribe<sensor_msgs::NavSatFix>("/fix", 1, boost::bind(&sensor_panel::gps_callback, this, _1, labels["GPS"])); // adds all the widgets to the layout for (std::pair<std::string, QLabel *> pear : labels) { pear.second->setStyleSheet(red); layout->addWidget(pear.second); } setLayout(layout); sensor_timer->start(); }
int handle_ffidef(const char *buf) { int parsed_funnum; unsigned char types[MAX_NUM_FFI_PARAMETERS]; int i = 0, j = 0; long int val; const char *numptr = buf; memset(types, 0x00, sizeof(types)); char *endptr; parsed_funnum = strtol(numptr, &endptr, 0); if(endptr == numptr || !parsed_funnum) return 0; numptr++; do { val = strtol(numptr, &endptr, 0); if(endptr == numptr) return 0; types[i] = val; numptr = endptr + 1; i++; } while(i < sizeof(types) - 1 && (!i || val != 0)); output_nums(OPCODE_FFIDEF, parsed_funnum, types[0]); for(j = 1; j < i; j += 4) { output_char(types[j]); if(j + 1 < i) output_char(types[j + 1]); else output_char(0); if(j + 2 < i) output_char(types[j + 2]); else output_char(0); if(j + 3 < i) output_char(types[j + 3]); else output_char(0); } output_until_space(numptr, 0); sync_output(); reset_labels(); return 1; }
static void select_click_handler(ClickRecognizerRef recognizer, void *context) { if (!state.isRunning) { state.score = 0; reset_labels(); layer_set_hidden((Layer*) high_score_label, true); layer_add_child(window_get_root_layer(window), text_layer_get_layer(high_score_label)); state.timeInterval = 1000; state.isRunning = true; state.buttonPushed = true; state.direction = 0; state.timer = app_timer_register(state.timeInterval, timer_callback, NULL); static char buf[32]; snprintf(buf, 32, "Score: %u", state.score); text_layer_set_text(score_label, buf); } }
static void timer_callback() { if (state.buttonPushed) { state.buttonPushed = false; // Seed the random number with a time srand(time(NULL)); // Get a number between 1 and 2 state.direction = (rand() % 2) + 1; static char buf[32]; snprintf(buf, 32, "Time interval: %u", state.timeInterval); text_layer_set_text(text_layer, buf); // Set the correct label based on random number if (state.direction == 1) { layer_set_hidden((Layer*) up_label, false); layer_set_hidden((Layer*) up_image_layer, false); } else { layer_set_hidden((Layer*) down_label, false); layer_set_hidden((Layer*) down_image_layer, false); } state.timeInterval -= 10; app_timer_register(state.timeInterval, timer_callback, NULL); } else { text_layer_set_text(text_layer, "Game over. Try again."); reset_labels(); state.direction = 0; state.isRunning = false; set_score(); } }
void jvmcodegen::gen_function_decl(const ast::node_ptr &node) { auto func = ast::to_function_decl(node); auto curr_scope = m_stack.top(); auto& sym = curr_scope->get(func->name); if (!sym.is_valid()) { throw jvmcodegen_error(fmt::sprintf("%s simbolo nao encontrado!", func->name)); } // empilha o escopo da função m_stack.push(m_symtable->get_scope(sym.scope_id)); reset_locals(); reset_labels(); m_out << fmt::sprintf(".method public static "); std::stringstream ss; if (func->is_main()) { m_out << fmt::sprintf("main([Ljava/lang/String;)V\n"); } else { ss << fmt::sprintf("%s(", func->name); for (size_t i = 0; i < func->arguments.size(); i++) { auto arg = ast::to_argument(func->arguments[i]); auto& asym = m_stack.top()->get(arg->name); ss << fmt::sprintf("%s", jvm_type(asym.c_type())); if (i != func->arguments.size() - 1) ss << m_out << fmt::sprintf(","); } ss << fmt::sprintf(")%s", jvm_type(sym.type & ~types::function)); // salva a assinatura para realizar chamadas.. sym.signature = ss.str(); m_out << fmt::sprintf(ss.str()); m_out << fmt::sprintf("\n"); } int locals = compute_locals(node); if (func->is_main()) locals += 1; m_out << fmt::sprintf(".limit locals %d\n", locals); m_out << fmt::sprintf(".limit stack 15\n"); for (const auto& arg : func->arguments) { gen_node(arg); } for (const auto& stmt : func->statements) { gen_node(stmt); } m_stack.pop(); if (!func->is_main()) { if (sym.c_type() == types::integer) { m_out << fmt::sprintf("ireturn\n"); } else if (sym.c_type() == types::voidt) { m_out << fmt::sprintf("return\n"); } else if (sym.c_type() == types::string) { m_out << fmt::sprintf("areturn\n"); } } else { m_out << fmt::sprintf("return\n"); } m_out << fmt::sprintf(".end method\n\n"); }
int main(int argc, char **argv) { char buf[1024]; int fundef = 0; interactive = argc > 1 && !strncmp(argv[1], "-i", 2); reset_labels(); if(!interactive) { int lib_index = 1; output_magic(); output_version(); for(lib_index = 1; lib_index < MAX_NUM_LIBS && lib_index < argc; lib_index++) { output_until_space(argv[lib_index], 1); output_header(' '); } output_header('\0'); } while(1) { int emptyline; if(interactive) { printf(">>> "); fflush(stdout); } emptyline = (fgets(buf, 1024, stdin) == NULL); if(!interactive && emptyline) break; if(buf[0] == ':') { if(buf[1] >= 'a' && buf[1] <= 'z') { labels[buf[1] - 'a'] = current_addr; } } else if(!strncmp(buf, "ADD", 3)) { output(OPCODE_ADD); } else if(!strncmp(buf, "SUB", 3)) { output(OPCODE_SUB); } else if(!strncmp(buf, "MUL", 3)) { output(OPCODE_MUL); } else if(!strncmp(buf, "DIV", 3)) { output(OPCODE_DIV); } else if(!strncmp(buf, "LT", 2)) { output(OPCODE_LT); } else if(!strncmp(buf, "LE", 2)) { output(OPCODE_LE); } else if(!strncmp(buf, "EQ", 2)) { output(OPCODE_EQ); } else if(!strncmp(buf, "DUP", 3)) { output(OPCODE_DUP); } else if(!strncmp(buf, "DROP", 4)) { output(OPCODE_DROP); } else if(!strncmp(buf, "NOP", 3)) { output(OPCODE_NOP); } else if(!strncmp(buf, "SWAP", 4)) { output(OPCODE_SWAP); } else if(!strncmp(buf, "NEW", 3)) { output(OPCODE_NEW); } else if(!strncmp(buf, "RSTORE", 6)) { output(OPCODE_RSTORE); } else if(!strncmp(buf, "RLOAD", 4)) { output(OPCODE_RLOAD); } else if(!strncmp(buf, "END_THUNK", 9)) { output(OPCODE_END_THUNK); } else if(output_offset(buf, "BR", OPCODE_BRANCH)); else if(output_offset(buf, "BRNZ", OPCODE_BRANCHNZ)); else if(output_offset(buf, "THUNK", OPCODE_START_THUNK)); else if(!strncmp(buf, "FUNCALL ", 8)) { int succ; long int parsed_num = getnum(buf + 8, &succ); if(!succ) fprintf(stderr, "?\n"); else { output_num(OPCODE_CALLFUN, parsed_num); } } else if(!strncmp(buf, "FUNPCALL", 8)) { output(OPCODE_CALLPFUN); } else if(!strncmp(buf, "FUNDEF ", 7)) { if(fundef) { fprintf(stderr, "?\n"); } else { int parsed_funnum, parsed_params; int succ = get_two_nums(buf + 7, &parsed_funnum, &parsed_params); if(!succ) fprintf(stderr, "?\n"); else { output_nums(OPCODE_DEFUN_START, parsed_params, parsed_funnum); fundef = 1; reset_labels(); } } } else if(!strncmp(buf, "FUNEND", 6)) { fundef = funend(OPCODE_DEFUN_END, fundef); } else if(!strncmp(buf, "RET0", 4)) { fundef = funend(OPCODE_RET0, fundef); } else if(!strncmp(buf, "RET1", 4)) { fundef = funend(OPCODE_RET1, fundef); } else if(!strncmp(buf, "LOAD ", 5)) { int succ; long int parsed_num = getnum(buf + 5, &succ); if(!succ) fprintf(stderr, "?\n"); else output_num(OPCODE_LOAD, parsed_num); } else if(!strncmp(buf, "FFIDEF ", 7)) { if(fundef) { fprintf(stderr, "?\n"); } else { int succ = handle_ffidef(buf + 7); if(!succ) { fprintf(stderr, "FFIDEF?\n"); } } } else if(buf[0] == 'f') { int succ; long int parsed_num = getnum(buf + 1, &succ); if(!succ) fprintf(stderr, "?\n"); else output_num(OPCODE_PFUN_ID, parsed_num); } else if(buf[0] == '-' || isdigit(buf[0])) { int succ; long int parsed_num = getnum(buf, &succ); if(!succ) fprintf(stderr, "?\n"); else output_num(OPCODE_INT, parsed_num); } else if(interactive && !strncmp(buf, "run", 3)) { parse_buffer(interactive_buffer, interactive_bufferpos); } else if(buf[0]) { fprintf(stderr, "?\n"); } } return 0; }