PandA-2024.02
los.c
Go to the documentation of this file.
1 #define DIM_X 60
2 #define DIM_Y 60
3 
4 #include <stdio.h>
5 #include "los.h"
6 
7 #define LEGUP 1
8 
9 //x0 and x0 are the coordinates of the pixel under consideration, which will move towards the person
10 //x1 and y1 are the coordinates of the location of the person
11 int line () {
12 
13  const int x1 = DIM_X/2;
14  const int y1 = DIM_Y/2;
15  int visible = 0;
16 #pragma omp parallel for reduction(+:visible)
17  for (int y_pixel=0; y_pixel<DIM_Y; y_pixel++) {
18  for (int x_pixel=0; x_pixel<DIM_X; x_pixel++) {
19 
20  int sight=1;
21  int x0 = x_pixel;
22  int y0 = y_pixel;
23  int sx, sy, err, dx, dy, e2;
24  if (x0 < x1) {
25  sx=1;
26  dx=x1-x0;
27  }
28  else {
29  sx=-1;
30  dx=x0-x1;
31  }
32 
33  if (y0 < y1) {
34  sy=1;
35  dy=y1-y0;
36  }
37  else {
38  sy=-1;
39  dy=y0-y1;
40  }
41  err=dx-dy;
42 
43  while (1) {
44  if ((x0==x1) && (y0==y1)) {
45  break;
46  }
47  //if there's an obstacle
48  if (obstacles[y0][x0] == 1) {
49  sight=0;
50  break;
51  }
52  e2=2*err;
53  if (e2 > -dy) {
54  err = err - dy;
55  x0 = x0+sx;
56  }
57 
58  if (e2 < dx) {
59  err = err + dx;
60  y0 = y0 + sy;
61  }
62  }
63 
64  //if an obstacle was not found on the way
65  if (sight == 1) {
66  //store 1 on the output
67  output[y_pixel][x_pixel] = 1;
68  visible++;
69  }
70  }
71  }
72 
73  return visible;
74 }
75 
76 int main() {
77  int sum = line();
78  int res = 0;
79  printf ("Sum: %d\n", sum);
80  if (sum == 2193) {
81  printf("RESULT: PASS\n");
82  } else {
83  printf("RESULT: FAIL\n");
84  res = 1;
85  }
86 
87  return res;
88 }
volatile int obstacles[DIM_Y][DIM_X]
Definition: los.h:3
#define DIM_X
Definition: los.c:1
volatile int output[DIM_Y][DIM_X]
Definition: los.h:1
int sum
Definition: dotproduct.h:3
#define DIM_Y
Definition: los.c:2
int main()
Definition: los.c:76
int line()
Definition: los.c:11

Generated on Mon Feb 12 2024 13:02:49 for PandA-2024.02 by doxygen 1.8.13