/* * Looks at all the particles in block x,y,z that have moved significantly in the last iteration and updates * particle p's neighborlist * * arguments: * particles: The spatially decomposed particle information * x, y, z: The indexes of the block in the particles array * neighbor_list: Particle p's neighborlist * p: The particle whose neighborlist is being built * moved_list: The list of all the particles that have moved significantly * counts: The number of particles in each moved list */ void check_moved_particles(Particle* particles[XDiv][YDiv][ZDiv], int x, int y, int z, Neighbor* neighbor_list, Particle p, Particle** moved_list[XDiv][YDiv][ZDiv], int counts[XDiv][YDiv][ZDiv]) { // Wraps around to check for "neighboring" particles on the opposite side of the block x = (x+XDiv)%XDiv; y = (y+YDiv)%YDiv; z = (z+ZDiv)%ZDiv; int i, dist; int index = 0; Particle** list = moved_list[x][y][z]; // Iterate through all the particles in the moved list to look for neighbors for (i = 0; i < counts[x][y][z]; ++i){ if (list[i]->index != -1) { dist = within_range(p, *list[i]); if (dist != 0){ //Iterate until we find an empty position in the neighborlist // NOTE: We can't employ the same strategy of just keeping track of the next empty spot // as we did above because we'll have gaps in the neighborlist while(neighbor_list[index].index != -1){ index++; } neighbor_list[index].ptr = list[i]; neighbor_list[index].index = list[i]->index; neighbor_list[index].list = dist; } } } }
/* * Looks at all the particles in block x,y,z that have moved significantly in the last iteration and updates * particle p's neighborlist * * arguments: * particles: The spatially decomposed particle information * x, y, z: The indexes of the block in the particles array * neighbor_list: Particle p's neighborlist * p: The particle whose neighborlist is being built * moved_list: The list of all the particles that have moved significantly * counts: The number of particles in each moved list */ void check_moved_particles_center(Particle* particles[XDiv][YDiv][ZDiv], int x, int y, int z, Neighbor* neighbor_list, Particle *p, Particle** moved_list[XDiv][YDiv][ZDiv], int counts[XDiv][YDiv][ZDiv]) { //Iterate through all moved particles in list //Check if the particle is within the radius //Add to neighborlist int i; int index = 0; Particle** list = moved_list[x][y][z]; int dist; for (i = 0; i < counts[x][y][z]; ++i){ if (list[i]->index != -1) { dist = within_range(*p, *list[i]); //Since this is for the block that the particle itself is in, it should only add particles that //are in array locations that are after the particle, to avoid double counting if (higher_index(list[i], p) && dist != 0){ //Iterate until we find an empty position in the neighborlist while(neighbor_list[index].index != -1){ index++; } neighbor_list[index].ptr = list[i]; neighbor_list[index].index = list[i]->index; neighbor_list[index].list = dist; } } } }
void gevas_sprite_set_inter_frame_delays( GtkgEvasSprite* ev, gint base, GArray* times, gint times_size) { gint i = 0; g_return_if_fail(ev != NULL); g_return_if_fail(times != NULL); g_return_if_fail(GTK_IS_GEVAS_SPRITE(ev)); g_return_if_fail(within_range(ev,base)); ev->frame_delay_ms_base = base; ev->frame_delay_ms_size = times_size; /* printf("gevas_sprite_set_inter_frame_delays() base:%d times:%p size:%d\n", */ /* base, times, times_size); */ if(ev->frame_delay_ms) g_array_free(ev->frame_delay_ms,0); ev->frame_delay_ms = g_array_new(0,0,sizeof(gint)); for (i = 0; i < times_size; i++) g_array_append_val(ev->frame_delay_ms, g_array_index (times, gint, i)); }
void gevas_sprite_set_current_frame( GtkgEvasSprite* ev, gint f ) { g_return_if_fail(ev != NULL); g_return_if_fail(GTK_IS_GEVAS_SPRITE(ev)); g_return_if_fail(GTK_IS_GEVAS_OBJ_COLLECTION(ev->col)); g_return_if_fail(within_range(ev,f)); ev->current_frame = f; }
void gevas_sprite_advance_n( GtkgEvasSprite* ev, gint n ) { gint f = 0; g_return_if_fail(ev != NULL); g_return_if_fail(GTK_IS_GEVAS_SPRITE(ev)); g_return_if_fail(GTK_IS_GEVAS_OBJ_COLLECTION(ev->col)); f = n + gevas_sprite_get_current_frame(ev); g_return_if_fail(within_range(ev,f)); gevas_sprite_set_current_frame(ev,f); }
int main(int argc, char const *argv[]) { char strings[][73] = { "$GPGGA,152606.000,3732.7200,N,07726.9881,W,1,4,1.56,159.0,M,-33.6,M,,*64", "$GPGSA,A,3,21,14,22,24,,,,,,,,,1.85,1.56,0.99*0C", "$GPRMC,152606.000,A,3732.7200,N,07726.9881,W,0.29,81.28,110413,,,A*48", "$GPVTG,81.28,T,,M,0.29,N,0.53,K,A*03", "$PGTOP,11,2*6E" }; for (int i = 0; i < 5; i++) { nmea_parse(strings[i], strlen(strings[i])); } // Validate state within_range(get_latitude(), 37.545333, 0.00001f); within_range(get_longitude(), -77.449802, 0.00001f); within_range(get_altitude(), 159.0, 0.1f); validate_int(get_sat_count(), 4); validate_int(get_fix_type(), 3); nmea_parser_t *parser = nmea_parser_new(); for (int i = 0; i < 5; i++) { nmea_parse_r(strings[i], strlen(strings[i]), parser); } within_range(get_latitude_r(parser), 37.545333, 0.00001f); within_range(get_longitude_r(parser), -77.449802, 0.00001f); within_range(get_altitude_r(parser), 159.0, 0.1f); validate_int(get_sat_count_r(parser), 4); validate_int(get_fix_type_r(parser), 3); nmea_parser_free(&parser); assert(NULL == parser); return error; }
/* * Looks at all the particles within block x,y,z containing particle p and checks the distance * * arguments: * particles: The spatially decomposed particle information * x, y, z: The indexes of the block in the particles array * list_index: The index of particle p in the block, x,y,z * neighbor_list: Particle p's neighborlist * p: The particle whose neighborlist is being built * index: The next empty spot in the neighborlist */ void check_particles_center(Particle* particles[XDiv][YDiv][ZDiv], int x, int y, int z, int list_index, Neighbor* neighbor_list, Particle p, int *index) { int i, dist; Particle* list = particles[x][y][z]; // Iterate through all the particles in the block to look for neighbors for (i = list_index + 1; i < block_size; ++i){ if (list[i].index != -1) { dist = within_range(p, list[i]); if (dist != 0){ // Adds the neighbor to the next available index in the neighborlist neighbor_list[*index].ptr = &list[i]; neighbor_list[*index].index = list[i].index; neighbor_list[*index].list = dist; *index = *index + 1; } } } }
/* * Looks at all the particles within a neighboring block, x,y,z and checks the distance against * given particle p * * arguments: * particles: The spatially decomposed particle information * x, y, z: The indexes of the block in the particles array * neighbor_list: Particle p's neighborlist * p: The particle whose neighborlist is being built * index: The next empty spot in the neighborlist */ void check_particles(Particle* particles[XDiv][YDiv][ZDiv], int x, int y, int z, Neighbor* neighbor_list, Particle p, int* index) { // Wraps around to check for "neighboring" particles on the opposite side of the block x = (x+XDiv)%XDiv; y = (y+YDiv)%YDiv; z = (z+ZDiv)%ZDiv; int i, dist; Particle* list = particles[x][y][z]; // Iterate through all the particles in the block to look for neighbors for (i = 0; i < block_size; ++i){ if (list[i].index != -1) { //If valid particles dist = within_range(p, list[i]); if (dist != 0){ // Adds the neighbor to the next available index in the neighborlist neighbor_list[*index].ptr = &list[i]; neighbor_list[*index].index = list[i].index; neighbor_list[*index].list = dist; *index = *index + 1; } } } }
void smart_object::follow(complex_object target) { if(within_range(target)) moveto_point((int)target.get_x(),(int)target.get_position().y); }
void smart_object::watch(complex_object target) { if(within_range(target)) turnto_point((int)target.get_y(),(int)target.get_y()); }