//
// Academic License - for use in teaching, academic research, and meeting
// course requirements at degree granting institutions only.  Not for
// government, commercial, or other organizational use.
// File: obscheck.cpp
//
// MATLAB Coder version            : 5.3
// C/C++ source code generated on  : 12-May-2022 07:57:40
//

// Include Files
#include "obscheck.h"
#include <cmath>

// Function Definitions
//
// Arguments    : const double map[737460]
//                double i
//                double j
//                double cubsize
//                double Sx
// Return Type  : double
//
double obscheck(const double map[737460], double i, double j, double cubsize,
                double Sx)
{
  double cnt;
  double flag;
  int b_i;
  int k;
  cnt = std::round(Sx / 2.0);
  i = i * Sx + cnt;
  j = j * Sx + cnt;
  cnt = 0.0;
  b_i = static_cast<int>(cubsize + (1.0 - (-cubsize)));
  k = 0;
  int exitg2;
  do {
    exitg2 = 0;
    if (k <= b_i - 1) {
      int exitg1;
      int l;
      l = 0;
      do {
        exitg1 = 0;
        if (l <= static_cast<int>(cubsize + (1.0 - (-cubsize))) - 1) {
          double d;
          boolean_T guard1{false};
          d = i + (-cubsize + static_cast<double>(k));
          guard1 = false;
          if (d >= 765.0) {
            guard1 = true;
          } else {
            double d1;
            d1 = j + (-cubsize + static_cast<double>(l));
            if (d1 >= 964.0) {
              guard1 = true;
            } else if (!(map[(static_cast<int>(d) +
                              765 * (static_cast<int>(d1) - 1)) -
                             1] != 0.0)) {
              flag = 0.0;
              exitg1 = 2;
            } else {
              l++;
            }
          }
          if (guard1) {
            cnt++;
            l++;
          }
        } else {
          // end for k cubesize check if it's obstacle
          k++;
          exitg1 = 1;
        }
      } while (exitg1 == 0);
      if (exitg1 != 1) {
        exitg2 = 1;
      }
    } else {
      if (cnt == Sx * Sx) {
        flag = 0.0;
      } else {
        flag = 1.0;
      }
      exitg2 = 1;
    }
  } while (exitg2 == 0);
  return flag;
}

//
// File trailer for obscheck.cpp
//
// [EOF]
//
