Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __kernel void can_contain_new_beacon(
- const long base_x,
- const uint num_of_sensors,
- __constant long *sensor_x,
- __constant long *sensor_y,
- __constant long *beacon_distance,
- __global long *beacon_location)
- {
- long x = get_global_id(0) + base_x;
- long y = get_global_id(1);
- // Check if this position is outside the range of ALL sensors
- bool can_exist = true;
- for (size_t i = 0; i < num_of_sensors; ++i) {
- long x_distance = abs_diff(x, sensor_x[i]);
- long y_distance = abs_diff(y, sensor_y[i]);
- long total_distance = x_distance + y_distance;
- // Check fails if the position is within range of ANY sensor
- if (total_distance <= beacon_distance[i]) {
- can_exist = false;
- break;
- }
- }
- // If this passes all test cases, return the position
- // Assumes there is only ONE possible solution
- if (can_exist) {
- beacon_location[0] = x;
- beacon_location[1] = y;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement