HRESULT WINAPI Container::GetBuf(LPAPPROXPOINT points, floattype step, int len, int *filled) { if(step < 0 || len <=0) { cerr << "step " << step << " len " << len << endl; cerr << "Invalid arg" << endl; return E_INVALIDARG; } floattype approx = 0.0; for(int i = 0; i < len || i < static_cast<int>(data.size()); approx+=step, i++) { points[i].x = data[round_double(approx)]->x; points[i].y = data[round_double(approx)]->y; (*filled)++; } if((*filled) < len){ cerr << "False, filled " << *filled << " datalen " << len << endl; return S_FALSE; } else return S_OK; }
double sanize_double(double a) { if (cmp_doubles(round_double(a), a)) { return round_double(a); } else { return a; } }
bool controller_base::handle_scroll(CKey& key, int mousex, int mousey, int mouse_flags, double x_axis, double y_axis) { bool mouse_in_window = (SDL_GetAppState() & SDL_APPMOUSEFOCUS) != 0 || preferences::get("scroll_when_mouse_outside", true); bool keyboard_focus = have_keyboard_focus(); int scroll_speed = preferences::scroll_speed(); int dx = 0, dy = 0; int scroll_threshold = (preferences::mouse_scroll_enabled()) ? preferences::mouse_scroll_threshold() : 0; BOOST_FOREACH(const theme::menu& m, get_display().get_theme().menus()) { if (point_in_rect(mousex, mousey, m.get_location())) { scroll_threshold = 0; } } if ((key[SDLK_UP] && keyboard_focus) || (mousey < scroll_threshold && mouse_in_window)) { dy -= scroll_speed; } if ((key[SDLK_DOWN] && keyboard_focus) || (mousey > get_display().h() - scroll_threshold && mouse_in_window)) { dy += scroll_speed; } if ((key[SDLK_LEFT] && keyboard_focus) || (mousex < scroll_threshold && mouse_in_window)) { dx -= scroll_speed; } if ((key[SDLK_RIGHT] && keyboard_focus) || (mousex > get_display().w() - scroll_threshold && mouse_in_window)) { dx += scroll_speed; } if ((mouse_flags & SDL_BUTTON_MMASK) != 0 && preferences::middle_click_scrolls()) { const SDL_Rect& rect = get_display().map_outside_area(); if (point_in_rect(mousex, mousey,rect)) { // relative distance from the center to the border // NOTE: the view is a rectangle, so can be more sensible in one direction // but seems intuitive to use and it's useful since you must // more often scroll in the direction where the view is shorter const double xdisp = ((1.0*mousex / rect.w) - 0.5); const double ydisp = ((1.0*mousey / rect.h) - 0.5); // 4.0 give twice the normal speed when mouse is at border (xdisp=0.5) int speed = 4 * scroll_speed; dx += round_double(xdisp * speed); dy += round_double(ydisp * speed); } } dx += round_double( x_axis * scroll_speed); dy += round_double( y_axis * scroll_speed); return get_display().scroll(dx, dy); }
void attack_context::attack_expected_damage(double attacker_inflict_, double defender_inflict_) { int attacker_inflict = round_double(attacker_inflict_ * stats::decimal_shift); int defender_inflict = round_double(defender_inflict_ * stats::decimal_shift); stats &att_stats = attacker_stats(), &def_stats = defender_stats(); att_stats.expected_damage_inflicted += attacker_inflict; att_stats.expected_damage_taken += defender_inflict; def_stats.expected_damage_inflicted += defender_inflict; def_stats.expected_damage_taken += attacker_inflict; att_stats.turn_expected_damage_inflicted += attacker_inflict; att_stats.turn_expected_damage_taken += defender_inflict; def_stats.turn_expected_damage_inflicted += defender_inflict; def_stats.turn_expected_damage_taken += attacker_inflict; }
static __not_inline int GoLGrid_or_filled_circle (GoLGrid *gg, double cent_x, double cent_y, double radius) { if (!gg || !gg->grid || radius < 0.0) return ffsc (__func__); s32 y_on = round_double (cent_y - radius); s32 y_off = 1 + round_double (cent_y + radius); s32 x_on = round_double (cent_x - radius); s32 x_off = 1 + round_double (cent_x + radius); int not_clipped = TRUE; s32 y; s32 x; for (y = y_on; y < y_off; y++) for (x = x_on; x < x_off; x++) if (((double) x - cent_x) * ((double) x - cent_x) + ((double) y - cent_y) * ((double) y - cent_y) < (radius * radius)) not_clipped &= GoLGrid_set_cell_on (gg, x, y); return not_clipped; }
extern int percent_up_fe_extract(struct fe_config_list *fe_list, double *feature_vector, int feature_vector_start_index, struct t_trace *trace){ double *list; int list_max; int i; struct generate_set_info info; info.total = 0; info.total_up = 0; info.total_down = 0; list = feature_vector + feature_vector_start_index; list_max = percent_up_fe_num(fe_list); for_each_t_pkt(trace, &generate_features_pkt, (void *)&info); list[0] = round_double(100.0 * (double)info.total_down/(double)info.total, 5.0); return EXIT_SUCCESS; }
extern int unique_down_fe_extract(struct fe_config_list *fe_list, double *feature_vector, int feature_vector_start_index, struct t_trace *trace){ double *list; int list_max; int i; struct countable_set *set = cs_init_set(); if(set == NULL){ return EXIT_FAILURE; } list = feature_vector + feature_vector_start_index; list_max = unique_down_fe_num(fe_list); for_each_t_pkt(trace, &generate_features_pkt, (void *)set); list[0] = round_double((double)set->num_elements, 2.0); cs_deinit_set(set); return EXIT_SUCCESS; }
static int generate_features(struct fe_config_list *fe_list, double *feature_vector, int max_features, struct t_trace *trace, struct countable_set *set){ struct generate_set_info info; int index; info.set = set; info.list = feature_vector; info.list_max = max_features; info.counterUP=0; info.counterDOWN=0; info.htmlMarker=0; for_each_t_pkt(trace, &generate_features_pkt, (void *)&info); info.htmlMarker = (int)round_double((double)info.htmlMarker, 600.0); index = cs_key_index(info.set, info.htmlMarker); if(index < 0 || index > info.list_max){ return EXIT_FAILURE; } info.list[index] = info.list[index] + 1.0; return EXIT_SUCCESS; }
bool controller_base::handle_scroll(CKey& key, int mousex, int mousey, int mouse_flags, double x_axis, double y_axis) { bool mouse_in_window = (SDL_GetAppState() & SDL_APPMOUSEFOCUS) != 0 || preferences::get("scroll_when_mouse_outside", true); bool keyboard_focus = have_keyboard_focus(); int scroll_speed = preferences::scroll_speed(); int dx = 0, dy = 0; int scroll_threshold = (preferences::mouse_scroll_enabled()) ? preferences::mouse_scroll_threshold() : 0; BOOST_FOREACH(const theme::menu& m, get_display().get_theme().menus()) { if (sdl::point_in_rect(mousex, mousey, m.get_location())) { scroll_threshold = 0; } } if ((key[SDLK_UP] && keyboard_focus) || (mousey < scroll_threshold && mouse_in_window)) { dy -= scroll_speed; } if ((key[SDLK_DOWN] && keyboard_focus) || (mousey > get_display().h() - scroll_threshold && mouse_in_window)) { dy += scroll_speed; } if ((key[SDLK_LEFT] && keyboard_focus) || (mousex < scroll_threshold && mouse_in_window)) { dx -= scroll_speed; } if ((key[SDLK_RIGHT] && keyboard_focus) || (mousex > get_display().w() - scroll_threshold && mouse_in_window)) { dx += scroll_speed; } if ((mouse_flags & SDL_BUTTON_MMASK) != 0 && preferences::middle_click_scrolls()) { const map_location original_loc = get_mouse_handler_base().get_scroll_start(); if (get_mouse_handler_base().scroll_started()) { const SDL_Rect& rect = get_display().map_outside_area(); if (sdl::point_in_rect(mousex, mousey,rect) && get_mouse_handler_base().scroll_started()) { // Scroll speed is proportional from the distance from the first // middle click and scrolling speed preference. const double speed = 0.04 * sqrt(static_cast<double>(scroll_speed)); const double snap_dist = 16; // Snap to horizontal/vertical scrolling const double x_diff = (mousex - original_loc.x); const double y_diff = (mousey - original_loc.y); if (fabs(x_diff) > snap_dist || fabs(y_diff) <= snap_dist) dx += speed * x_diff; if (fabs(y_diff) > snap_dist || fabs(x_diff) <= snap_dist) dy += speed * y_diff; } } else { // Event may fire mouse down out of order with respect to initial click get_mouse_handler_base().set_scroll_start(mousex, mousey); } } dx += round_double( x_axis * scroll_speed); dy += round_double( y_axis * scroll_speed); return get_display().scroll(dx, dy); }
bool controller_base::handle_scroll(CKey& key, int mousex, int mousey, int mouse_flags) { #if (defined(__APPLE__) && TARGET_OS_IPHONE) || defined(ANDROID) // for tablet device. bool mouse_in_window = false; #else // for mouse device. bool mouse_in_window = (SDL_GetAppState() & SDL_APPMOUSEFOCUS) != 0 || preferences::get("scroll_when_mouse_outside", true); #endif bool keyboard_focus = have_keyboard_focus(); int scroll_speed = preferences::scroll_speed(); int dx = 0, dy = 0; int scroll_threshold = (preferences::mouse_scroll_enabled()) ? preferences::mouse_scroll_threshold() : 0; foreach (const theme::menu& m, get_display().get_theme().menus()) { if (point_in_rect(mousex, mousey, m.get_location())) { scroll_threshold = 0; } } if ((key[SDLK_UP] && keyboard_focus) || (mousey < scroll_threshold && mouse_in_window)) { dy -= scroll_speed; } if ((key[SDLK_DOWN] && keyboard_focus) || (mousey > get_display().h() - scroll_threshold && mouse_in_window)) { dy += scroll_speed; } if ((key[SDLK_LEFT] && keyboard_focus) || (mousex < scroll_threshold && mouse_in_window)) { dx -= scroll_speed; } if ((key[SDLK_RIGHT] && keyboard_focus) || (mousex > get_display().w() - scroll_threshold && mouse_in_window)) { dx += scroll_speed; } if ((mouse_flags & SDL_BUTTON_MMASK) != 0 && preferences::middle_click_scrolls()) { const SDL_Rect& rect = get_display().map_outside_area(); if (point_in_rect(mousex, mousey,rect)) { // relative distance from the center to the border // NOTE: the view is a rectangle, so can be more sensible in one direction // but seems intuitive to use and it's useful since you must // more often scroll in the direction where the view is shorter const double xdisp = ((1.0*mousex / rect.w) - 0.5); const double ydisp = ((1.0*mousey / rect.h) - 0.5); // 4.0 give twice the normal speed when mouse is at border (xdisp=0.5) int speed = 4 * scroll_speed; dx += round_double(xdisp * speed); dy += round_double(ydisp * speed); } } if (finger_motion_scroll_) { if (finger_motion_direction_ == UP) { dy += scroll_speed; } else if (finger_motion_direction_ == DOWN) { dy -= scroll_speed; } else if (finger_motion_direction_ == LEFT) { dx += scroll_speed; } else if (finger_motion_direction_ == RIGHT) { dx -= scroll_speed; } else if (finger_motion_direction_ == NORTH_EAST) { dx -= scroll_speed; dy += scroll_speed; } else if (finger_motion_direction_ == SOUTH_EAST) { dx -= scroll_speed; dy -= scroll_speed; } else if (finger_motion_direction_ == SOUTH_WEST) { dx += scroll_speed; dy -= scroll_speed; } else if (finger_motion_direction_ == NORTH_WEST) { dx += scroll_speed; dy += scroll_speed; } finger_motion_scroll_ = false; } return get_display().scroll(dx, dy); }
/* AVI uses little-endian ordering, and block sizes count only bytes after * the block size integer. */ void parse_avi(FILE *file, Data *data) { char fourcc[5]; /* Buffer in which to store fourccs */ unsigned blockLen; /* Length of the current block */ fseek(file, 12L, SEEK_SET); /* We've already checked signature */ /* Verify existence of and read length of AVI header: * "LIST____hdrlavih____" * where the first ____ is the length of the LIST block */ fread(fourcc, sizeof(char), 4, file); if(memcmp(fourcc, "LIST", 4)!=0) return; fseek(file, 4L, SEEK_CUR); fread(fourcc, sizeof(char), 4, file); if(memcmp(fourcc, "hdrl", 4)!=0) return; fread(fourcc, sizeof(char), 4, file); if(memcmp(fourcc, "avih", 4)!=0) return; blockLen = fread_le(file, 4); /* Now we're at the start of the AVI header */ /* 0: microseconds per frame (4 bytes) */ data->fps = (unsigned int) round_double((double) 1.0e6 / fread_le(file, 4)); fseek(file, 12L, SEEK_CUR); /* 16: total frames (4 bytes) */ data->duration = (unsigned int) round_double((double) fread_le(file, 4) * 1000 / data->fps); fseek(file, 12L, SEEK_CUR); /* 32: width (4 bytes) */ data->width = (unsigned int) fread_le(file, 4); /* 36: height (4 bytes) */ data->height = (unsigned int) fread_le(file, 4); /* Skip rest of avi header */ fseek(file, (long) blockLen - 40, SEEK_CUR); /* Verify existence of and read length of video stream header: * "LIST____strlstrh____vids" */ fread(fourcc, sizeof(char), 4, file); if(memcmp(fourcc, "LIST", 4)!=0) return; blockLen = fread_le(file, 4); fread(fourcc, sizeof(char), 4, file); if(memcmp(fourcc, "strl", 4)!=0) return; fread(fourcc, sizeof(char), 4, file); if(memcmp(fourcc, "strh", 4)!=0) return; fseek(file, 4L, SEEK_CUR); fread(fourcc, sizeof(char), 4, file); if(memcmp(fourcc, "vids", 4)!=0) return; /* Now we're in the video stream header */ /* 16: FOURCC of video codec (4 bytes)*/ fread(fourcc, sizeof(char), 4, file); fourcc[4] = '\0'; data->codec = strdup(fourcc); /* Skip rest of video stream header */ fseek(file, (long) blockLen - 20, SEEK_CUR); /* Verify existence of audio stream header: * "LIST____strlstrh____auds" * Note: audio stream header is optional */ /* This is commented out since we're not reading audio data anyway (yet) */ /* fread(fourcc, sizeof(char), 4, file); if(memcmp(fourcc, "LIST", 4)!=0) return; fseek(file, 4L, SEEK_CUR); fread(fourcc, sizeof(char), 4, file); if(memcmp(fourcc, "strl", 4)!=0) return; fread(fourcc, sizeof(char), 4, file); if(memcmp(fourcc, "strh", 4)!=0) return; fseek(file, 4L, SEEK_CUR); fread(fourcc, sizeof(char), 4, file); if(memcmp(fourcc, "auds", 4)!=0) return; */ /* Now we're in the audio stream header */ /* TODO: extract some information about audio stream encoding */ }